扫雷游戏核心库

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如何使用Spring的AnnotationMethodHandlerAdapter实现redirectafterpost表单?   使用“$”处理ANTLR异常,Java   从Oracle触发器启动Java Web应用程序中的进程   java如何从GWTUpload SingleUploader将照片保存到MySQL?   snappydata无法使用Java智能连接器从现有Spark安装访问snappydata存储   java将值设置/放入Springboot的Spring环境中供以后使用   java jsonsimple,从文件中读取   JavaSpring异步请求和每个线程的设置值   java如何从数组对象中删除符号并保存?   安卓如何从Java中的asynctask访问外部类中的公共变量?   java如何获取以下错误的崩溃点。它没有告诉我线路没有   曲线1D数组下的数学区域(Java)   java如何在第一个错误时停止验证?   java使用本机查询更新数据库中数据的最佳方法是什么   java事务如何真正工作简单用例(SpingBoot)?