@@ -140,45 +140,45 @@ def play_a_game():
140140 number_uncovered = 0
141141 touch_x = - 1
142142 touch_y = - 1
143- last_x = - 1
144- last_y = - 1
145- hold_count = 0
146- press = 0
147143 touch_time = 0
144+ wait_for_release = False
148145 while True :
149146 now = time .monotonic ()
150147 snapshot .update ()
151148 # if snapshot.fell:
152149 # save_pixels()
153150 # continue
154151 if now >= touch_time :
155- touch_time = now + 0.1
152+ touch_time = now + 0.2
153+
154+ # process touch
156155 touch_at = touchscreen .touch_point
157- if touch_at is not None :
156+ if touch_at is None :
157+ wait_for_release = False
158+ else :
159+ if wait_for_release :
160+ continue
161+ wait_for_release = True
158162 touch_x = max (min ([touch_at [0 ] // 16 , 19 ]), 0 )
159163 touch_y = max (min ([touch_at [1 ] // 16 , 14 ]), 0 )
160- if touch_x == last_x and touch_y == last_y :
161- hold_count += 1
162- else :
163- if hold_count > 5 :
164- press = 2
165- elif hold_count > 1 :
166- elif tilegrid [touch_x , touch_y ] == BLANK :
167- under_the_tile = get_data (touch_x , touch_y )
168- if under_the_tile == 14 :
169- reveal ()
170- tilegrid [touch_x , touch_y ] = BOMBDEATH
171- time .sleep (10.0 )
172- return False #lost
173- elif under_the_tile > OPEN0 and under_the_tile <= OPEN8 :
174- tilegrid [touch_x , touch_y ] = under_the_tile
175- elif under_the_tile == OPEN0 :
176- number_uncovered += expand_uncovered (touch_x , touch_y )
177- else :
178- print ('Unexpected value on board' )
179- return None #something bad happened
180- continue
181- if number_uncovered == 300 :
164+ print ('Touched (%d, %d)' % (touch_x , touch_y ))
165+ if tilegrid [touch_x , touch_y ] == BLANK :
166+ tilegrid [touch_x , touch_y ] = BOMBFLAGGED
167+ elif tilegrid [touch_x , touch_y ] == BOMBFLAGGED :
168+ under_the_tile = get_data (touch_x , touch_y )
169+ if under_the_tile == 14 :
170+ reveal ()
171+ tilegrid [touch_x , touch_y ] = BOMBDEATH
172+ return False #lost
173+ elif under_the_tile > OPEN0 and under_the_tile <= OPEN8 :
174+ tilegrid [touch_x , touch_y ] = under_the_tile
175+ elif under_the_tile == OPEN0 :
176+ tilegrid [touch_x , touch_y ] = BLANK
177+ number_uncovered += expand_uncovered (touch_x , touch_y )
178+ else :
179+ print ('Unexpected value on board' )
180+ return None #something bad happened
181+ if check_for_win ():
182182 return True #won
183183
184184def reset_board ():
0 commit comments