from graphics import Point, Line class Cell: def __init__(self, window=None, lwall=True, twall=True, rwall=True, bwall=True): self._x1 = None self._y1 = None self._x2 = None self._y2 = None self._win = window self.lwall = lwall self.twall = twall self.rwall = rwall self.bwall = bwall self.visited = False def draw(self, x1, y1, x2, y2): if self._win is None: return self._x1 = x1 self._y1 = y1 self._x2 = x2 self._y2 = y2 self._win.draw_line(Line(Point(x1, y1), Point(x1, y2))) if self.lwall else self._win.draw_line(Line(Point(x1, y1), Point(x1, y2)), "white") self._win.draw_line(Line(Point(x1, y1), Point(x2, y1))) if self.twall else self._win.draw_line(Line(Point(x1, y1), Point(x2, y1)), "white") self._win.draw_line(Line(Point(x2, y1), Point(x2, y2))) if self.rwall else self._win.draw_line(Line(Point(x2, y1), Point(x2, y2)), "white") self._win.draw_line(Line(Point(x1, y2), Point(x2, y2))) if self.bwall else self._win.draw_line(Line(Point(x1, y2), Point(x2, y2)), "white") def draw_move(self, to_cell, undo=False): half_length_start = abs(self._x2 - self._x1) // 2 center_start = Point(self._x1 + half_length_start, self._y1 + half_length_start) half_length_end = abs(to_cell._x2 - to_cell._x1) // 2 center_end = Point(to_cell._x1 + half_length_end, to_cell._y1 + half_length_end) fill_color = "red" if undo: fill_color = "gray" self._win.draw_line(Line(center_start, center_end), fill_color)