WS send game state

This commit is contained in:
Eden Kirin
2023-03-25 15:54:23 +01:00
parent 0f0fe68890
commit 4b511c0cb8
5 changed files with 41 additions and 18 deletions

View File

@ -18,14 +18,14 @@ from hopper.api.dto import (
from hopper.engine import GameEngine
from hopper.enums import Direction, PlayerMoveResult
from hopper.errors import Collision, PositionOutOfBounds
from hopper.ws_client import send_game_state
from hopper.ws_client import ws_send_game_state
router = APIRouter()
@router.get("/ping", response_model=PingResponse)
async def ping() -> PingResponse:
await send_game_state()
await ws_send_game_state()
return PingResponse(
message="Pong!",
)
@ -48,7 +48,7 @@ async def start_game(
body: StartGameRequestDto,
engine: GameEngine = Depends(get_game_engine),
) -> StartGameResponseDto:
new_player = engine.start_game(player_name=body.player_name)
new_player = await engine.start_game(player_name=body.player_name)
return StartGameResponseDto(
board=engine.board,
@ -118,7 +118,7 @@ async def move_player(
)
try:
move_result = engine.move_player(player, direction)
move_result = await engine.move_player(player, direction)
except PositionOutOfBounds:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT, detail="Position out of bounds"