本文介绍了在十五岁的游戏中完成move()的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我应该在fif.c中完成一个move()函数,这个程序的目标是实现Game of Fifteen。我只是看不到move()函数本身在程序中使用的位置和方式。 我尝试了什么: I am supposed to complete a move() function in fifteen.c, a program with the goal of implementing Game of Fifteen. I just don't see where/how the move() function itself is used in the program.What I have tried:int main(int argc, string argv[]){ // ensure proper usage if (argc != 2) { printf("Usage: fifteen d\n"); return 1; } // ensure valid dimensions d = atoi(argv[1]); if (d < DIM_MIN || d > DIM_MAX) { printf("Board must be between %i x %i and %i x %i, inclusive.\n", DIM_MIN, DIM_MIN, DIM_MAX, DIM_MAX); return 2; } // open log FILE* file = fopen("log.txt", "w"); if (file == NULL) { return 3; } // greet user with instructions greet(); // initialize the board init(); // accept moves until game is won while (true) { // clear the screen clear(); // draw the current state of the board draw(); // log the current state of the board (for testing) for (int i = 0; i < d; i++) { for (int j = 0; j < d; j++) { fprintf(file, "%i", board[i][j]); if (j < d - 1) { fprintf(file, "|"); } } fprintf(file, "\n"); } fflush(file); // check for win if (won()) { printf("ftw!\n"); break; } // prompt for move printf("Tile to move: "); int tile = GetInt(); // quit if user inputs 0 (for testing) if (tile == 0) { break; } // log move (for testing) fprintf(file, "%i\n", tile); fflush(file); // move if possible, else report illegality if (!move(tile)) { printf("\nIllegal move.\n"); usleep(500000); } // sleep thread for animation's sake usleep(500000); } // close log fclose(file); // success return 0;} ---- 我的任务: ----My Task: * If tile borders empty space, moves tile and returns true, else * returns false. */bool move(int tile){ // TODO return false;} 非常感谢,Thanks a lot,推荐答案 你更好看你的代码更清晰,因为它是: You better look sharper at your code because it goes:int tile = GetInt();// quit if user inputs 0 (for testing)if (tile == 0){ break;}// log move (for testing)fprintf(file, "%i\n", tile);fflush(file);// move if possible, else report illegalityif (!move(tile)){ printf("\nIllegal move.\n"); usleep(500000);} 有一个调用移动功能。如果 int tile 的移动有效,则此函数应返回true。我猜这个值应该由一些用户输入提取。 我理解你的代码片段,移动功能也应该在屏幕上绘制。如果不清楚,你最好问一下代码的作者(以及你的家庭作业)。There is a call of the move function. This function should return true, if the move for the int tile is valid. I guess the value should be fetched by some user input.As I understand your code fragment the move function should also draw on the screen. You better ask the author of the code (and your home work) if something is unclear. 这篇关于在十五岁的游戏中完成move()的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 02:21