这个函数假设在连接4游戏中返回1步,但是,它返回两次...我用调试器完成了这个功能,它似乎跳过了getc()调用我不知道为什么.任何帮助深表感谢!
char UndoBoard(char x[ROWS][COLS], char * player){
struct Node* temp = head;
int i,j;
temp = temp->next;
char input = 'q';
while((input != 'q' || input != 'Q') && temp != NULL){
for (i=0;i<ROWS;i++){
for (j=0;j<COLS;j++){
x[i][j] = temp->data[i][j];
}
}
printBoard(x);
if(*player == 'O')*player = 'X';
else *player = 'O';
printf("b - undo one step more, f - go forward, q - resume game from here\n");
input = getc(stdin);
if(input == 'q' || input == 'Q')break;
temp = temp -> next;
}
}
Run Code Online (Sandbox Code Playgroud)
用于的逻辑
while((input != 'q' || input != 'Q') && temp != NULL){
Run Code Online (Sandbox Code Playgroud)
是有缺陷的.你需要使用:
while((input != 'q' && input != 'Q') && temp != NULL){
Run Code Online (Sandbox Code Playgroud)