|
3 | 3 |
|
4 | 4 | from tkinter import * |
5 | 5 | from tkinter import messagebox as tkMessageBox |
| 6 | +from collections import deque |
6 | 7 | import random |
7 | 8 | import platform |
8 | | -from collections import deque |
| 9 | +import time |
9 | 10 |
|
10 | 11 | STATE_DEFAULT = 0 |
11 | 12 | STATE_CLICKED = 1 |
@@ -120,13 +121,6 @@ def rclicked_wrapper(self, x, y): |
120 | 121 |
|
121 | 122 | def lclicked(self, button_data): |
122 | 123 | if button_data["isMine"] == True: |
123 | | - # show all mines and check for flags |
124 | | - for x in range(0, 10): |
125 | | - for y in range (0, 10): |
126 | | - if self.buttons[x][y]["isMine"] == False and self.buttons[x][y]["state"] == STATE_FLAGGED: |
127 | | - self.buttons[x][y]["widget"].config(image = self.tiles["wrong"]) |
128 | | - if self.buttons[x][y]["isMine"] == True and self.buttons[x][y]["state"] != STATE_FLAGGED: |
129 | | - self.buttons[x][y]["widget"].config(image = self.tiles["mine"]) |
130 | 124 | # end game |
131 | 125 | self.gameover() |
132 | 126 | else: |
@@ -197,13 +191,21 @@ def clear_empty_tiles(self, id): |
197 | 191 | self.check_tile(source_x+1, source_y+1, queue) #bottom left |
198 | 192 |
|
199 | 193 | def gameover(self): |
200 | | - tkMessageBox.showinfo("Game Over", "You Lose!") |
| 194 | + for x in range(0, 10): |
| 195 | + for y in range (0, 10): |
| 196 | + if self.buttons[x][y]["isMine"] == False and self.buttons[x][y]["state"] == STATE_FLAGGED: |
| 197 | + self.buttons[x][y]["widget"].config(image = self.tiles["wrong"]) |
| 198 | + if self.buttons[x][y]["isMine"] == True and self.buttons[x][y]["state"] != STATE_FLAGGED: |
| 199 | + self.buttons[x][y]["widget"].config(image = self.tiles["mine"]) |
201 | 200 | global root |
| 201 | + root.update() |
| 202 | + tkMessageBox.showinfo("Game Over", "You Lose!") |
202 | 203 | root.destroy() |
203 | 204 |
|
204 | 205 | def victory(self): |
205 | | - tkMessageBox.showinfo("Game Over", "You Win!") |
206 | 206 | global root |
| 207 | + root.update() |
| 208 | + tkMessageBox.showinfo("Game Over", "You Win!") |
207 | 209 | root.destroy() |
208 | 210 |
|
209 | 211 | def update_flags(self): |
|
0 commit comments