-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui.py
44 lines (34 loc) · 1.37 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pyxel
from gui_utils import draw_scene
from game import Game
class Gui:
def __init__(self, game: Game, title="Game of the Goose") -> None:
self.game = game
self.title = title
self.message = "Press Space to Roll Dice"
self._start_gui()
def _start_gui(self):
"""Creates a graphics window."""
pyxel.init(120, 80, caption=self.title)
def update(self):
"""Runs every frame. It's meant to take and direct user input."""
if pyxel.btnp(pyxel.KEY_SPACE):
if not self.game.is_over():
print(f'Rolling Dice for player: {self.game.get_current_player()}')
self.game.roll_dice()
else:
print('Game is over. Exit game to Restart.')
elif pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
def draw(self):
"""Draws the graphics."""
draw_scene(
player1=self.game.get_player1_name(),
player2=self.game.get_player2_name(),
player1_space=self.game.get_player1_space(),
player2_space=self.game.get_player2_space(),
last_dice_roll=self.game.get_last_dice_roll(),
message=self.message if not self.game.is_over() else f"{self.game.get_winner()} won!",
)
def run(self):
pyxel.run(self.update, self.draw)