Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_MineSweeper.py ZZZ
- from Tkinter import *
- import random
- root1 = Tk()
- root1.title("Tk_MineSweeper")
- root1.geometry("250x250")
- botton = Button(root1, width=12, height=3, text='New Game', font="Arial 10")
- botton.place(x=80, y=20)
- Label(root1, text='Difficulty:', width=20, height=3, font="Arial 12").place(x=0, y=80)
- hard = DoubleVar()
- hard.set(0.2)
- rad0 = Radiobutton(root1, text="1", variable=hard, value=0.15).place(x=0, y=130)
- rad1 = Radiobutton(root1, text="2", variable=hard, value=0.2).place(x=0, y=170)
- rad2 = Radiobutton(root1, text="3", variable=hard, value=0.25).place(x=0, y=210)
- def init(event):
- root1.destroy()
- root = Tk()
- root.title("New Game")
- my_list =[]
- all_buttons = []
- v = hard.get()
- polerow = 9
- polecolumn = 9
- matrix = []
- pole = []
- game_pole = []
- my_list = [[0 for i in range(polerow)] for j in range(polecolumn)]
- all_buttons = []
- pole = [[0 for i in range(polerow)] for j in range(polecolumn)]
- matrix = [['*' if random.random() < 0.15 else '' for i in range(9)] for j in range(9)]
- def creaMatriz():
- for y, row in enumerate(my_list):
- buttons_row = []
- for x, element in enumerate(row):
- btn2 = Button(root, text="", width=6, height=3, command=lambda a=x, b=y: onButtonPressed(a, b))
- btn2.grid(row=y, column=x)
- buttons_row.append(btn2)
- all_buttons.append(buttons_row)
- def game_polle():
- for a in range(polerow): # a=0,1,2,3,4,5
- for b in range(polecolumn): # b=0,1,2,3,4,5
- if matrix[a][b] == "*":
- for c in range((a-1), (a+2)):
- for d in range((b-1), (b+2)):
- if c >= 0 and d >=0 and c <= (polerow-1) and d <= (polecolumn-1) and matrix[c][d] != '*':
- pole[c][d] = pole[c][d] + 1
- elif c >= 0 and d >= 0 and c <= (polerow-1) and d <= (polecolumn-1):
- pole[c][d] = '*'
- return pole
- qwer = game_polle()
- def onButtonPressed(x, y):
- all_buttons[y][x]['text'] = str(qwer[x][y])
- creaMatriz()
- root.mainloop()
- botton.bind("<Button-1>", init)
- root1.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement