用 C語言 實現掃雷遊戲

2021-09-23 10:49:59 字數 2514 閱讀 7685

要求

1>第一次下子,不炸死。

2>座標周圍沒雷,可以實現展開。

標頭檔案game.h

#include#include#include#include#include#define row 9

#define col 9

#define rows row+2

#define cols col+2

#define num 10 //雷的個數

void setmine(char mine[rows][cols], int row, int col, int n); //設定雷

void c_mine(char mine[rows][cols], int row, int col); //初始化

void print(char mine[rows][cols], int row, int col); //列印

void c_show(char mine[rows][cols], int row, int col); //初始化

int findmine(char mine[rows][cols], char show[rows][cols], int row, int col); //找雷

game.c檔案

#define _crt_secure_no_warnings

#include"game.h"

void c_mine(char mine[rows][cols], int row, int col) //初始化

void c_show(char mine[rows][cols], int row, int col)

void print(char mine[rows][cols], int row, int col) //列印雷區

printf("\n");

for (i = 1; i <= row; i++)

printf("\n"); }}

static void movemine(char mine[rows][cols], int x, int y) //移動第一次踩到的雷

} mine[x][y] = '0';

}void setmine(char mine[rows][cols], int row, int col, int n) //隨機放置雷 }}

static int minecount(char mine[rows][cols], int x, int y) //統計雷數

static int opeanmine(char mine[rows][cols], char show[rows][cols], int x, int y) //用遞迴實現展開未知區域

else

return 0;

}static int is_win(char show[rows][cols], int row, int col) //判斷贏

} return count;

}int findmine(char mine[rows][cols], char show[rows][cols], int row, int col)

else if (show[x][y] != '*')

else if (mine[x][y] == '1' && flag == 1)

else if (mine[x][y] == '1' && flag == 0)

else if (mine[x][y] == '0')

}printf("恭喜你掃雷成功\n");

return 0;

}

main函式檔案

#define _crt_secure_no_warnings

#include"game.h"

void menu()

void game()

; char show[rows][cols] = ;

c_mine(mine, rows, cols); //初始化雷區

setmine(mine, row, col, num); //放置雷

c_show(show, rows, cols); //初始化show

//print(mine, row, col); //列印雷區

system("cls");

print(show, row, col);

findmine(mine, show, row, col);

}int main()

} while (input);

system("pause");

return 0;

}

用C語言實現(掃雷遊戲)

include include include include pragma warning disable 4996 define rows 8 define cols 8 define mines 62 void menu 列印選單 void init mine char mine cols 2...

用C語言實現掃雷遊戲

本人能力不足,能力有待提公升,在敲 的過程中遇到了很多問題,在此不再一一贅述,現將 以及分析展示如下 include stdio.h include stdlib.h include time.h include string.h pragma warning disable 4996 define...

用c語言實現掃雷遊戲

test.c define crt secure no warnings include game.h void menu void play print player 列印玩家棋盤 while 1 迴圈掃雷 if ret 判斷是否踩到雷 print player 列印玩家棋盤 intmain wh...