mirror of
				https://github.com/d3vyce/Python-Game.git
				synced 2025-10-31 15:34:56 +01:00 
			
		
		
		
	Add error handling
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | from ast import Break | ||||||
| import pygame | import pygame | ||||||
| from pygame.locals import * | from pygame.locals import * | ||||||
| import src.level as level | import src.level as level | ||||||
| @@ -19,11 +20,21 @@ def main(): | |||||||
|  |  | ||||||
|     matrix = level.init_level(HEIGH, WIDTH) |     matrix = level.init_level(HEIGH, WIDTH) | ||||||
|     matrix[5][5] = 1 |     matrix[5][5] = 1 | ||||||
|     matrix[5][6] = 2 |     matrix[5][6] = 1 | ||||||
|     level.spawn_apple(matrix, HEIGH, WIDTH) |     level.spawn_apple(matrix, HEIGH, WIDTH) | ||||||
|     #print(matrix) |     #print(matrix) | ||||||
|  |  | ||||||
|  |     try: | ||||||
|         L_snake = snake.Snake_move(matrix, L_snake, "right") |         L_snake = snake.Snake_move(matrix, L_snake, "right") | ||||||
|  |     except ValueError as Error: | ||||||
|  |         if Error.args[0] == 1: | ||||||
|  |             print("You take a wall !") | ||||||
|  |         elif Error.args[0] == 2: | ||||||
|  |             print("You ate your tale !") | ||||||
|  |          | ||||||
|  |         exit() | ||||||
|  |      | ||||||
|  |      | ||||||
|     print(L_snake) |     print(L_snake) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user