Purchase timeout

This commit is contained in:
Eden Kirin
2023-03-30 13:16:25 +02:00
parent ecffdc5d1e
commit b80130d942

View File

@ -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)