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