checkpoint: setting up breaking of walls
This commit is contained in:
parent
6d919a99d6
commit
19a29bbb5b
2 changed files with 50 additions and 8 deletions
49
cell.py
49
cell.py
|
@ -52,6 +52,8 @@ class Cell:
|
|||
# A reference to the root Window class for drawing purposes.
|
||||
self._window = window
|
||||
|
||||
self.visited = False
|
||||
|
||||
def configure_walls(
|
||||
self,
|
||||
top: bool = True,
|
||||
|
@ -73,6 +75,13 @@ class Cell:
|
|||
"""
|
||||
return self._centre
|
||||
|
||||
#def break_walls_r(self, i: int, j: int) -> None:
|
||||
# self.visited = True
|
||||
# while True:
|
||||
# list_i = []
|
||||
# list_j = []
|
||||
# break
|
||||
|
||||
def draw(self) -> None:
|
||||
"""
|
||||
draw draws the cell onto the canvas
|
||||
|
@ -81,24 +90,48 @@ class Cell:
|
|||
return
|
||||
|
||||
if self._top_wall.exists:
|
||||
self._window.draw_line(self._top_wall.line, fill_colour=self._window.cell_grid_colour)
|
||||
self._window.draw_line(
|
||||
self._top_wall.line,
|
||||
fill_colour=self._window.cell_grid_colour,
|
||||
)
|
||||
else:
|
||||
self._window.draw_line(self._top_wall.line, fill_colour=self._window.background_colour)
|
||||
self._window.draw_line(
|
||||
self._top_wall.line,
|
||||
fill_colour=self._window.background_colour,
|
||||
)
|
||||
|
||||
if self._bottom_wall.exists:
|
||||
self._window.draw_line(self._bottom_wall.line, fill_colour=self._window.cell_grid_colour)
|
||||
self._window.draw_line(
|
||||
self._bottom_wall.line,
|
||||
fill_colour=self._window.cell_grid_colour,
|
||||
)
|
||||
else:
|
||||
self._window.draw_line(self._bottom_wall.line, fill_colour=self._window.background_colour)
|
||||
self._window.draw_line(
|
||||
self._bottom_wall.line,
|
||||
fill_colour=self._window.background_colour,
|
||||
)
|
||||
|
||||
if self._left_wall.exists:
|
||||
self._window.draw_line(self._left_wall.line, fill_colour=self._window.cell_grid_colour)
|
||||
self._window.draw_line(
|
||||
self._left_wall.line,
|
||||
fill_colour=self._window.cell_grid_colour,
|
||||
)
|
||||
else:
|
||||
self._window.draw_line(self._left_wall.line, fill_colour=self._window.background_colour)
|
||||
self._window.draw_line(
|
||||
self._left_wall.line,
|
||||
fill_colour=self._window.background_colour,
|
||||
)
|
||||
|
||||
if self._right_wall.exists:
|
||||
self._window.draw_line(self._right_wall.line, fill_colour=self._window.cell_grid_colour)
|
||||
self._window.draw_line(
|
||||
self._right_wall.line,
|
||||
fill_colour=self._window.cell_grid_colour,
|
||||
)
|
||||
else:
|
||||
self._window.draw_line(self._right_wall.line, fill_colour=self._window.background_colour)
|
||||
self._window.draw_line(
|
||||
self._right_wall.line,
|
||||
fill_colour=self._window.background_colour,
|
||||
)
|
||||
|
||||
def draw_move(self, to_cell: 'Cell', undo: bool = False) -> None:
|
||||
"""
|
||||
|
|
9
maze.py
9
maze.py
|
@ -1,5 +1,6 @@
|
|||
from typing import List
|
||||
from time import sleep
|
||||
import random
|
||||
from graphics import Window
|
||||
from cell import Cell
|
||||
|
||||
|
@ -18,6 +19,7 @@ class Maze:
|
|||
cell_size_x: int,
|
||||
cell_size_y: int,
|
||||
window: Window = None,
|
||||
seed=None,
|
||||
) -> None:
|
||||
self._x_position = x_position
|
||||
self._y_position = y_position
|
||||
|
@ -26,6 +28,13 @@ class Maze:
|
|||
self._cell_size_x = cell_size_x
|
||||
self._cell_size_y = cell_size_y
|
||||
self._window = window
|
||||
self._seed = None
|
||||
|
||||
# Generate the seed if it does not exist
|
||||
if seed:
|
||||
self._seed = seed
|
||||
else:
|
||||
random.seed(self._seed)
|
||||
|
||||
# Create the Maze's cells
|
||||
self._cells: List[List[Cell]] = [None for i in range(self._num_cell_rows)]
|
||||
|
|
Loading…
Reference in a new issue