Game state
This commit is contained in:
@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user