掃雷小遊戲簡單易懂

2021-07-30 23:58:38 字數 1665 閱讀 2443

game.h//遊戲的標頭檔案
#ifndef __game_h__

#define __game_h__

#include #include #include #include #define count 10//雷數

#define col 9

#define row 9

#define cols col+2

#define rows row+2

void init_board(char board[rows][cols],char set, int row, int col);

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

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

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

#endif

test.c//測試
#define _crt_secure_no_warnings

#include#include"game.h"

#include#includevoid menu()

void game()

;//記錄雷的資訊

char show[rows][cols] = ;//排出雷的資訊

int x = 0;

int y = 0;

int win = 0;

init_board(mine, '0',rows, cols);//初始化棋盤

init_board(show, '*', rows, cols);//初始化棋盤

set_mine(mine);

display_board(mine, row, col);//列印棋盤

display_board(show, row, col);//...

while(win < row*col-count)

else }

else }

if(win==row*col-count)//結束條件

}void test()

} while(input);

}int main()

game.c

#include "game.h"

#include#includevoid init_board(char board[rows][cols],char set,int row, int col)//初始化棋盤宣告

void display_board(char board[rows][cols], int row, int col)//列印棋盤函式宣告

printf("\n");

for(i=1; i0) }

}int get_mine_count(char mine[rows][cols], int x, int y)//統計周圍雷的數目

簡單掃雷小遊戲

game.h ifndef game h define game h include include include include define row 9 define col 9 define rows row 2 define cols col 2 define easy count 10 ...

小遊戲 掃雷

c語言實現的乙個簡單的掃雷遊戲 介面簡單,功能 首次踩雷的,會換雷。掃雷有九宮格擴撒 環境 vs2015 如下 game.h pragma once ifndef game h define game h define rows 11 define cols 11 define num 9 incl...

小遊戲 掃雷

實現乙個掃雷遊戲 1.設定兩個陣列 mine row col 表示布雷,show row col 顯示掃雷情況 顯示周圍有幾個雷 因為統計四周,邊緣位置不好實現,所以把二維陣列的行和列都加二,這樣無論是否在邊緣都可以當做一種情況來實現。2.初始化mine和show,show mine 0 3.set...