java.lang.Object
polimi.ingsw.am21.codex.model.Lobby.Lobby
Represents the lobby where players join before starting the game.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPlayer
(UUID connectionID, CardPair<ObjectiveCard> objectiveCards, PlayableCard starterCard) Adds a player to the lobby.boolean
containsConnectionID
(UUID connectionID) Checks if a player with the given socket ID is already in the lobby.finalizePlayer
(UUID connectionID, CardSideType cardSide, List<PlayableCard> hand) Finalizes a player in the lobby, constructing the Player object and removing the PlayerBuilder from the mapGets a list of all the available token colors in the lobbygetPlayerNickname
(UUID connectionID) Gets the nickname of the player in the lobby.getPlayerObjectiveCards
(UUID connectionID) Retrieves the objective cards associated with a player in the lobby.int
Gets the current count of players in the lobby.Map
<UUID, javafx.util.Pair<String, TokenColor>> Gets the information of all the players in the lobby.getPlayerTokenColor
(UUID connectionID) Gets the token color of the player in the lobby.int
Gets the number of remaining player slots in the lobby.getStarterCard
(UUID connectionID) hasSelectedFirstObjectiveCard
(UUID connectionID) Gets the objective card associated with the player in the lobby.javafx.util.Pair
<CardPair<ObjectiveCard>, PlayableCard> removePlayer
(UUID connectionID) Removes a player from the lobby.void
setNickname
(UUID connectionID, String nickname) Sets the nickname for a player in the lobby.void
setObjectiveCard
(UUID connectionID, Boolean firstObjectiveCard) Updates the PlayerBuilder with connectionID with the selectedObjectiveCardvoid
setToken
(UUID connectionID, TokenColor tokenColor) Sets the token color for a player in the lobby.
-
Constructor Details
-
Lobby
public Lobby(int maxPlayers) Constructs a lobby with the specified maximum number of players.- Parameters:
maxPlayers
- the maximum number of players allowed in the lobby
-
Lobby
public Lobby()Constructs a lobby with a default maximum number of players (4).
-
-
Method Details
-
getRemainingPlayerSlots
public int getRemainingPlayerSlots()Gets the number of remaining player slots in the lobby.- Returns:
- the number of remaining player slots
-
getPlayersCount
public int getPlayersCount()Gets the current count of players in the lobby.- Returns:
- the count of players in the lobby
-
addPlayer
public void addPlayer(UUID connectionID, CardPair<ObjectiveCard> objectiveCards, PlayableCard starterCard) throws LobbyFullException.LobbyFullInternalException Adds a player to the lobby.- Parameters:
connectionID
- the socket ID of the player to add- Throws:
LobbyFullException.LobbyFullInternalException
- if the lobby is full and cannot accept more players
-
removePlayer
public javafx.util.Pair<CardPair<ObjectiveCard>,PlayableCard> removePlayer(UUID connectionID) throws PlayerNotFoundGameException Removes a player from the lobby.- Parameters:
connectionID
- the socket ID of the player to remove- Returns:
- the extracted objective card associated and the starter card of the player
- Throws:
PlayerNotFoundGameException
- if the player is not found in the lobby
-
setNickname
public void setNickname(UUID connectionID, String nickname) throws PlayerNotFoundGameException, NicknameAlreadyTakenException Sets the nickname for a player in the lobby.- Parameters:
connectionID
- the socket ID of the playernickname
- the nickname to set- Throws:
PlayerNotFoundGameException
- if the socket ID is not found in the lobbyNicknameAlreadyTakenException
- if the nickname is already taken by another player
-
setToken
public void setToken(UUID connectionID, TokenColor tokenColor) throws PlayerNotFoundGameException, TokenAlreadyTakenException Sets the token color for a player in the lobby.- Parameters:
connectionID
- the socket ID of the playertokenColor
- the token color to set- Throws:
PlayerNotFoundGameException
- if the socket ID is not found in the lobbyTokenAlreadyTakenException
- if the token color is already taken by another player
-
setObjectiveCard
public void setObjectiveCard(UUID connectionID, Boolean firstObjectiveCard) throws PlayerNotFoundGameException Updates the PlayerBuilder with connectionID with the selectedObjectiveCard- Parameters:
connectionID
- the socket ID of the playerfirstObjectiveCard
- sets the selectedObjectiveCard card to the first or second from the CardPair- Throws:
PlayerNotFoundGameException
- if the socket ID is not found in the lobby
-
hasSelectedFirstObjectiveCard
Gets the objective card associated with the player in the lobby.- Parameters:
connectionID
- the socket ID of the player- Returns:
- the objective card associated with the player
- Throws:
PlayerNotFoundGameException
- if the player is not found in the lobby
-
finalizePlayer
public Player finalizePlayer(UUID connectionID, CardSideType cardSide, List<PlayableCard> hand) throws PlayerNotFoundGameException, IncompletePlayerBuilderException, IllegalCardSideChoiceException, IllegalPlacingPositionException Finalizes a player in the lobby, constructing the Player object and removing the PlayerBuilder from the map- Parameters:
connectionID
- the socket ID of the player to finalizecardSide
- the objective card associated with the player- Returns:
- the finalized Player object
- Throws:
PlayerNotFoundGameException
- if the socked ID is not found in the lobbyIncompletePlayerBuilderException
IllegalCardSideChoiceException
IllegalPlacingPositionException
-
getPlayerObjectiveCards
Retrieves the objective cards associated with a player in the lobby.- Parameters:
connectionID
- the socket ID of the player- Returns:
- the CardPair containing the objective cards of the player
-
containsConnectionID
Checks if a player with the given socket ID is already in the lobby.- Parameters:
connectionID
- the socket ID of the player to check- Returns:
- true if the player is already in the lobby, otherwise false
-
getPlayerNickname
Gets the nickname of the player in the lobby.- Parameters:
connectionID
- the socket ID of the player- Returns:
- the nickname of the player
- Throws:
PlayerNotFoundGameException
- if the player is not found in the lobby
-
getPlayerTokenColor
public Optional<TokenColor> getPlayerTokenColor(UUID connectionID) throws PlayerNotFoundGameException Gets the token color of the player in the lobby.- Parameters:
connectionID
- the socket ID of the player- Returns:
- the token color of the player
- Throws:
PlayerNotFoundGameException
- if the player is not found in the lobby
-
getAvailableColors
Gets a list of all the available token colors in the lobby -
getPlayersInfo
Gets the information of all the players in the lobby.- Returns:
- a map of the players' socket ID to their nickname and token color
-
getStarterCard
- Parameters:
connectionID
- the socked ID of the player- Returns:
- the starter card of the player
- Throws:
PlayerNotFoundGameException
- if the player is not found in the lobby
-