用c語言實現掃雷遊戲

2021-09-02 18:30:07 字數 3039 閱讀 9467

test.c

#define _crt_secure_no_warnings

#include

"game.h"

void

menu()

void

play()

print_player()

;列印玩家棋盤

while(1

)//迴圈掃雷

if(ret)

//判斷是否踩到雷

print_player()

;//列印玩家棋盤}}

intmain()

}while

(choose)

;system

("pause");

return0;

}

game.c

#define _crt_secure_no_warnings

#include

"game.h"

char real_mine[row]

[col]=;

char show_mine[row]

[col]=;

void

init_mine()

//初始化兩個雷陣

void

print_player()

//列印玩家棋盤

printf

("\n");

for(i =

1; i 2; i++

)//列印豎標(1--10)

printf

("\n");

}printf

("10 ");

//開始列印最後一行

for(i =

1; i < row -

1; i++

)printf

("\n");

}void

print_mine()

//列印設計者棋盤

//printf("\n");

//for (i = 1; i //

// printf("\n");

//}//printf("10 ");//開始列印最後一行

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

////printf("\n");

}void

set_mine()

//給設計者棋盤布雷}}

intcount_mine

(int x,

int y)

//檢測周圍8個區域雷的個數

void

safe_mine()

//避免第一次炸死

}break

;//跳出此函式 }if

(real_mine[x]

[y]==

'0')

}else

//座標錯誤}}

void

open_mine

(int x,

int y)

//座標周圍展開函式

if(real_mine[x -1]

[y]==

'0')

if(real_mine[x -1]

[y +1]

=='0')if

(real_mine[x]

[y -1]

=='0')if

(real_mine[x]

[y +1]

=='0')if

(real_mine[x +1]

[y -1]

=='0')if

(real_mine[x +1]

[y]==

'0')

if(real_mine[x +1]

[y +1]

=='0')}

intsweep_mine()

//掃雷函式,踩到雷返回1,沒有踩到雷返回0

}else

if(real_mine[x]

[y]==

'1')

//踩到雷

}else

return0;

//沒踩到雷

}int

count_show_mine()

//判斷剩餘未知區域的個數,個數為雷數時玩家贏}}

return count;

}```c

game.h

#ifndef __game_h__

#define __game__h__

#include

#include

#include

#include

#define row 12

#define col 12

#define count 10

//棋盤中雷的總數

extern

char show_mine[row]

[col]

;//展示陣列

extern

char real_mine[row]

[col]

;//布雷陣列

void

muen()

;//選單函式

void

init_mine()

;//初始化陣列函式

void

set_mine()

;//布雷函式

intcount_mine()

;//統計周圍雷的個數

void

print_player()

;//列印玩家棋盤

void

print_mine()

;//列印設計者棋盤

intsweep_mine()

;//掃雷函式

void

safe_mine()

;//避免第一次被雷炸死的函式

void

open_mine

(int x,

int y)

;//展開函式

intcount_show_mine()

;///判斷玩家棋盤剩餘未知區域的個數

#endif

//__game_h__

用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語言 實現掃雷遊戲

要求 1 第一次下子,不炸死。2 座標周圍沒雷,可以實現展開。標頭檔案game.h include include include include include define row 9 define col 9 define rows row 2 define cols col 2 define...