前文中存在重复输入同一坐标可以刷累计次数的bug。现在对其做修复处理。
void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS],int row, int col)
{
int x = 0;
int y = 0;
int win = 0;
printf("输入样例:x(空格)y (x代表行,y代表列)\n");
printf("输入完成后请敲回车键\n");
while (win < row * col - EASY_COUNT)
{
next:
printf("请输入需要排查的坐标:>\n");
scanf("%d %d", &x, &y);
if (x >= 1 && x <= row && y >= 1 && y <= col)//保证不越界
{
if (mine[x][y] == '1')
{
printf("很遗憾,你被炸死了\n");
DisplayBoard(mine, ROW, COL);
printf("上表中1代表雷,0代表安全\n");
break;
}
else
{
if ((show[x][y] == '0')||(show[x][y] == '1')||(show[x][y] == '2') || (show[x][y] == '3') || (show[x][y] == '4') || (show[x][y] == '5') || (show[x][y] == '6') || (show[x][y] == '7') || (show[x][y] == '8'))
{
printf("该坐标已输入,请重新输入\n");
goto next;
}
int count = GetMineCount(mine, x, y);
show[x][y] = count + '0';//'0'+1 ='1'
DisplayBoard(show, ROW, COL);
win++;
}
}
else
{
printf("非法坐标,请重新输入\n");
}
}
if (win == row * col - EASY_COUNT)
{
printf("恭喜你,排雷成功\n");
DisplayBoard(mine, ROW, COL);
printf("上表中1代表雷,0代表安全\n");
}
}