关于扫雷的自动补空实现C语言
相信很多朋友在用C语言实现扫雷功能时,都想实现扫雷里面的的自动补足功能,但总是难以实现,在这里我将分享一种方法——递归思想
先看代码!
位置在game.c
//判断附近雷区并过滤空白区(实现递归)
void FilterBlankAreas(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col, int x, int y) {
int MineCount = GetMineCount(mine, x, y);
if (MineCount != 0) {
show[x][y] = MineCount + '0';
}
else if(show[x][y] != ' ' && MineCount == 0 && x >= 1 && x <= row && y >= 1 && y <= col){
show[x][y] = ' ';
FilterBlankAreas(mine, show, row, col, x - 1, y - 1);
FilterBlankAreas(mine, show, row, col, x - 1, y);
FilterBlankAreas(mine, show, row, col, x - 1, y + 1);
FilterBlankAreas(mine, show, row, col, x