From 3982e7ab404e55d75e12f8c81ee8247c17a003e1 Mon Sep 17 00:00:00 2001 From: Plaza521 <89989298+Plaza521@users.noreply.github.com> Date: Wed, 26 Oct 2022 23:43:49 +0300 Subject: [PATCH] add score --- main.py | 2 ++ out.py | 1 + player.py | 3 +++ point.py | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 7c7fbff..8fd694f 100644 --- a/main.py +++ b/main.py @@ -38,6 +38,8 @@ class Game: self.running = False print(e) + input("Press enter to leave from game") + def main() -> None: Game().play() diff --git a/out.py b/out.py index 526dc3b..c7736ef 100644 --- a/out.py +++ b/out.py @@ -36,3 +36,4 @@ class Out: ) frame.show() + print(F"Score: {pl.score}") diff --git a/player.py b/player.py index f609a57..66b4963 100644 --- a/player.py +++ b/player.py @@ -13,6 +13,8 @@ class Player: self.food = Food(0, 0, self) self.food.generate_new() + self.score = 0 + def update(self) -> None: sleep(1 / FPS) @@ -31,6 +33,7 @@ class Player: if self.body[-1] == self.food: self.food.generate_new() + self.score += 1 else: self.body.pop(0) diff --git a/point.py b/point.py index 8760254..d6d41e9 100644 --- a/point.py +++ b/point.py @@ -12,7 +12,7 @@ class Point: else: raise TypeError("You can compare only Point with Point") - def __hash__(self) -> None: + def __hash__(self) -> int: return int(f"{abs(self.x)}000{abs(self.y)}") def __str__(self) -> str: