summaryrefslogtreecommitdiff
path: root/maze.py
diff options
context:
space:
mode:
authoryuzu-eva <stevenhu@web.de>2024-11-11 15:52:22 +0100
committeryuzu-eva <stevenhu@web.de>2024-11-11 15:52:22 +0100
commit696199a0227cfccb2247978b1ba8c1b03f1ae26d (patch)
tree493c3f65fdb65634c1577529bcfbf76356d9ec4f /maze.py
initial commit
Diffstat (limited to 'maze.py')
-rw-r--r--maze.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/maze.py b/maze.py
new file mode 100644
index 0000000..71086cb
--- /dev/null
+++ b/maze.py
@@ -0,0 +1,51 @@
+from cell import Cell
+import time
+
+class Maze:
+ def __init__(
+ self,
+ x1,
+ y1,
+ num_rows,
+ num_cols,
+ cell_size_x,
+ cell_size_y,
+ win=None
+ ):
+ self._cells = []
+ self._x1 = x1
+ self._y1 = y1
+ self._num_rows = num_rows
+ self._num_cols = num_cols
+ self._cell_size_x = cell_size_x
+ self._cell_size_y = cell_size_y
+ self._win = win
+
+ self._create_cells()
+ self._break_entrance_and_exit()
+
+ def _create_cells(self):
+ self._cells = [[Cell(self._win)]*self._num_rows for i in range(self._num_cols)]
+ for i in range(self._num_cols):
+ for j in range(self._num_rows):
+ self._draw_cell(i, j)
+
+ def _draw_cell(self, i, j):
+ if self._win is None:
+ return
+ x1 = self._x1 + i * self._cell_size_x
+ y1 = self._y1 + j * self._cell_size_y
+ x2 = x1 + self._cell_size_x
+ y2 = y1 + self._cell_size_x
+ self._cells[i][j].draw(x1, y1, x2, y2)
+ self._animate()
+
+ def _animate(self):
+ self._win.redraw()
+ time.sleep(0.01)
+
+ def _break_entrance_and_exit(self):
+ self._cells[0][0].twall = False
+ self._draw_cell(0, 0)
+ self._cells[-1][-1].bwall = False
+ self._draw_cell(self._num_cols-1, self._num_rows-1)