parent
4840b016db
commit
a77fe7840d
24
frame.py
24
frame.py
|
@ -23,14 +23,20 @@ class Frame:
|
|||
self.matrix = [[SPACE] * width for line in range(height)]
|
||||
|
||||
def __str__(self) -> str:
|
||||
out_string = f"Width:\n {self.width}\n"
|
||||
out_string += f"Height:\n {self.height}\n"
|
||||
return out_string
|
||||
return (
|
||||
f"Width:\n {self.width}\n"
|
||||
f"Height:\n {self.height}"
|
||||
)
|
||||
|
||||
def draw(
|
||||
self, x: int, y: int,
|
||||
self,
|
||||
|
||||
x: int,
|
||||
y: int,
|
||||
|
||||
value: int = WALL,
|
||||
width: int = 1, height: int = 1
|
||||
width: int = 1,
|
||||
height: int = 1
|
||||
) -> None:
|
||||
if not isinstance(value, int):
|
||||
raise TypeError("Value must be int")
|
||||
|
@ -42,12 +48,12 @@ class Frame:
|
|||
def show(self) -> None:
|
||||
set_cursor_position(0, 0)
|
||||
|
||||
out_string = f"┍{'━' * (self.width * 2)}┑\n"
|
||||
out_string = f"{WALL_COLOR}┍{'━' * (self.width * 2)}┑{RESET_COLOR}\n"
|
||||
|
||||
for line in self.matrix:
|
||||
to_str = ''
|
||||
|
||||
to_str += '│'
|
||||
to_str += f'{WALL_COLOR}│{RESET_COLOR}'
|
||||
for elem in line:
|
||||
if elem == SPACE:
|
||||
to_str += TT_SPACE
|
||||
|
@ -59,10 +65,10 @@ class Frame:
|
|||
to_str += TT_WALL_FOOD
|
||||
elif elem == HEAD:
|
||||
to_str += TT_HEAD
|
||||
to_str += '│\n'
|
||||
to_str += f'{WALL_COLOR}│{RESET_COLOR}\n'
|
||||
|
||||
out_string += to_str
|
||||
out_string += f"┕{'━' * (self.width * 2)}┙"
|
||||
out_string += f"{WALL_COLOR}┕{'━' * (self.width * 2)}┙{RESET_COLOR}"
|
||||
|
||||
print(out_string)
|
||||
|
||||
|
|
6
point.py
6
point.py
|
@ -4,13 +4,13 @@ class Point:
|
|||
self.y = y
|
||||
|
||||
def __eq__(self, other) -> bool:
|
||||
if isinstance(other, Point):
|
||||
if not isinstance(other, Point):
|
||||
return False
|
||||
|
||||
if self.x == other.x and self.y == other.y:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
raise TypeError("You can compare only Point with Point")
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return int(f"{abs(self.x)}000{abs(self.y)}")
|
||||
|
|
10
settings.py
10
settings.py
|
@ -2,6 +2,8 @@
|
|||
WIDTH = 20
|
||||
HEIGHT = 20
|
||||
FPS = 5
|
||||
WALL_COLOR = "\u001b[31m"
|
||||
RESET_COLOR = "\u001b[0m"
|
||||
|
||||
# Buttons
|
||||
QUIT_BUTTON = 'q'
|
||||
|
@ -28,7 +30,7 @@ WALL_FOOD = 3
|
|||
HEAD = 4
|
||||
|
||||
TT_SPACE = " "
|
||||
TT_WALL = "██"
|
||||
TT_FOOD = "@@"
|
||||
TT_WALL_FOOD = "@█"
|
||||
TT_HEAD = "██"
|
||||
TT_WALL = "\u001b[34m{}\u001b[0m".format("██")
|
||||
TT_FOOD = "\u001b[33m{}\u001b[0m".format("██")
|
||||
TT_WALL_FOOD = "\u001b[32m{}\u001b[0m".format("██")
|
||||
TT_HEAD = "\u001b[36m{}\u001b[0m".format("██")
|
||||
|
|
Loading…
Reference in New Issue