我被要求编写一个记忆游戏,其中包含一些细节,然后,如果第二个提示中的用户猜到相应的匹配点,那么在用户完成游戏之前,棋盘应该保持不变(通过猜测所有正确的匹配点),这是一个 2x2 网格的示例
Your program:
* *
* *
Enter a pair of integers in the range [1, 2]
Player: 1 1
Your program:
A *
* *
(then it clears the screen and displays)
* *
* *
Enter another pair of integers in the range [1, 2]
Player: 2 1
Your program:
* *
C *
(then it clears screen and displays)
* *
* *
Enter a pair of integers in the range [1, 2]
Player: 1 2
Your program:
* C
* *
(then it clears screen and displays)
* *
* *
Enter another pair of integers in the range [1, 2]
Player: 2 1
Your program:
* *
C *
(then it clears the screen and displays)
* C
C *
Enter a pair of integers in the range [1, 2]
Player: 1 1
Your program:
A C
C *
(then it clears the screen and displays)
* C
C *
Enter another pair of integers in the range [1, 2]
Player: 1 1
Your program:
A C
C *
(then it clears the screen and displays)
* C
C *
Enter a pair of integers in the range [1, 2]
Player: 1 1
Your program:
A C
C *3
(then it clears the screen and displays)
* C
C *
Enter another pair of integers in the range [1, 2]
Player: 2 2
Your program:
A C
C A
CONGRATULATIONS. YOU SUCCEEDED
我需要一个 4x4,我知道如何显示正确的匹配,但我似乎无法存储新的棋盘,所以用户看到的是最新的棋盘,我无法绕过它....
char board[4][4] = { {'A','B','A','D'},{'C','E','H','G'},{'B','D','G','C'},{'F','H','F','E'} };
int i, j, row, column, row2, column2;
char boardmatch[4][4];
int tempX,tempY;
for(tempX = 0; tempX < 4; tempX++){
for(tempY = 0; tempY < 4; tempY++){
boardmatch[tempX][tempY] = 0;
}
}
for (i=0; i < 4 ; i++){
for (j=0; j<4; j++){
printf("* ");
}
printf("\n");
}
do {
printf("\nEnter a pair of integers in the range [1, 4]: ");
scanf("%d %d", &row, &column);
row--;
column--;
printf("\n");
for (i=0; i < 4 ; i++){
for (j=0; j < 4 ; j++){
if ( i == row && j == column){
printf("%c ", board[row][column]);
}else{
printf("* ");
}
}
printf("\n");
}
printf("\n");
system("pause");
system("cls");
for (i=0; i < 4 ; i++){
for (j=0; j<4; j++){
printf("* ");
}
printf("\n");
}
printf("\nEnter another pair of integers in the range [1, 4]: ");
scanf("%d %d", &row2, &column2);
row2--;
column2--;
printf("\n");
for (i=0; i < 4 ; i++){
for (j=0; j < 4 ; j++){
if (i == row2 && j == column2){
printf("%c ", board[row2][column2]);
}else{
printf("* ");
}
}
printf("\n");
}
system("pause");
system("cls");
if(board[row][column]==board[row2][column2]){
boardmatch[row][column] = 1;
boardmatch[row2][column2] = 1;
}
for (i=0; i < 4 ; i++){
for (j=0; j<4; j++){
if (boardmatch[i][j] == 1){
printf("%c ", board[row2][column2]);
}else{
printf("* ");
}
}
printf("\n");
}
printf("\n");
system("pause");
system("cls");
}while(1);
system("PAUSE");
return 0;
}