1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| #include"game.h"
void Init(char board[ROWS][COLS], int rows, int cols, char set) { int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { board[i][j] = set; } } }
void print(char board[ROWS][COLS], int row, int col) { int i, j; for (i = 0; i <= row; i++) { for (j = 0; j <= col; j++) { if (i == 0) { printf("%d ", j); continue; } if (j == 0) printf("%d ", i); else printf("%c ",board[i][j]);
} printf("\n"); } }
void Lay_thun(char Find[ROWS][COLS], int row, int col) {
int count = Thunder; while(count) { int x = rand() % row + 1; int y = rand() % col + 1; if (Find[x][y] == '0') { Find[x][y] = '1'; count--; } }
}
void check(char Lay[ROWS][COLS], char Find[ROWS][COLS], int row, int col) { int x, y; int count = 0; while (count < row * col - Thunder) { printf("请输入你要排查的坐标:>"); scanf("%d %d", &x, &y); if (x >= 1 && x <= row && y >= 1 && y <= col) { if (Lay[x][y] == '1') { printf("运气有点菜哦 TAT\n"); printf("\n\n"); print(Lay,ROW,COL); break; } if (Find[x][y] == '0' || Find[x][y] == '1') { printf("这里你已经扫过啦\n"); } else { int digit = Statis(Lay, x, y); Find[x][y] = digit + '0'; print(Find, ROW, COL); count++; }
} else { printf("输入的坐标范围不对哦,换一个试试\n"); } if (count == row * col - Thunder) { printf("我去,你竟然有耐心做完,太厉害了吧\n"); print(Find, ROW, COL); } } }
static int Statis(char Lay[ROWS][COLS], int x, int y) { return Lay[x - 1][y - 1] + Lay[x][y - 1] + Lay[x + 1][y - 1] + Lay[x - 1][y] + Lay[x + 1][y] + Lay[x - 1][y + 1] + Lay[x][y + 1] + Lay[x + 1][y + 1] - 8 * '0';
}
|