def handle_key(key): """Handles key events in the game""" direction = DIRECTIONS.get(key) if direction: move(maze, direction) img = draw_grid(maze, tile_img, tiles) display.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224))) pygame.display.update()
def handle_key(key): """Obsluguje zdarzenia nacisniecia klawiszy w grze""" direction = DIRECTIONS.get(key) if direction: move(maze, DIRECTIONS.get(key)) img = draw_grid(maze, tile_img, tiles) display.blit(img, Rect(0, 0, 384, 224), Rect(0, 0, 384, 224)) pygame.display.update()
def draw(): """Displays the maze on the screen""" img = draw_grid(maze, tile_img, tiles) display.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224))) pygame.display.update()
import pygame # initialize display pygame.init() pygame.display.set_mode((800, 600)) display = pygame.display.get_surface() # prepare the maze maze = parse_grid(create_maze(12, 7)) maze[1][1] = '*' maze[5][10] = 'x' # draw the graphics tile_img, tiles = load_tiles() img = draw_grid(maze, tile_img, tiles) display.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224))) pygame.display.update() # start the game DIRECTIONS = { 276: LEFT, 275: RIGHT, 273: UP, 274: DOWN } def handle_key(key): """Handles key events in the game""" direction = DIRECTIONS.get(key)
if level[newy][newx] == 'x': sys.exit(0) if level[newy][newx] != '#': #level[oldy][oldx] = ' ' level[newy][newx] = '*' level[oldy][oldx] = ' ' if __name__ == '__main__': tile_img, tiles = load_tiles() maze = create_maze(12, 7) maze = parse_grid(maze) maze[1][1] = '*' for i in range(100): direction = random.choice([LEFT, RIGHT, UP, DOWN]) move(maze, direction) img = draw_grid(maze, tile_img, tiles) image.save(img, 'moved.png')