refactor food and rename pause_game function
parent
a96f8fcc71
commit
b6a097bbb3
3
food.py
3
food.py
|
@ -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)
|
||||||
|
|
4
main.py
4
main.py
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue