头文件game.h
#pragma once #include#include #define PLAY 1 #define EXIT 0 #define ROW 9 #define COL 9 #define ROWS ROW+2 #define COLS COL+2 #define gamelevel 20 void startgame(); void InitBoard(char board[ROWS][COLS], char set); void DisplayBoard(char board[ROWS][COLS], int row, int col); void SetMine(char mine[ROWS][COLS], int row, int col); void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col);
源文件game.c
#include"game.h"
void InitBoard(char board[ROWS][COLS], char set)
{
for (int i = 0; irow)||(y<1 || y>col)){
printf("你输入的位置不合法请重新输入n");
continue;
}
if (mine[x][y] == '1'){
DisplayBoard(mine, ROW, COL);
printf("很可惜你踩雷了!!n");
break;
}
int count = GetMine(mine, x, y);
show[x][y] = count+'0';
win++;
system("cls");
DisplayBoard(show, ROW, COL);
}
if (win > row*col - gamelevel){
DisplayBoard(mine, ROW, COL);
printf("恭喜你扫雷成功");
}
}
void startgame(){
char mine[ROWS][COLS];
char show[ROWS][COLS];
//初始化棋盘
InitBoard(mine, '0');
InitBoard(show, '*');
//进入游戏
//埋雷
SetMine(mine, ROW, COL);
//显示棋盘
DisplayBoard(show, ROW, COL);
//判断
FindMine(mine, show, ROW, COL);
}
主函数gamemine.c
#include "game.h"
int main(){
int select = 1;
while (select){
printf("***************************n");
printf("*******简易扫雷游戏********n");
printf("******[1]PLAY [0]EXIT******n");
printf("***************************n");
printf("请输入你的选择:");
scanf("%d", &select);
if (select ==EXIT){
printf("退出游戏!");
break;
}
else if (select != PLAY){
printf("你输入的有误请重新输入:n");
continue;
}
startgame();
}
return 0;
}



