@@ -81,7 +81,7 @@ def setup(self):
81
81
isMine = True
82
82
self .mines += 1
83
83
84
- self . tiles [ x ][ y ] = {
84
+ tile = {
85
85
"id" : id ,
86
86
"isMine" : isMine ,
87
87
"state" : STATE_DEFAULT ,
@@ -93,11 +93,11 @@ def setup(self):
93
93
"mines" : 0 # calculated after grid is built
94
94
}
95
95
96
- self .tiles [x ][y ]["button" ].bind (BTN_CLICK , self .onClickWrapper (x , y ))
97
- self .tiles [x ][y ]["button" ].bind (BTN_FLAG , self .onRightClickWrapper (x , y ))
96
+ tile ["button" ].bind (BTN_CLICK , self .onClickWrapper (x , y ))
97
+ tile ["button" ].bind (BTN_FLAG , self .onRightClickWrapper (x , y ))
98
+ tile ["button" ].grid ( row = x + 1 , column = y ) # offset by 1 row for timer
98
99
99
- # lay buttons in grid, offset by 1 row for timer
100
- self .tiles [x ][y ]["button" ].grid ( row = x + 1 , column = y )
100
+ self .tiles [x ][y ] = tile
101
101
102
102
# loop again to find nearby mines and display number on tile
103
103
for x in range (0 , SIZE_X ):
@@ -223,21 +223,21 @@ def clearSurroundingTiles(self, id):
223
223
x = int (parts [0 ])
224
224
y = int (parts [1 ])
225
225
226
- for n in self .getNeighbors (x , y ):
227
- self .clearTile (n [ "coords" ][ "x" ], n [ "coords" ][ "y" ] , queue )
228
-
229
- def clearTile (self , x , y , queue ):
230
- try :
231
- if self . tiles [ x ][ y ][ "state" ] == STATE_DEFAULT :
232
- if self . tiles [ x ][ y ][ "mines" ] == 0 :
233
- self . tiles [ x ][ y ][ "button" ]. config ( image = self . images [ "clicked" ])
234
- queue . append ( self .tiles [ x ][ y ][ "id " ])
235
- else :
236
- self . tiles [ x ][ y ][ "button" ]. config ( image = self . images [ "numbers" ][ self . tiles [ x ][ y ][ "mines" ] - 1 ])
237
- self .tiles [ x ][ y ][ "state" ] = STATE_CLICKED
238
- self . clickedCount += 1
239
- except KeyError :
240
- pass
226
+ for tile in self .getNeighbors (x , y ):
227
+ self .clearTile (tile , queue )
228
+
229
+ def clearTile (self , tile , queue ):
230
+ if tile [ "state" ] != STATE_DEFAULT :
231
+ return
232
+
233
+ if tile [ "mines" ] == 0 :
234
+ tile [ "button" ]. config ( image = self .images [ "clicked " ])
235
+ queue . append ( tile [ "id" ])
236
+ else :
237
+ tile [ "button" ]. config ( image = self .images [ "numbers" ][ tile [ "mines" ] - 1 ])
238
+
239
+ tile [ "state" ] = STATE_CLICKED
240
+ self . clickedCount += 1
241
241
242
242
### END OF CLASSES ###
243
243
0 commit comments