掃雷問題(可實現展開)

2021-09-28 16:11:30 字數 3786 閱讀 7019

第一下掃雷時,即使踩中了雷也不能直接炸死;

掃雷時,座標周圍沒有雷的地方可以實現展開;

;//雷的資訊

char show[rows]

[cols]=;

//顯示排查出的雷的個數

//初始化

initboard

(mine, rows, cols,

'0')

;initboard

(show, rows, cols,

'*')

;display

(show, row, col)

;//布置雷

setmine

(mine, row, col)

;display

(mine, row, col)

;//排查雷

findmine

(mine, show, row, col);}

void

test()

}while

(input);}

intmain()

void

initboard

(char board[rows]

[cols]

,int rows,

int cols,

char set)

}}

void

display

(char board[rows]

[cols]

,int row,

int col)

printf

("\n");

for(i =

1; i <= row; i++

)printf

("\n");

}printf

("\n");

}

利用函式 strand() 函式和 rand() 函式在棋盤上隨機地方布置雷,有雷的地方標記為 1 ,沒有雷的地方標記為 0。

void

setmine

(char board[rows]

[cols]

,int row,

int col)

}}

因為是char型別陣列,中間存的是字串『0』,則判斷周圍八個區域減去乙個八個『0』就為周圍雷的個數

int

getminecount

(char board[rows]

[cols]

,int x,

int y)

掃雷時,座標周圍沒有雷的地方展開,並統計展開的地方邊緣處可能存在的雷的個數。

先統計雷周圍雷的的數,如果為 0,則排除這個區域即置為 『 』 ,並遞迴周圍的 8 個位置,如果還出現為 0 的情況則繼續遞迴

void

nomine

(char mine[rows]

[cols]

,char show[rows]

[cols]

,int x,

int y)

else

show[x]

[y]= ret +

'0';

}

#define _crt_secure_no_warnings 1

#include

"game.h"

void

initboard

(char board[rows]

[cols]

,int rows,

int cols,

char set)}}

void

display

(char board[rows]

[cols]

,int row,

int col)

printf

("\n");

for(i =

1; i <= row; i++

)printf

("\n");

}printf

("\n");

}void

setmine

(char board[rows]

[cols]

,int row,

int col)}}

intgetminecount

(char board[rows]

[cols]

,int x,

int y)

void

nomine

(char mine[rows]

[cols]

,char show[rows]

[cols]

,int x,

int y)

else

show[x]

[y]= ret +

'0';

}void

findmine

(char mine[rows]

[cols]

,char show[rows]

[cols]

,int row,

int col)

else}}

else}if

(win >= row * col - easy_count)

}

#define _crt_secure_no_warnings 1

#include

#include

#include

#define row 9

#define col 9

#define rows row+2

#define cols col+2

#define easy_count 10

void

initboard

(char board[rows]

[cols]

,int rows,

int cols,

char set)

;void

display

(char board[rows]

[cols]

,int row,

int col)

;void

setmine

(char board[rows]

[cols]

,int row,

int col)

;void

findmine

(char mine[rows]

[cols]

,char show[rows]

[cols]

,int row,

int col)

;void

nomine

(char mine[rows]

[cols]

,char show[rows]

[cols]

,int x,

int y)

;

掃雷(C語言實現)(第一步不炸死,可實現展開)

掃雷遊戲大家應該都有玩過,今天的我們用c語言實現一下掃雷遊戲。點開時第一步不炸死,而且沒有雷的周圍會展開。實現思路 1.棋盤設計 必須要設計倆個棋盤,乙個設計者棋盤,乙個玩家棋盤。2.棋盤列印 列印棋盤 3.雷的布置 我的 中採用9 9的棋盤,布置了10個雷。用二維陣列來存棋盤的資訊,將二維陣列初始...

掃雷 關於展開空格的演算法

第一種 方法的相互呼叫 達到遞迴的效果 開啟盒子 public boolean click int x,int y else else else 判斷空白的格仔 public void clickblank int x,int y if x 1 1 x 1 9 grid x 1 y getconte...

antd Table 展開行可全部展開或關閉

有乙個需要實現的需求 可展開 可以全部展開或關閉。如下 技術實現前提 react antd table hooks tsx 在 antd table 上並沒有找到這個屬性,所以就自己上手來解決一下咯。實現思路 總體實現 展開行 可控 const expkeys,setexpkeys react.us...