-
Notifications
You must be signed in to change notification settings - Fork 110
/
box.py
76 lines (61 loc) · 2.12 KB
/
box.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from typing import List, Optional, Tuple
class Box:
ALL_BOXES: List["Box"] = []
BOXES_DONE = 0
def __init__(self, y: int, x: int):
self.idx: Tuple[int, int] = (y, x)
self._top: Optional[str] = None
self._bottom: Optional[str] = None
self._left: Optional[str] = None
self._right: Optional[str] = None
self.sides: int = 0
self.color: Optional[str] = None
Box.ALL_BOXES.append(self)
def top_idx(self) -> Tuple[Tuple[int, int], Tuple[int, int]]:
return self.idx, (self.idx[0], self.idx[1] + 1)
def bottom_idx(self) -> Tuple[Tuple[int, int], Tuple[int, int]]:
return (self.idx[0] + 1, self.idx[1]), (self.idx[0] + 1, self.idx[1] + 1)
def left_idx(self) -> Tuple[Tuple[int, int], Tuple[int, int]]:
return self.idx, (self.idx[0] + 1, self.idx[1])
def right_idx(self) -> Tuple[Tuple[int, int], Tuple[int, int]]:
return (self.idx[0], self.idx[1] + 1), (self.idx[0] + 1, self.idx[1] + 1)
@property
def top(self) -> Optional[str]:
return self._top
@top.setter
def top(self, top: str):
self._top = top
self.sides += 1
if self.sides == 4:
self.color = top
Box.BOXES_DONE += 1
@property
def bottom(self) -> Optional[str]:
return self._bottom
@bottom.setter
def bottom(self, bottom: str):
self._bottom = bottom
self.sides += 1
if self.sides == 4:
self.color = bottom
Box.BOXES_DONE += 1
@property
def left(self) -> Optional[str]:
return self._left
@left.setter
def left(self, left: str):
self._left = left
self.sides += 1
if self.sides == 4:
self.color = left
Box.BOXES_DONE += 1
@property
def right(self) -> Optional[str]:
return self._right
@right.setter
def right(self, right: str):
self._right = right
self.sides += 1
if self.sides == 4:
self.color = right
Box.BOXES_DONE += 1