refactor food and rename pause_game function

main
Plaza521 2022-10-27 17:41:10 +03:00 committed by GitHub
parent a96f8fcc71
commit b6a097bbb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 5 deletions

View File

@ -4,9 +4,8 @@ from settings import *
class Food(Point): class Food(Point):
def __init__(self, x, y, pl): def __init__(self, x, y):
Point.__init__(self, x, y) Point.__init__(self, x, y)
self.pl = pl
def generate_new(self) -> None: def generate_new(self) -> None:
self.x = randint(0, WIDTH - 1) self.x = randint(0, WIDTH - 1)

View File

@ -14,13 +14,13 @@ class Game:
self.is_pause = False self.is_pause = False
kb.add_hotkey(QUIT_BUTTON, self.stop_game) kb.add_hotkey(QUIT_BUTTON, self.stop_game)
kb.add_hotkey(PAUSE_BUTTON, self.pause_game) kb.add_hotkey(PAUSE_BUTTON, self.switch_pause)
kb.add_hotkey(LEFT_BUTTON, self.pl.left) kb.add_hotkey(LEFT_BUTTON, self.pl.left)
kb.add_hotkey(RIGHT_BUTTON, self.pl.right) kb.add_hotkey(RIGHT_BUTTON, self.pl.right)
kb.add_hotkey(UP_BUTTON, self.pl.up) kb.add_hotkey(UP_BUTTON, self.pl.up)
kb.add_hotkey(DOWN_BUTTON, self.pl.down) kb.add_hotkey(DOWN_BUTTON, self.pl.down)
def pause_game(self) -> None: def switch_pause(self) -> None:
self.is_pause = not self.is_pause self.is_pause = not self.is_pause
def stop_game(self) -> None: def stop_game(self) -> None:

View File

@ -8,7 +8,7 @@ class Player:
self.direction = MAIN_DIRECTION self.direction = MAIN_DIRECTION
self.body = [Point(MAIN_X, MAIN_Y)] self.body = [Point(MAIN_X, MAIN_Y)]
self.food = Food(0, 0, self) self.food = Food(0, 0)
self.food.generate_new() self.food.generate_new()
self.score = 1 self.score = 1