import pygame
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
size = [700, 500]
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()
x_speed = 0
y_speed = 0
x_coord = 10
y_coord = 10
maze = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 1, 0, 1, 0, 1, 0, 1, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 1, 1],
[1, 0, 1, 0, 1, 1, 1, 0, 1, 1],
[1, 0, 1, 0, 0, 0, 1, 0, 1, 1],
[1, 0, 1, 1, 1, 0, 1, 0, 1, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]
while not done:
# This limits the while loop to a max of 10 times per second.
# Leave this out and we will use all CPU we can.
clock.tick(10)
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
# Clear the screen and set the screen background
screen.fill(BLACK)
# Draw the maze
for row in range(9):
for column in range(10):
if maze[row][column] == 1:
pygame.draw.rect(screen, WHITE, [(25 * column), (25 * row), 25, 25])
# Draw the runner
pygame.draw.rect(screen, WHITE, [x_coord, y_coord, 25, 25])
# Move the runner based on the key pressed
pressed = pygame.key.get_pressed()
if pressed[pygame.K_UP]:
y_speed = -5
elif pressed[pygame.K_DOWN]:
y_speed = 5
elif pressed[pygame.K_LEFT]:
x_speed = -5
elif pressed[pygame.K_RIGHT]:
x_speed = 5
# Update the position of the runner
x_coord += x_speed
y_coord += y_speed
# If the runner hits the edge of the screen, bounce it back
if x_coord > 675:
x_speed = -5
elif x_coord < 0:
x_speed = 5
if y_coord > 475:
y_speed = -5
elif y_coord < 0:
y_speed = 5
# If the runner hits a wall, stop it
if maze[int(y_coord / 25)][int(x_coord / 25)] == 1:
x_speed = 0
y_speed = 0
#Update the screen
pygame.display.flip()
pygame.quit()
```