-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (35 loc) · 1.15 KB
/
main.py
File metadata and controls
44 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from graphics import Window
from maze import Maze
import sys
def main():
num_rows = 18
num_cols = 24
margin = 50
screen_x = 1000
screen_y = 750
cell_size_x = (screen_x - 2 * margin) / num_cols
cell_size_y = (screen_y - 2 * margin) / num_rows
sys.setrecursionlimit(10000)
win = Window(screen_x, screen_y)
# This function will create a new maze and solve it
def create_and_solve_maze():
# Clear the canvas first if this is a reset
win._Window__canvas.delete("all")
maze = Maze(margin, margin, num_rows, num_cols, cell_size_x, cell_size_y, win)
print("maze created")
is_solvable = maze.solve()
if not is_solvable:
print("maze can not be solved!")
else:
print("maze solved!")
print("Press spacebar to generate a new maze")
# Create the first maze
create_and_solve_maze()
# Bind the spacebar to reset
def reset_maze(event):
print("Resetting maze...")
create_and_solve_maze()
win.bind_key("<space>", reset_maze)
# Wait for window close
win.wait_for_close()
main()