summaryrefslogtreecommitdiff
path: root/cell.py
diff options
context:
space:
mode:
Diffstat (limited to 'cell.py')
-rw-r--r--cell.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/cell.py b/cell.py
new file mode 100644
index 0000000..c2f763b
--- /dev/null
+++ b/cell.py
@@ -0,0 +1,34 @@
+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
+
+ 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):
+ center_start = Point((self._x1+self._x2)>>1, (self._y1+self._y2)>>1)
+ center_end = Point((to_cell._x1+to_cell._x2)>>1, (to_cell._y1+to_cell._y2)>>1)
+ fill_color = "red"
+ if undo:
+ fill_color = "gray"
+ self._win.draw_line(Line(center_start, center_end), fill_color)