Player state
This commit is contained in:
@ -14,7 +14,7 @@ from hopper.api.dto import (
|
||||
)
|
||||
from hopper.engine import GameEngine
|
||||
from hopper.enums import Direction, PlayerMoveResult
|
||||
from hopper.errors import Collision, PositionOutOfBounds
|
||||
from hopper.errors import Collision, GameLockForMovement, PositionOutOfBounds
|
||||
from hopper.models.player import Player
|
||||
|
||||
router = APIRouter()
|
||||
@ -60,7 +60,7 @@ async def start_game(
|
||||
body: StartGameRequestDto,
|
||||
engine: GameEngine = Depends(get_game_engine),
|
||||
) -> StartGameResponseDto:
|
||||
new_player = await engine.start_game(player_name=body.player_name)
|
||||
new_player = await engine.start_game_for_player(player_name=body.player_name)
|
||||
|
||||
return StartGameResponseDto(
|
||||
board=engine.board,
|
||||
@ -112,6 +112,10 @@ async def get_player_info(
|
||||
"model": ErrorResponseDto,
|
||||
"description": " Position out of bounds or collision with an object",
|
||||
},
|
||||
status.HTTP_423_LOCKED: {
|
||||
"model": ErrorResponseDto,
|
||||
"description": " Player reached destination. Can't move anymore.",
|
||||
},
|
||||
},
|
||||
)
|
||||
async def move_player(
|
||||
@ -130,6 +134,11 @@ async def move_player(
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT, detail="Collision with an object"
|
||||
)
|
||||
except GameLockForMovement:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_423_LOCKED,
|
||||
detail="Player reached destination. Can't move anymore.",
|
||||
)
|
||||
|
||||
if move_result == PlayerMoveResult.DESTINATION_REACHED:
|
||||
response.status_code = status.HTTP_200_OK
|
||||
|
||||
Reference in New Issue
Block a user