Skip to content

Commit 10cd5da

Browse files
committed
random_maze.py: display qwstpad errors
1 parent abb947f commit 10cd5da

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/random_maze.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
BACKGROUND = display.create_pen(60, 57, 169)
4848
PATH = display.create_pen((227 + 60) // 2, (231 + 57) // 2, (110 + 169) // 2)
4949

50+
51+
def show_message(text):
52+
display.set_pen(BACKGROUND)
53+
display.clear()
54+
display.set_pen(WALL)
55+
display.text(f"{text}", 5, 10, WIDTH, 2)
56+
presto.update()
57+
58+
5059
# Gameplay Constants
5160
Position = namedtuple("Position", ("x", "y"))
5261
MIN_MAZE_WIDTH = 2
@@ -286,8 +295,8 @@ def build_maze():
286295
try:
287296
player = Player(*start, PLAYER, QwSTPad(i2c, I2C_ADDRESS))
288297
except OSError:
289-
print("QwSTPad: Not Connected ... Exiting")
290-
raise SystemExit
298+
while True:
299+
show_message("QwSTPad: Not Found!\n\nConnect a QwSTPad and try again :)")
291300

292301
print("QwSTPad: Connected ... Starting")
293302

@@ -371,7 +380,7 @@ def build_maze():
371380

372381
# Handle the QwSTPad being disconnected unexpectedly
373382
except OSError:
374-
print("QwSTPad: Disconnected .. Exiting")
383+
show_message("QwSTPad: Disconnected!")
375384

376385
# Turn off the LEDs of the connected QwSTPad
377386
finally:

0 commit comments

Comments
 (0)