diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-30 13:58:02 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-30 13:58:02 +0200 |
commit | 5874005e58d0f26b4393845b3b18160658ece160 (patch) | |
tree | 428f315dbd99e3f77677107586cac493d000cac7 /src/sliceitoff/game/game.py | |
parent | acfac65f17a274d6d7f73cb44ed9476032241134 (diff) |
refactor game.level
Diffstat (limited to 'src/sliceitoff/game/game.py')
-rw-r--r-- | src/sliceitoff/game/game.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py index bcb04e7..b7d5212 100644 --- a/src/sliceitoff/game/game.py +++ b/src/sliceitoff/game/game.py @@ -17,6 +17,7 @@ from .show import Show from .initials import Initials class Game: + """ This is the whole game. """ def __init__(self): pygame.init() self.clock = pygame.time.Clock() @@ -26,46 +27,46 @@ class Game: Fonts.load_fonts( Path(__file__).parent.parent.resolve() ) pygame.mouse.set_visible(False) + def __del__(self): + pygame.quit() + def welcome(self): + """ displays instruction and waits a key """ ws = Show(welcome_screen()) - dt = 0 while ws.active: ws.update(dt = self.clock.tick()) self.display.update( [ws] ) def show_highscores(self): + """ displays highscores and waits a key """ his = Show(hiscores_screen(str(self.hiscores))) - dt = 0 while his.active: his.update(dt = self.clock.tick()) self.display.update( [his] ) def newgame(self): + """ new game, new score, runs through levels till game over """ self.stats = Stats() while self.stats.lives: - level = Level(display = self.display, stats = self.stats) - dt = 0 - while level.step(dt): - dt = self.clock.tick() + level = Level(stats = self.stats) + while level.active: + level.update(dt = self.clock.tick()) + self.display.update( [level] ) if self.stats.lives: self.stats.level_up() def initials(self): + """ asks for initials in case of high enough score """ initials = Initials() - dt = 0 while initials.active: initials.update(dt = self.clock.tick()) self.display.update([initials]) return initials.name def run(self): + """ This is the main loop of the game (not loop at the moment) """ self.welcome() self.newgame() if self.hiscores.high_enough(self.stats.score): self.hiscores.add( self.stats.score, self.initials()) self.show_highscores() - - - def __del__(self): - pygame.quit() - |