-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare.py
55 lines (48 loc) · 1.85 KB
/
square.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
"""Class representing the a single square in the crossword grid."""
from dataclasses import dataclass
from typing import Optional
@dataclass
class Square:
is_black: bool = False
letter: Optional[str] = None
index: Optional[int] = None
starts_down_word: bool = False
starts_across_word: bool = False
across_entry_parent: Optional[str] = None
down_entry_parent: Optional[str] = None
# Example of one square rendered:
# +—————+
# |129 |
# | A |
# +—————+
# Example of five squares rendered next to each other,
# with the left-most square being a black square:
# +—————++—————++—————++—————++—————+
# |█████||129 || || || |
# |█████|| A || B || _ || A |
# +—————++—————++—————++—————++—————+
def get_render_str(self):
border_str = "+—————+"
if self.is_black:
# top-border
render_str = f"{border_str}\n"
# first row - fill w/ big black rectangles
render_str += "|\u2588\u2588\u2588\u2588\u2588|\n"
# second row - fill w/ big black rectangles
render_str += "|\u2588\u2588\u2588\u2588\u2588|\n"
# bottom-border
render_str += border_str
return render_str
# top-border
render_str = f"{border_str}\n"
# second row with index
render_str += "|"
render_str += " " if self.index is None else "{:<3d}".format(self.index)
render_str += " |\n"
# third row with letter
render_str += "| "
render_str += "_" if self.letter is None else self.letter
render_str += " |\n"
# bottom-border
render_str += border_str
return render_str