refactor(game)

This commit is contained in:
Kristofers Solo 2024-01-06 23:18:10 +02:00
parent 080ba1b9cb
commit c8859bc571
4 changed files with 13 additions and 8 deletions

View File

@ -46,15 +46,18 @@ class Main(BaseScreen, SceenElement, TextScreen):
def run(self) -> None: def run(self) -> None:
while True: while True:
if not self.game: self.run_game_loop()
self.draw()
self.handle_events() def run_game_loop(self) -> None:
if not self.game:
self.draw()
if self.game: self.handle_events()
self.game.run()
self.update() if self.game:
self.game.run()
self.update()
def exit(self) -> None: def exit(self) -> None:
"""Exit the game.""" """Exit the game."""

View File

@ -341,7 +341,8 @@ class Tetris(BaseScreen):
def _play_landing_sound(self) -> None: def _play_landing_sound(self) -> None:
"""Play the landing sound effect.""" """Play the landing sound effect."""
self.landing_sound.play() if self.game_mode is GameMode.PLAYER:
self.landing_sound.play()
def _update_display_surface(self) -> None: def _update_display_surface(self) -> None:
"""Update the display surface.""" """Update the display surface."""

View File

@ -17,4 +17,5 @@ __all__ = [
"Rotation", "Rotation",
"GameMode", "GameMode",
"Weights", "Weights",
"BestMove",
] ]

View File

@ -15,4 +15,4 @@ class Size(NamedTuple):
class BestMove(NamedTuple): class BestMove(NamedTuple):
rotation: int rotation: int
direction: Direction x: int