@@ -165,6 +165,62 @@ def square_flagged(self, coords):
165165 break
166166 return True
167167
168+ def square_chorded (self , coords ):
169+ if self ._status in (STATUS_WON , STATUS_LOST ):
170+ return False
171+
172+ x , y = coords
173+ if self ._get_board (x , y ) in (OPEN1 , OPEN2 , OPEN3 , OPEN4 , OPEN5 , OPEN6 , OPEN7 , OPEN8 ):
174+ # Count the flags around this square
175+ flags = 0
176+ for dx in (- 1 , 0 , 1 ):
177+ if x + dx < 0 or x + dx >= self .grid_width :
178+ continue # off screen
179+ for dy in (- 1 , 0 , 1 ):
180+ if y + dy < 0 or y + dy >= self .grid_height :
181+ continue # off screen
182+ if dx == 0 and dy == 0 :
183+ continue # don't process where the mine
184+ if self ._get_board (x + dx , y + dy ) == FLAG :
185+ flags += 1
186+ if flags == self ._get_board (x , y ):
187+ # Uncover all non-flagged squares around here
188+ for dx in (- 1 , 0 , 1 ):
189+ if x + dx < 0 or x + dx >= self .grid_width :
190+ continue # off screen
191+ for dy in (- 1 , 0 , 1 ):
192+ if y + dy < 0 or y + dy >= self .grid_height :
193+ continue # off screen
194+ if dx == 0 and dy == 0 :
195+ continue # don't process where the mine
196+ if self ._get_board (x + dx , y + dy ) != FLAG :
197+ if not self .square_clicked ((x + dx , y + dy )):
198+ return False # lost
199+ return True
200+
201+ def square_chord_highlight (self , coords , highlight = True ):
202+ if self ._status in (STATUS_WON , STATUS_LOST ):
203+ return False
204+
205+ x , y = coords
206+ if self ._get_board (x , y ) in (OPEN1 , OPEN2 , OPEN3 , OPEN4 , OPEN5 , OPEN6 , OPEN7 , OPEN8 ):
207+ # Highlight all non-flagged squares around here
208+ for dx in (- 1 , 0 , 1 ):
209+ if x + dx < 0 or x + dx >= self .grid_width :
210+ continue # off screen
211+ for dy in (- 1 , 0 , 1 ):
212+ if y + dy < 0 or y + dy >= self .grid_height :
213+ continue # off screen
214+ if dx == 0 and dy == 0 :
215+ continue # don't process where the mine
216+ if highlight :
217+ if self ._get_board (x + dx , y + dy ) == BLANK :
218+ self ._set_board (x + dx , y + dy ,MINE_QUESTION_OPEN )
219+ else :
220+ if self ._get_board (x + dx , y + dy ) == MINE_QUESTION_OPEN :
221+ self ._set_board (x + dx , y + dy , BLANK )
222+ return True
223+
168224 def square_clicked (self , coords ):
169225 x , y = coords
170226
@@ -215,7 +271,9 @@ def check_for_win(self):
215271 # first make sure everything has been explored and decided
216272 for x in range (self .grid_width ):
217273 for y in range (self .grid_height ):
218- if self ._get_board (x , y ) == BLANK or self ._get_board (x , y ) == MINE_QUESTION :
274+ if self ._get_board (x , y ) == BLANK or \
275+ self ._get_board (x , y ) == MINE_QUESTION or \
276+ self ._get_board (x , y ) == MINE_QUESTION_OPEN :
219277 return None # still ignored or question squares
220278 # then check for mistagged bombs
221279 for x in range (self .grid_width ):
0 commit comments