game.h
#include <stdio.h> #include <stdlib.h> #include <time.h> #define ROW 9 #define
COL 9 #define ROWS ROW+2 #define COLS COL+2 #define EASY_COUNT 10 // initialization void
init_board(char arr[ROWS][COLS], int rows, int cols, char set); // Print void
show_board(char arr[ROWS][COLS], int row, int col); // Lay thunder void set_mine(char
mine[ROWS][COLS], int row, int col); // mine clearance void find_mine(char mine[ROWS][COLS],
char show[ROWS][COLS], int row, int col); // Expand a piece void SpreadMind(char
mine[ROWS][COLS], char show[ROWS][COLS], int row, int col);

game.c
#include "game.h" void init_board(char arr[ROWS][COLS], int rows, int cols,
char set) { int i = 0; int j = 0; for (i = 0; i < rows; i++) { for (j = 0; j <
cols; j++) { arr[i][j] = set; } } } void show_board(char arr[ROWS][COLS], int
row, int col) { int i = 0; int j = 0; printf("--------- mine clearance ---------\n"); for (i
= 0; i <= col; i++) { printf("%d ", i); } printf("\n"); // Print a column for (i = 1; i <=
row; i++) { printf("%d ", i); // Print one line for (j = 1; j <= col; j++) { printf("%c ",
arr[i][j]); } printf("\n"); } printf("--------- mine clearance ---------\n"); } // Lay thunder void
set_mine(char mine[ROWS][COLS], int row, int col) { int count = EASY_COUNT;
// Randomly generated coordinates int x = 0; int y = 0; while (count) { x = rand() % row + 1;//8+1=9 y =
rand() % col + 1;//9 if (mine[x][y] == '0') { mine[x][y] = '1';// Lay thunder count--;
// The number of cycles is greater than or equal to the number of Mines } } } // mine clearance //int get_mine_count(char mine[ROWS][COLS], int x,
int y) //{ // return mine[x - 1][y] + // mine[x - 1][y - 1] + // mine[x][y - 1]
+ // mine[x + 1][y - 1] + // mine[x + 1][y] + // mine[x + 1][y + 1] + //
mine[x][y + 1] + // mine[x - 1][y + 1] - 8 * '0'; //} static int
get_mine_count(char mine[ROWS][COLS], int x, int y) { int i = 0; int j = 0; int
count = 0; for (i = x - 1; i <= x + 1; i++) { for (j = y - 1; j <= y + 1; j++)
{ if (mine[i][j] == '1') { count++; } } } return count; } void find_mine(char
mine[ROWS][COLS], char show[ROWS][COLS], int row, int col) { int x = 0; int y =
0; int win = 0; while (win<row*col-EASY_COUNT) { printf(" Please enter the coordinates to be checked :");
scanf("%d %d", &x, &y); // Judge whether the coordinates are legal if (x >= 1 && x <= row && y >= 1 && y <=
col) { if (mine[x][y] == '1') { printf("! Find the bomb , Game failed !\n"); show_board(mine, ROW,
COL); break; } else { int count = get_mine_count(mine, x, y); show[x][y] =
count + '0'; SpreadMind(mine, show, x, y); show_board(show, ROW, COL); win++; }
} else { printf(" Illegal coordinates , Please re-enter \n"); } //SignMine(show, row, col); } if (win == row
* col - EASY_COUNT) { printf(" Congratulations on the successful demining \n"); show_board(mine, ROW, COL); } }
// Expand a piece void SpreadMind(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int
y) { int count = get_mine_count(mine, x, y); if (count != 0) { show[x][y] =
count + '0'; } else// No thunder around { show[x][y] = ' ';// No ray gave him ' ' if (show[x - 1][y]
== '*') SpreadMind(mine, show, x - 1, y); if (show[x - 1][y - 1] == '*')
SpreadMind(mine, show, x - 1, y - 1); if (show[x][y - 1] == '*')
SpreadMind(mine, show, x, y - 1); if (show[x + 1][y - 1] == '*')
SpreadMind(mine, show, x + 1, y - 1); if (show[x + 1][y] == '*')
SpreadMind(mine, show, x + 1, y); if (show[x + 1][y + 1] == '*')
SpreadMind(mine, show, x + 1, y + 1); if (show[x][y + 1] == '*')
SpreadMind(mine, show, x, y + 1); if (show[x - 1][y + 1] == '*')
SpreadMind(mine, show, x - 1, y + 1); } }

test.c
#include "game.h" void menu() { printf("***************\n");
printf("****1.play*****\n"); printf("*****0.exit****\n");
printf("***************\n"); } void game() { // Implementation of mine sweeping game //mine Array is used to store the information of the deployed mine
char mine[ROWS][COLS] = { 0 };//'0' //show Array is used to store the information of detected mines char show[ROWS][COLS]
= { 0 };//'*' // Initialize chessboard init_board(mine, ROWS, COLS, '0'); init_board(show, ROWS,
COLS, '*'); // Print chessboard 9*9 //show_board(mine, ROW, COL); // Lay thunder set_mine(mine, ROW,
COL); show_board(show, ROW, COL); // mine clearance find_mine(mine, show, ROW, COL); // Expand a piece
SpreadMind(mine, show, ROW, COL); } int main() { int input = 0; srand((unsigned
int)time(NULL)); do { menu(); printf(" Please enter :"); scanf("%d", &input); switch
(input) { case 1: game(); break; case 0: printf(" Exit the game \n"); break; default:
printf(" Selection error , Reselect \n"); break; } } while (input); return 0; }

Technology