C/C++仿华容道小游戏

这篇文章主要介绍了C/C++仿华容道小游戏的相关资料,模仿实现华容道游戏,感兴趣的朋友可以参考一下

本文实例介绍了C++模仿华容道小游戏实现代码,分享给大家供大家参考,具体内容如下

 #include  #include  #include  #include  #define maxnum 16 #define colnum 4 bool numexists(int *numbers, int length, int num); int getnumber(int **numbers, int randIndex, int *length); int* initnumbers(void); void swap(int **a, int **b); int main(int argc, char *argv[]) { int *tempnumbers = initnumbers(); int *randnumbers = initnumbers(); int **numbers; numbers = malloc(maxnum * sizeof(int*)); //bool a = numexists(numbers, 16, 3); //printf("a=%d\n", a); int length = maxnum; srand((unsigned)time(NULL)); for (int i = 0; i = maxnum || i <0) { printf("sorry, i can't find %d\n", i); break; } unsigned char sign = abs(numbers[i] - numbers[0]); switch (sign) { case 1: case 4: swap(&numbers[0], &numbers[i]); break; } } if (numbers != NULL) free(numbers); if (randnumbers != NULL) free(randnumbers); } void swap(int **a, int **b) { int *templocation = *a; int tempvalue = **a; **a = **b; **b = tempvalue; *a = *b; *b = templocation; } int* initnumbers(void) { int *numbers = malloc(maxnum * sizeof(int)); for (int i = 0; i  num) return _numexists(numbers, start, middle-1, num); else return _numexists(numbers, middle+1, end, num); } } bool numexists(int *numbers, int length, int num) { return _numexists(numbers, 0, length-1, num); } 

希望本文对大家学习C++程序设计有所帮助。

以上就是C/C++仿华容道小游戏的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » C语言