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

View File

@ -22,5 +22,11 @@ class PlayerMoveResult(Enum):
class GameState(Enum): class GameState(Enum):
RUNNING = auto() RUNNING = auto()
LOCKED_FOR_PRODUCT_SELECTION = auto() LOCK_FOR_MOVEMENT = auto()
ENDGAME = auto() ENDGAME = auto()
class PlayerState(Enum):
PLAYING = auto()
ON_DESTINATION = auto()
INACTIVE = auto()

View File

@ -8,3 +8,7 @@ class PositionOutOfBounds(BaseError):
class Collision(BaseError): class Collision(BaseError):
... ...
class GameLockForMovement(BaseError):
...