C語言實現乙個簡易的掃雷2

2021-08-19 03:57:08 字數 2125 閱讀 7037

#ifndef _game_h_

#define _game_h_

#define crt_secure_no_warnings 1

#include

#include

#include

#include

#define rows 11

#define cols 11

#define count 10

void init_board(char mine[rows][cols], char show[rows][cols]);//初始化棋盤

void set_mine(char mine[rows][cols]);//設定雷的位置

void display(char show[rows][cols]);//列印棋盤

int sweep(char mine[rows][cols], char show[rows][cols]);//開始掃雷

int get_num(char mine[rows][cols], int x, int y);//計算雷個數

#endif

#define _crt_secure_no_warnings 1

#include"game.h"

//初始化棋盤

void init_board(char mine[rows][cols], char show[rows][cols])

}}//設定雷位置

void set_mine(char mine[rows][cols])

}}//列印介面

void display(char show[rows][cols])

printf("\n\n");

for (i = 1; i < rows - 1; i++)

printf("\n\n");

}}//計算雷個數

int get_num(char mine[rows][cols], int x, int y)

if (mine[x][y - 1] == '1')//左方

if (mine[x + 1][y - 1] == '1')//左下方

if (mine[x - 1][y] == '1')//上方

if (mine[x + 1][y] == '1')//下方

if (mine[x - 1][y + 1] == '1')//右上方

if (mine[x][y + 1] == '1')//右方

if (mine[x + 1][y + 1] == '1')//右下方

return

count;

}//開始掃雷

int sweep(char mine[rows][cols], char show[rows][cols])

}fflag = 1;

}else

if (mine[x][y] == '1' && fflag > 0)

else

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

}printf("恭喜你贏了!\n");

display(mine);

return

0;}

#define _crt_secure_no_warnings 1

#include "game.h"

//選單

void menu()

//遊戲主體

void game()

//執行測試

void test()

} while (input);

}int main()

執行顯示:

列印雷位置和初始化棋盤

當首次踩雷,不顯示炸開,將雷的位置移開,並顯示移開後的雷區

顯示踩雷

C語言實現簡易掃雷

define crt secure no warnings 1 include include include include define row 9 顯示棋盤的大小 define col 9 define rows row 2 整個棋盤的大小 define cols col 2 define c...

c語言實現簡易掃雷遊戲

掃雷遊戲很多人都玩過吧,今天就為大家介紹我用c語言製作的簡單掃雷程式。這個遊戲的主要功能就是game 函式的實現,用乙個型別為char 的show map二維陣列進行標記一定數量的地雷,不列印給玩家和另乙個同型別的名為mine map的二維陣列,用於記錄座標周圍的地雷數。玩遊戲的功能都是圍繞這兩個函...

C語言實現簡易版掃雷

minesweeping define crt secure no warnings 1 ifndef game h define game h include include include include define row 10 define col 10 define rows row 2...