C實現掃雷小遊戲

2021-08-20 14:50:07 字數 2424 閱讀 7974

直接上傳**

這是乙個「game.h」標頭檔案

#ifndef __game_h__

#define __game_h__

#include#include#define row 9

#define col 9

#define count 10

#define rows 11

#define cols 11

void initboard(char board[rows][cols], int row, int col, char c);

void displayboard(char board[rows][cols]);

void setmine(char board[rows][cols]);

int sweep(char showboard[rows][cols], char mineboard[rows][cols]);

#endif //__game_h__

這是遊戲實現的函式

#include"game.h"

void initboard(char board[rows][cols], int row, int col, char c)

}}//初始化棋盤

void displayboard(char board[rows][cols])

printf("\n");

for (j = 1; j < cols - 1; j++)

printf("-\n");

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

printf("\n");

}}//列印棋盤

void setmine(char board[rows][cols])

}}//布雷

static int getmine(char mineboard[rows][cols], int x, int y)

//返回周圍累的個數

static void play(char mineboard[rows][cols], char showboard[rows][cols], int x, int y)

if ((x - 1 > 0) && (y > 0) && (showboard[x - 1][y] == '*'))

if ((x - 1 > 0) && (y + 1> 0) && (showboard[x - 1][y + 1] == '*'))

if ((x > 0) && (y + 1> 0) && (showboard[x][y + 1] == '*'))

if ((x + 1 > 0) && (y + 1 > 0) && (showboard[x + 1][y + 1] == '*'))

if ((x + 1 > 0) && (y > 0) && (showboard[x + 1][y] == '*'))

if ((x + 1 > 0) && (y - 1 > 0) && (showboard[x + 1][y - 1] == '*'))

if ((x > 0) && (y - 1 > 0) && (showboard[x][y - 1] == '*'))

}else

showboard[x][y] = ret + '0';

}//遞迴展開無雷區域

int sweep(char showboard[rows][cols], char mineboard[rows][cols])

else

}if (mineboard[x][y] == '1')

}} else

while (count != (row)*(col)-count-1)

else

}if (mineboard[x][y] == '1')

else

}return 0;

}//返回1,即被炸死。 返回0,繼續遊戲

以下為主函式

#include"game.h"

void meun()

void game()

; char mineboard[rows][cols] = ;

int num = 0;

initboard(showboard, rows, cols, '*');

initboard(mineboard, rows, cols, '0');

setmine(mineboard);

displayboard(showboard);

num = sweep(showboard, mineboard);

if (num == 1)

else }

void test()

} while (input);

}int main()

這就是實現遊戲的全部**。若有不足之處請見諒,歡迎批評指正。

C 小遊戲 掃雷

標頭檔案 define crt secure no warnings 1 ifndef game h define game h include include include include define row 9 define col 9 define rows row 2 define co...

c 小遊戲 掃雷

include include include include include include includeusing namespace std define maxn 35 define midx 10 define midy 40 define cg 25 define ck 80 int ...

c 小遊戲 掃雷

include include include include include include includeusing namespace std define maxn 35 define midx 10 define midy 40 define cg 25 define ck 80 int ...