diff --git a/Metro/Metro_RP2350_Snake/code.py b/Metro/Metro_RP2350_Snake/code.py index 3c25a99da..f6031cff8 100644 --- a/Metro/Metro_RP2350_Snake/code.py +++ b/Metro/Metro_RP2350_Snake/code.py @@ -157,6 +157,10 @@ # read it into cur_btn_val cur_btn_val = sys.stdin.read(available) + # change to lower-case before comparison + # so that it's case-insensitive. + cur_btn_val = cur_btn_val.lower() + else: # no keyboard input # set to None to clear out previous value cur_btn_val = None @@ -173,31 +177,31 @@ # if game is being played elif CURRENT_STATE == STATE_PLAYING: # if up button was pressed - if cur_btn_val == KEY_UP: + if cur_btn_val == KEY_UP.lower(): # if the snake is not already moving up or down if snake.direction not in (snake.DIRECTION_DOWN, snake.DIRECTION_UP): # change the direction to up snake.direction = snake.DIRECTION_UP # if down button was pressed - if cur_btn_val == KEY_DOWN: + if cur_btn_val == KEY_DOWN.lower(): # if the snake is not already moving up or down if snake.direction not in (snake.DIRECTION_DOWN, snake.DIRECTION_UP): # change the direction to down snake.direction = snake.DIRECTION_DOWN # if right button was pressed - if cur_btn_val == KEY_RIGHT: + if cur_btn_val == KEY_RIGHT.lower(): # if the snake is not already moving left or right if snake.direction not in (snake.DIRECTION_LEFT, snake.DIRECTION_RIGHT): # change the direction to right snake.direction = snake.DIRECTION_RIGHT # if left button was pressed - if cur_btn_val == KEY_LEFT: + if cur_btn_val == KEY_LEFT.lower(): # if the snake is not already moving left or right if snake.direction not in (snake.DIRECTION_LEFT, snake.DIRECTION_RIGHT): # change direction to left snake.direction = snake.DIRECTION_LEFT # if the pause button was pressed - if cur_btn_val == KEY_PAUSE: + if cur_btn_val == KEY_PAUSE.lower(): # change the state to paused CURRENT_STATE = STATE_PAUSED @@ -245,19 +249,19 @@ # if the game is paused elif CURRENT_STATE == STATE_PAUSED: # if the pause button was pressed - if cur_btn_val == KEY_PAUSE: + if cur_btn_val == KEY_PAUSE.lower(): # change the state to playing so the game resumes CURRENT_STATE = STATE_PLAYING # if the current state is game over elif CURRENT_STATE == STATE_GAME_OVER: # if the p button is pressed for play again - if cur_btn_val == "p": + if cur_btn_val in {"p", "P"}: # set next code file to this one supervisor.set_next_code_file(__file__) # reload supervisor.reload() # if the q button is pressed for exit - if cur_btn_val == "q": + if cur_btn_val in {"q", "Q"}: # break out of main while True loop. break