From b80130d9424db44b2a9bc484836552d100463404 Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Thu, 30 Mar 2023 13:16:25 +0200 Subject: [PATCH] Purchase timeout --- hopper/engine.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hopper/engine.py b/hopper/engine.py index 4f9e51e..98888e6 100644 --- a/hopper/engine.py +++ b/hopper/engine.py @@ -4,8 +4,8 @@ import random from typing import Optional from hopper.countdown_timer import CountdownTimer -from hopper.enums import Direction, PlayerMoveResult, GameState, PlayerState -from hopper.errors import Collision, PositionOutOfBounds, GameLockForMovement +from hopper.enums import Direction, GameState, PlayerMoveResult, PlayerState +from hopper.errors import Collision, GameLockForMovement, PositionOutOfBounds from hopper.interfaces import SendGameDumpInterface from hopper.models.board import ( BOARD_DUMP_CHARS, @@ -64,7 +64,7 @@ class GameEngine: ) self._inacivity_watchdog.start() - async def reset_game(self) -> None: + def reset_game(self) -> None: self.__debug_print_board() self.game_state = GameState.RUNNING @@ -144,6 +144,7 @@ class GameEngine: if self._is_player_on_destination(player): player.state = PlayerState.ON_DESTINATION + self._player_on_destination(player) logging.info(f"Player {player} reached destination!") if self.ws_server: @@ -172,7 +173,17 @@ class GameEngine: def _player_on_destination(self, player: Player) -> None: self.game_state = GameState.LOCK_FOR_MOVEMENT - self._purchase_countdown_timer = CountdownTimer() + logging.info(f"Starting purchase countdown timer for {settings.purchase_timeout} seconds") + self._purchase_countdown_timer = CountdownTimer( + seconds=settings.purchase_timeout, + callback=self._on_purchase_timeout, + ) + self._purchase_countdown_timer.start() + + def _on_purchase_timeout(self) -> None: + logging.info("Ding ding! Purchase countdown timer timeout") + self._purchase_countdown_timer = None + self.game_state = GameState.RUNNING def get_board_layout(self) -> BoardLayout: return BoardLayout(board=self.board, players=self.players)