From a77fe7840de12242bcd3e475b53d6a45e1018a22 Mon Sep 17 00:00:00 2001 From: Plaza521 <89989298+Plaza521@users.noreply.github.com> Date: Sat, 29 Oct 2022 04:25:09 +0300 Subject: [PATCH] add color --- frame.py | 24 +++++++++++++++--------- point.py | 12 ++++++------ settings.py | 10 ++++++---- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/frame.py b/frame.py index a53b321..60cf12f 100644 --- a/frame.py +++ b/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) diff --git a/point.py b/point.py index d6d41e9..9a82575 100644 --- a/point.py +++ b/point.py @@ -4,13 +4,13 @@ class Point: self.y = y def __eq__(self, other) -> bool: - if isinstance(other, Point): - if self.x == other.x and self.y == other.y: - return True - else: - return False + if not isinstance(other, Point): + return False + + if self.x == other.x and self.y == other.y: + return True else: - raise TypeError("You can compare only Point with Point") + return False def __hash__(self) -> int: return int(f"{abs(self.x)}000{abs(self.y)}") diff --git a/settings.py b/settings.py index 5e8dd4e..16a1976 100644 --- a/settings.py +++ b/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("██")