Send purchase state

This commit is contained in:
Eden Kirin
2023-03-30 21:09:11 +02:00
parent 6111d07f09
commit 059408242c
5 changed files with 107 additions and 20 deletions

View File

@ -144,20 +144,14 @@ 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!")
await self._player_on_destination(player)
return PlayerMoveResult.DESTINATION_REACHED
if self.ws_server:
await self.ws_server.send_game_dump()
self.__debug_print_board()
if player.state == PlayerState.ON_DESTINATION:
self.game_state = GameState.LOCK_FOR_MOVEMENT
return PlayerMoveResult.DESTINATION_REACHED
await asyncio.sleep(settings.game.MOVE_DELAY)
return PlayerMoveResult.OK
def _is_player_on_destination(self, player: Player) -> bool:
@ -171,8 +165,15 @@ class GameEngine:
def _colided_with_obstacle(self, position: Position) -> bool:
return self.board.get_object_at_position(position) is not None
def _player_on_destination(self, player: Player) -> None:
async def _player_on_destination(self, player: Player) -> None:
logging.info(f"Player {player} reached destination!")
self.game_state = GameState.LOCK_FOR_MOVEMENT
await self.ws_server.send_game_dump()
self.__debug_print_board()
await self.ws_server.send_product_purchase_message(products=settings.products)
logging.info(f"Starting purchase countdown timer for {settings.purchase_timeout} seconds")
self._purchase_countdown_timer = CountdownTimer(
seconds=settings.purchase_timeout,
@ -183,6 +184,9 @@ class GameEngine:
def _on_purchase_timeout(self) -> None:
logging.info("Ding ding! Purchase countdown timer timeout")
self._purchase_countdown_timer = None
asyncio.run(self.ws_server.send_product_purchase_done_message(product=None))
self.game_state = GameState.RUNNING
def get_board_layout(self) -> BoardLayout: