Skip to content

Commit 3f4559d

Browse files
Merge pull request #2498 from avinashkranjan/deepsource-transform-fbb2205b
format code with autopep8
2 parents d6071a1 + e52e51a commit 3f4559d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Maze Generator and Solver/maze_game.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
RED = (255, 0, 0)
1212
GREEN = (0, 255, 0)
1313

14+
1415
class Cell:
1516
WALL = 0
1617
PATH = 1
1718
VISITED = 2
1819

20+
1921
maze = [[Cell.WALL for _ in range(MAZE_WIDTH)] for _ in range(MAZE_HEIGHT)]
2022

23+
2124
def generate_maze(x, y):
2225
maze[y][x] = Cell.VISITED
2326
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
@@ -29,6 +32,7 @@ def generate_maze(x, y):
2932
maze[y + dy][x + dx] = Cell.PATH
3033
generate_maze(nx, ny)
3134

35+
3236
class Player:
3337
def __init__(self, x, y):
3438
self.x = x
@@ -40,6 +44,7 @@ def move(self, dx, dy):
4044
self.x = new_x
4145
self.y = new_y
4246

47+
4348
player = Player(1, 1)
4449

4550
pygame.init()
@@ -59,7 +64,8 @@ def move(self, dx, dy):
5964
running = False
6065
elif event.type == pygame.KEYDOWN:
6166
if event.key == pygame.K_r:
62-
maze = [[Cell.WALL for _ in range(MAZE_WIDTH)] for _ in range(MAZE_HEIGHT)]
67+
maze = [[Cell.WALL for _ in range(
68+
MAZE_WIDTH)] for _ in range(MAZE_HEIGHT)]
6369
generate_maze(0, 0)
6470
start_point = (1, 1)
6571
end_point = (MAZE_WIDTH - 2, MAZE_HEIGHT - 2)
@@ -79,22 +85,29 @@ def move(self, dx, dy):
7985
for y in range(MAZE_HEIGHT):
8086
for x in range(MAZE_WIDTH):
8187
if maze[y][x] == Cell.WALL:
82-
pygame.draw.rect(window, BLACK, (x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
88+
pygame.draw.rect(window, BLACK, (x * CELL_SIZE,
89+
y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
8390
elif maze[y][x] == Cell.PATH:
84-
pygame.draw.rect(window, WHITE, (x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
91+
pygame.draw.rect(window, WHITE, (x * CELL_SIZE,
92+
y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
8593
elif maze[y][x] == Cell.VISITED:
86-
pygame.draw.rect(window, GREEN, (x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
94+
pygame.draw.rect(window, GREEN, (x * CELL_SIZE,
95+
y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
8796

8897
for x, y in path:
89-
pygame.draw.rect(window, RED, (x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
98+
pygame.draw.rect(window, RED, (x * CELL_SIZE, y *
99+
CELL_SIZE, CELL_SIZE, CELL_SIZE))
90100

91-
pygame.draw.rect(window, GREEN, (end_point[0] * CELL_SIZE, end_point[1] * CELL_SIZE, CELL_SIZE, CELL_SIZE))
101+
pygame.draw.rect(
102+
window, GREEN, (end_point[0] * CELL_SIZE, end_point[1] * CELL_SIZE, CELL_SIZE, CELL_SIZE))
92103

93104
if (player.x, player.y) == end_point:
94105
elapsed_time = time.time() - start_time
95-
pygame.draw.rect(window, GREEN, (end_point[0] * CELL_SIZE, end_point[1] * CELL_SIZE, CELL_SIZE, CELL_SIZE))
106+
pygame.draw.rect(
107+
window, GREEN, (end_point[0] * CELL_SIZE, end_point[1] * CELL_SIZE, CELL_SIZE, CELL_SIZE))
96108
font = pygame.font.SysFont(None, 40)
97-
text = font.render(f"Congratulations! Time: {elapsed_time:.2f} seconds", True, BLACK)
109+
text = font.render(
110+
f"Congratulations! Time: {elapsed_time:.2f} seconds", True, BLACK)
98111
window.blit(text, (10, WINDOW_HEIGHT - 40))
99112
else:
100113
path = []
@@ -118,4 +131,4 @@ def move(self, dx, dy):
118131

119132
pygame.display.update()
120133

121-
pygame.quit()
134+
pygame.quit()

0 commit comments

Comments
 (0)