继续我的自我学习,并制作了一个基本的扫雷游戏...单击以揭示该盒子周围有多少个“矿山”或“矿山”的红色。右键单击以将您认为是矿山的位置,正方形变成蓝色...出于某种原因,右键单击可能有点气质,并以常规点击注册。谁能告诉我这是笔记本电脑鼠标还是代码的问题?如果有一种简单的方法来更改代码以更改网格的大小和“矿山”的数量,那就太好了!导入tkinter导入随机gameover = false score = 0 Squarestoclear = 0
def play_minesweeper():create_bombfield(bombfield)window = tkinter.tk()layout_window(window)window.mainloop()
bombfield = [] def create_bombfield(bombfield): global squaresToClear for row in range(0,10): rowList = [] for column in range(0,10): if random.randint(1,100) <20: rowList.append(1) else: rowList.append(0) squaresToClear = squaresToClear + 1 bombfield.append(rowList) #printfield(bombfield) def printfield(Bombfield):对于Bombfield的Rowlist:Print(Rowlist)
def layout_window(窗口):对于届时,枚举(bombfield)中的rowlist:对于columnnumber,columnentry in Enumerate(rowlist)中的columnentry(rowlant):如果Randy.randint(1,100)<35:square = tkinter.tkinter.label.label.label.label(window = window = text,text =“,bg =”,bg =“ tkinter.label(窗口,text =“”,bg =“ seagreen”)else:square = tkinter.label(window,text,text =“”,bg =“ green”)square.grid(row = rownumber,columnnumber,columnnumber) int(square.grid_info()[“ row”])列= int(square.grid_info()[“列”])square.config(bg =“ blue”)
def on_click(事件):全局分数全局squarestoclear square = event.widget row = int(square.grid_info()[“ row”])列= int = int(square.grid_info()打印(“游戏结束!您击中炸弹。”)print(“您的得分是:”,得分) 0: if bombfield[row][column-1] == 1: totalBombs = totalBombs + 1 if column < 9: if bombfield[row][column+1] == 1: totalBombs = totalBombs + 1 if row > 0 and column > 0: if bombfield[row-1][column-1] == 1: totalBombs = totalBombs + 1 if row < 9 and column > 0: if bombfield[row+1][column-1] == 1: totalBombs = totalBombs + 1 if row > 0 and column < 9: if bombfield[row-1][column+1] == 1: totalBombs = totalBombs + 1 if row < 9 and column < 9: if bombfield[row+1][column+1] == 1: totalBombs = totalBombs + 1 square.config(text = " " + str(totalBombs) + " ") squaresToClear = squaresToClear - 1分数=得分 + 1如果SquareStoclear == 0:GameOver = true Print(“做得好!您找到了所有安全的正方形!”)print(“您的得分是:”,得分)