|
177 | 177 | # if game is being played |
178 | 178 | elif CURRENT_STATE == STATE_PLAYING: |
179 | 179 | # if up button was pressed |
180 | | - if cur_btn_val == KEY_UP: |
| 180 | + if cur_btn_val == KEY_UP.lower(): |
181 | 181 | # if the snake is not already moving up or down |
182 | 182 | if snake.direction not in (snake.DIRECTION_DOWN, snake.DIRECTION_UP): |
183 | 183 | # change the direction to up |
184 | 184 | snake.direction = snake.DIRECTION_UP |
185 | 185 | # if down button was pressed |
186 | | - if cur_btn_val == KEY_DOWN: |
| 186 | + if cur_btn_val == KEY_DOWN.lower(): |
187 | 187 | # if the snake is not already moving up or down |
188 | 188 | if snake.direction not in (snake.DIRECTION_DOWN, snake.DIRECTION_UP): |
189 | 189 | # change the direction to down |
190 | 190 | snake.direction = snake.DIRECTION_DOWN |
191 | 191 | # if right button was pressed |
192 | | - if cur_btn_val == KEY_RIGHT: |
| 192 | + if cur_btn_val == KEY_RIGHT.lower(): |
193 | 193 | # if the snake is not already moving left or right |
194 | 194 | if snake.direction not in (snake.DIRECTION_LEFT, snake.DIRECTION_RIGHT): |
195 | 195 | # change the direction to right |
196 | 196 | snake.direction = snake.DIRECTION_RIGHT |
197 | 197 | # if left button was pressed |
198 | | - if cur_btn_val == KEY_LEFT: |
| 198 | + if cur_btn_val == KEY_LEFT.lower(): |
199 | 199 | # if the snake is not already moving left or right |
200 | 200 | if snake.direction not in (snake.DIRECTION_LEFT, snake.DIRECTION_RIGHT): |
201 | 201 | # change direction to left |
202 | 202 | snake.direction = snake.DIRECTION_LEFT |
203 | 203 | # if the pause button was pressed |
204 | | - if cur_btn_val == KEY_PAUSE: |
| 204 | + if cur_btn_val == KEY_PAUSE.lower(): |
205 | 205 | # change the state to paused |
206 | 206 | CURRENT_STATE = STATE_PAUSED |
207 | 207 |
|
|
249 | 249 | # if the game is paused |
250 | 250 | elif CURRENT_STATE == STATE_PAUSED: |
251 | 251 | # if the pause button was pressed |
252 | | - if cur_btn_val == KEY_PAUSE: |
| 252 | + if cur_btn_val == KEY_PAUSE.lower(): |
253 | 253 | # change the state to playing so the game resumes |
254 | 254 | CURRENT_STATE = STATE_PLAYING |
255 | 255 |
|
256 | 256 | # if the current state is game over |
257 | 257 | elif CURRENT_STATE == STATE_GAME_OVER: |
258 | 258 | # if the p button is pressed for play again |
259 | | - if cur_btn_val == "p": |
| 259 | + if cur_btn_val in {"p", "P"}: |
260 | 260 | # set next code file to this one |
261 | 261 | supervisor.set_next_code_file(__file__) |
262 | 262 | # reload |
263 | 263 | supervisor.reload() |
264 | 264 | # if the q button is pressed for exit |
265 | | - if cur_btn_val == "q": |
| 265 | + if cur_btn_val in {"q", "Q"}: |
266 | 266 | # break out of main while True loop. |
267 | 267 | break |
0 commit comments