扫雷游戏核心库
pygame-minesweeper-core的Python项目详细描述
简介
这个扫雷舰核心库包含了游戏的基本功能。在
扫雷是一款单人益智电脑游戏。这个游戏的目标是清除一块长方形的棋盘,里面有隐藏的“地雷”或炸弹,而不引爆其中任何一枚,借助于每个领域中相邻地雷数量的线索。这款游戏起源于20世纪60年代,为当今使用的许多计算平台编写。它有许多变体和分支。在
动机
这些扫雷项目的动机是学习python项目的工具,如何为python项目创建CI/CD管道,以及分发python鸡蛋。在
入门
安装
python3 -m pip install pygame-minesweeper-core
# or
pip install pygame-minesweeper-core
总则
这个库板和图板有两个类。Board类包含整个棋盘/游戏的数据,而BoardTile类只包含单个棋盘的数据。要初始化新游戏,请创建一个具有所需参数的Board类。一块板总是随机生成的,第一块被打开的瓦片永远不会包含地雷。如果一个空的磁贴被打开,相邻的磁贴也会被打开。在
板
^{pr2}$在使用Board类时,您只需要关注少数几个方法和属性,这些方法和属性包括:
methods | returns |
---|---|
game_new(self, rows: int, cols: int, mines: int): | initialize a new game with given parameters |
game_reset() | initialize a new game with the same parameters |
tile_open(i: int, j: int) -> List[BoardTile] | The value i is the row/y-axis and j is the col/x-axis. The function returns a list of BoardTiles objects that represents tiles that get opened. The function will return an empty list if you try to open a tile that is already opened, if the game is lost or won, or if you open tile that is out of bounds. The functions open adjacent tiles recursively if the tile has zero adjacent mines. The first tiles that get opened can never be a mine. |
tile_valid(i : int, j : int) -> bool | Returns true if i and j is inside boundaries |
木板
properties | returns |
---|---|
i -> int | The row of the tile |
j -> int | the columns of the tile |
type -> str | string representation of the tile |
number -> int | int representation of the tile |
static | returns |
---|---|
mine | "x" |
unopened | "t" |
zero | "0" |
one | "1" |
two | "2" |
three | "3" |
four | "4" |
five | "5" |
six | "6" |
seven | "7" |
eight | "8" |
示例
fromminesweeperimportcoredefmain():board=core.Board(rows=10,cols=10,mines=30)tiles=board.tile_open(5,5)fortileintiles:print(f"tile={tile.type}, ({tile.i}, {tile.j})")print(board.is_game_over)print(board.is_game_finished)print(board)print(board.solution)if__name__=="__main__":main()
# Outputstile=0, (5, 5)tile=1, (5, 6)tile=0, (5, 4)tile=2, (5, 3)tile=1, (6, 4)tile=0, (6, 5)tile=0, (6, 6)tile=0, (6, 7)tile=1, (6, 8)tile=1, (7, 7)tile=1, (7, 8)tile=2, (7, 6)tile=1, (5, 7)tile=2, (5, 8)tile=1, (7, 5)tile=2, (7, 4)tile=3, (6, 3)tile=1, (4, 4)tile=0, (4, 5)tile=1, (4, 6)tile=1, (3, 5)tile=2, (3, 6)tile=2, (3, 4)tile=4, (4, 3) False False t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t 212 t t t t t t 4101 t t t t t t 200112 t t t t 310001 t t t t t 21211 t t t t t t t t t t t t t t t t t t t t t x 33 x x 3 x 2 x x 3 x x 34 x 323 x 2 x 533 x 212224 x x 2122 x 1 x 5 x 4101 x 32 x 5 x 200112 x x 43310001112 x x 21211001333 x 3 x 32001 x 22 x 3 x x
参考文献
- 项目
标签: