Player move delay
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from hopper.enums import Direction, PlayerMoveResult
|
from hopper.enums import Direction, PlayerMoveResult
|
||||||
@ -68,8 +69,6 @@ class GameEngine:
|
|||||||
new_position = Position(player.position.x, player.position.y)
|
new_position = Position(player.position.x, player.position.y)
|
||||||
logging.info(f"Player {player} move to {direction}")
|
logging.info(f"Player {player} move to {direction}")
|
||||||
|
|
||||||
player.move_attempt_count += 1
|
|
||||||
|
|
||||||
if direction == Direction.LEFT:
|
if direction == Direction.LEFT:
|
||||||
new_position.x -= 1
|
new_position.x -= 1
|
||||||
elif direction == Direction.RIGHT:
|
elif direction == Direction.RIGHT:
|
||||||
@ -81,6 +80,8 @@ class GameEngine:
|
|||||||
else:
|
else:
|
||||||
raise ValueError(f"Unhandled direction: {direction}")
|
raise ValueError(f"Unhandled direction: {direction}")
|
||||||
|
|
||||||
|
player.move_attempt_count += 1
|
||||||
|
|
||||||
if not self.position_in_board_bounds(new_position):
|
if not self.position_in_board_bounds(new_position):
|
||||||
raise PositionOutOfBounds()
|
raise PositionOutOfBounds()
|
||||||
|
|
||||||
@ -97,6 +98,8 @@ class GameEngine:
|
|||||||
return PlayerMoveResult.DESTINATION_REACHED
|
return PlayerMoveResult.DESTINATION_REACHED
|
||||||
|
|
||||||
self.__debug_print_board()
|
self.__debug_print_board()
|
||||||
|
|
||||||
|
await asyncio.sleep(settings.game.MOVE_DELAY)
|
||||||
return PlayerMoveResult.OK
|
return PlayerMoveResult.OK
|
||||||
|
|
||||||
def is_player_on_destination(self, player: Player) -> bool:
|
def is_player_on_destination(self, player: Player) -> bool:
|
||||||
|
|||||||
@ -2,6 +2,9 @@ import logging
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class GameSettings:
|
||||||
|
MOVE_DELAY: int = 0.5 # seconds
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BoardSettings:
|
class BoardSettings:
|
||||||
@ -31,6 +34,7 @@ class DebugSettings:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Settings:
|
class Settings:
|
||||||
|
game: GameSettings
|
||||||
board: BoardSettings
|
board: BoardSettings
|
||||||
inacivity_watchdog: InactivityWatchdogSettings
|
inacivity_watchdog: InactivityWatchdogSettings
|
||||||
ws_server: WSServerSettings
|
ws_server: WSServerSettings
|
||||||
|
|||||||
@ -2,12 +2,14 @@ import logging
|
|||||||
|
|
||||||
from hopper.models.config import (
|
from hopper.models.config import (
|
||||||
BoardSettings,
|
BoardSettings,
|
||||||
|
GameSettings,
|
||||||
InactivityWatchdogSettings,
|
InactivityWatchdogSettings,
|
||||||
Settings,
|
Settings,
|
||||||
WSServerSettings,
|
WSServerSettings,
|
||||||
)
|
)
|
||||||
|
|
||||||
settings = Settings(
|
settings = Settings(
|
||||||
|
game=GameSettings(),
|
||||||
board=BoardSettings(),
|
board=BoardSettings(),
|
||||||
inacivity_watchdog=InactivityWatchdogSettings(),
|
inacivity_watchdog=InactivityWatchdogSettings(),
|
||||||
log_level=logging.INFO,
|
log_level=logging.INFO,
|
||||||
|
|||||||
Reference in New Issue
Block a user