Game state

This commit is contained in:
Eden Kirin
2023-03-30 11:44:20 +02:00
parent 413e395a75
commit 33f2220356
3 changed files with 18 additions and 3 deletions

View File

@ -3,8 +3,8 @@ import logging
import random
from typing import Optional
from hopper.enums import Direction, PlayerMoveResult
from hopper.errors import Collision, PositionOutOfBounds
from hopper.enums import Direction, PlayerMoveResult, GameState
from hopper.errors import Collision, PositionOutOfBounds, GameLockForMovement
from hopper.interfaces import SendGameDumpInterface
from hopper.models.board import (
BOARD_DUMP_CHARS,
@ -30,6 +30,7 @@ class GameEngine:
self.players = PlayerList()
self._inacivity_watchdog = None
self.__debug_print_board()
self.game_state = GameState.RUNNING
def dump_board(self) -> list[list[str]]:
dump = self.board.dump()
@ -113,8 +114,12 @@ class GameEngine:
) -> PlayerMoveResult:
player.reset_timeout()
if self.game_state == GameState.LOCK_FOR_MOVEMENT:
raise GameLockForMovement("Player reached destination. Can't move now.")
# player will not be able to move once they reach the destination
if player.reached_destination:
self.game_state = GameState.LOCK_FOR_MOVEMENT
return PlayerMoveResult.DESTINATION_REACHED
logging.info(f"Player {player} move to {direction}")