WS send game state
This commit is contained in:
@ -9,10 +9,11 @@ from hopper.models.board import (
|
||||
Layer,
|
||||
LayerObject,
|
||||
ObjectType,
|
||||
create_random_position,
|
||||
create_random_position, BoardLayout,
|
||||
)
|
||||
from hopper.models.player import Player, PlayerList, Position
|
||||
from hopper.watchdog import InactivityWatchdog
|
||||
from hopper.ws_client import ws_send_game_state
|
||||
from settings import settings
|
||||
|
||||
|
||||
@ -46,7 +47,7 @@ class GameEngine:
|
||||
)
|
||||
self._inacivity_watchdog.start()
|
||||
|
||||
def start_game(self, player_name: str) -> Player:
|
||||
async def start_game(self, player_name: str) -> Player:
|
||||
self._start_inactivity_watchdog()
|
||||
player = Player(
|
||||
name=player_name,
|
||||
@ -57,9 +58,11 @@ class GameEngine:
|
||||
logging.info(f"Starting new game for player: {player}")
|
||||
self.__debug_print_board()
|
||||
|
||||
await ws_send_game_state()
|
||||
|
||||
return player
|
||||
|
||||
def move_player(self, player: Player, direction: Direction) -> PlayerMoveResult:
|
||||
async def move_player(self, player: Player, direction: Direction) -> PlayerMoveResult:
|
||||
player.reset_timeout()
|
||||
|
||||
new_position = Position(player.position.x, player.position.y)
|
||||
@ -87,6 +90,8 @@ class GameEngine:
|
||||
player.position = new_position
|
||||
player.move_count += 1
|
||||
|
||||
await ws_send_game_state()
|
||||
|
||||
if self.is_player_on_destination(player):
|
||||
logging.info(f"Player {player} reached destination!")
|
||||
return PlayerMoveResult.DESTINATION_REACHED
|
||||
@ -105,6 +110,8 @@ class GameEngine:
|
||||
def colided_with_obstacle(self, position: Position) -> bool:
|
||||
return self.board.get_object_at_position(position) is not None
|
||||
|
||||
def get_board_layout(self) -> BoardLayout:
|
||||
return BoardLayout(board=self.board, players=self.players)
|
||||
|
||||
class GameEngineFactory:
|
||||
@staticmethod
|
||||
@ -144,6 +151,7 @@ class GameEngineFactory:
|
||||
def __add_test_player(players: PlayerList) -> None:
|
||||
if not (settings.debug and settings.debug.CREATE_TEST_PLAYER):
|
||||
return
|
||||
|
||||
player = Player(
|
||||
name="Pero",
|
||||
uuid="test-player-id",
|
||||
|
||||
Reference in New Issue
Block a user