41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
from Line import Line
|
|
from Point import Point
|
|
from Window import Window
|
|
from typing import Self
|
|
|
|
|
|
class Cell:
|
|
def __init__(self, win:Window=None):
|
|
self.has_left_wall:bool = True
|
|
self.has_right_wall:bool = True
|
|
self.has_top_wall:bool = True
|
|
self.has_bottom_wall:bool = True
|
|
self.visited:bool = False
|
|
self._x1:int|None = None
|
|
self._x2:int|None = None
|
|
self._y1:int|None = None
|
|
self._y2:int|None = None
|
|
self._win:Window = win
|
|
|
|
def draw(self, x1:int, y1:int, x2:int, y2:int) -> None:
|
|
if self._win is None:
|
|
return
|
|
self._x1 = x1
|
|
self._x2 = x2
|
|
self._y1 = y1
|
|
self._y2 = y2
|
|
self._win.draw_line(Line(Point(x1, y1), Point(x1, y2)), "black" if self.has_left_wall else "white")
|
|
self._win.draw_line(Line(Point(x1, y1), Point(x2, y1)), "black" if self.has_top_wall else "white")
|
|
self._win.draw_line(Line(Point(x2, y1), Point(x2, y2)), "black" if self.has_right_wall else "white")
|
|
self._win.draw_line(Line(Point(x1, y2), Point(x2, y2)), "black" if self.has_bottom_wall else "white")
|
|
|
|
def draw_move(self, to_cell:Self, undo:bool=False) -> None:
|
|
half_length = abs(self._x2 - self._x1) // 2
|
|
p1 = Point(half_length + self._x1, half_length + self._y1)
|
|
|
|
half_length2 = abs(to_cell._x2 - to_cell._x1) // 2
|
|
p2 = Point(half_length2 + to_cell._x1, half_length2 + to_cell._y1)
|
|
|
|
line = Line(p1, p2)
|
|
self._win.draw_line(line, "gray" if undo else "red")
|