add color

main 4
Plaza521 2022-10-29 04:25:09 +03:00 committed by GitHub
parent 4840b016db
commit a77fe7840d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 19 deletions

View File

@ -23,14 +23,20 @@ class Frame:
self.matrix = [[SPACE] * width for line in range(height)] self.matrix = [[SPACE] * width for line in range(height)]
def __str__(self) -> str: def __str__(self) -> str:
out_string = f"Width:\n {self.width}\n" return (
out_string += f"Height:\n {self.height}\n" f"Width:\n {self.width}\n"
return out_string f"Height:\n {self.height}"
)
def draw( def draw(
self, x: int, y: int, self,
x: int,
y: int,
value: int = WALL, value: int = WALL,
width: int = 1, height: int = 1 width: int = 1,
height: int = 1
) -> None: ) -> None:
if not isinstance(value, int): if not isinstance(value, int):
raise TypeError("Value must be int") raise TypeError("Value must be int")
@ -42,12 +48,12 @@ class Frame:
def show(self) -> None: def show(self) -> None:
set_cursor_position(0, 0) 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: for line in self.matrix:
to_str = '' to_str = ''
to_str += '' to_str += f'{WALL_COLOR}{RESET_COLOR}'
for elem in line: for elem in line:
if elem == SPACE: if elem == SPACE:
to_str += TT_SPACE to_str += TT_SPACE
@ -59,10 +65,10 @@ class Frame:
to_str += TT_WALL_FOOD to_str += TT_WALL_FOOD
elif elem == HEAD: elif elem == HEAD:
to_str += TT_HEAD to_str += TT_HEAD
to_str += '\n' to_str += f'{WALL_COLOR}{RESET_COLOR}\n'
out_string += to_str out_string += to_str
out_string += f"{'' * (self.width * 2)}" out_string += f"{WALL_COLOR}{'' * (self.width * 2)}{RESET_COLOR}"
print(out_string) print(out_string)

View File

@ -4,13 +4,13 @@ class Point:
self.y = y self.y = y
def __eq__(self, other) -> bool: 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: if self.x == other.x and self.y == other.y:
return True return True
else: else:
return False return False
else:
raise TypeError("You can compare only Point with Point")
def __hash__(self) -> int: def __hash__(self) -> int:
return int(f"{abs(self.x)}000{abs(self.y)}") return int(f"{abs(self.x)}000{abs(self.y)}")

View File

@ -2,6 +2,8 @@
WIDTH = 20 WIDTH = 20
HEIGHT = 20 HEIGHT = 20
FPS = 5 FPS = 5
WALL_COLOR = "\u001b[31m"
RESET_COLOR = "\u001b[0m"
# Buttons # Buttons
QUIT_BUTTON = 'q' QUIT_BUTTON = 'q'
@ -28,7 +30,7 @@ WALL_FOOD = 3
HEAD = 4 HEAD = 4
TT_SPACE = " " TT_SPACE = " "
TT_WALL = "██" TT_WALL = "\u001b[34m{}\u001b[0m".format("██")
TT_FOOD = "@@" TT_FOOD = "\u001b[33m{}\u001b[0m".format("██")
TT_WALL_FOOD = "@█" TT_WALL_FOOD = "\u001b[32m{}\u001b[0m".format("██")
TT_HEAD = "██" TT_HEAD = "\u001b[36m{}\u001b[0m".format("██")