add score

main 2
Plaza521 2022-10-26 23:43:49 +03:00 committed by GitHub
parent 713504a3d5
commit 3982e7ab40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 1 deletions

View File

@ -38,6 +38,8 @@ class Game:
self.running = False
print(e)
input("Press enter to leave from game")
def main() -> None:
Game().play()

1
out.py
View File

@ -36,3 +36,4 @@ class Out:
)
frame.show()
print(F"Score: {pl.score}")

View File

@ -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)

View File

@ -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: