扫雷游戏核心库

pygame-minesweeper-core的Python项目详细描述


Build StatusPyPI - LicensePyPIAzure DevOps coverage

简介

这个扫雷舰核心库包含了游戏的基本功能。在

扫雷是一款单人益智电脑游戏。这个游戏的目标是清除一块长方形的棋盘,里面有隐藏的“地雷”或炸弹,而不引爆其中任何一枚,借助于每个领域中相邻地雷数量的线索。这款游戏起源于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类时,您只需要关注少数几个方法和属性,这些方法和属性包括:

methodsreturns
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) -> boolReturns true if i and j is inside boundaries
^{tb2}$

木板

propertiesreturns
i -> intThe row of the tile
j -> intthe columns of the tile
type -> strstring representation of the tile
number -> intint representation of the tile
staticreturns
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

参考文献

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在jetty请求日志中添加milliscond字段?   java在使用Scanner类从文件读取信息时遇到问题   为什么。类不适用于泛型类型?   SQLite插入上的java空指针异常   java能告诉我们Guava缓存是在禁用统计数据的情况下构建的吗?   java在应用程序中使用常量   java无法使用AutoIT和Selenium Webdriver在所需位置/文件夹保存图像   java如何在jtable中更新jprogress栏   java是比较给定日期和当前日期(在给定时区中没有时间段)的最佳方法   安卓代码中的java错误   java无法访问实体类中的字段   java如何在tomcat中处理三个JDBC连接池?   java无法使用Spring Security保护AngularJS页面   如何在没有TCP/IP协议栈的情况下用Java发送以太帧