Package it.polimi.ingsw.Model
Class TurnOrder
java.lang.Object
it.polimi.ingsw.Model.TurnOrder
- All Implemented Interfaces:
Serializable
Represents the order in which players will play a round, and organizes the next round based on played
AssistantCard
s- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate List<PlayerBoard>
private int
private GamePhase
private final Map<PlayerBoard,
OptionalValue<AssistantCard>> private static final long
-
Constructor Summary
ConstructorDescriptionTurnOrder
(List<PlayerBoard> playerBoards) Creates the turn order object and assigns a random starting turn formation for players. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check to see if the player can still play a card that is unique this turnprivate void
Removes the selected cards from memoryvoid
Based on thegetSelectedCards()
set the new turn order for the next round.Get the current pecking order for the turnGet the phase of the current roundGet a reference to the current playerGet the card a user played to define the pecking orderGet all of the assistant cards played this roundboolean
Check if a card has already been played this roundboolean
isOwnTurn
(PlayerBoard pb) Finds if it is a player's own turn yetvoid
setSelectedCard
(PlayerBoard pb, AssistantCard ac) Select theAssistantCard
used by the player this roundprivate void
During the round, switches betweenGamePhase
svoid
Proceed to the next player in the turn order
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
selectedCards
-
currentTurnPosition
private int currentTurnPosition -
currentTurnOrder
-
gamePhase
-
-
Constructor Details
-
TurnOrder
Creates the turn order object and assigns a random starting turn formation for players.- Parameters:
playerBoards
- the players in the game
-
-
Method Details
-
getCurrentTurnOrder
Get the current pecking order for the turn- Returns:
- an Unmodifiable
List
ordered from index 0 being the first player, onwards
-
getMutableSelectedCard
Get the card a user played to define the pecking order- Parameters:
pb
- the player to filter the playedAssistantCard
s for- Returns:
- a
OptionalValue
containing the selectedAssistantCard
, if one has been played by the user this round.
-
setSelectedCard
Select theAssistantCard
used by the player this round- Parameters:
pb
- the player to set the card forac
- the card selected by the player- Throws:
ForbiddenOperationException
- if the card was already used, if theGamePhase
is not inGamePhase.SETUP
or if it's not the player's turn yet, if the card or the player were null or if the player could have played a different, not yet played by him or anyone else (during this turn) card.
-
getGamePhase
Get the phase of the current round- Returns:
- the
GamePhase
of the current round
-
isOwnTurn
Finds if it is a player's own turn yet- Parameters:
pb
- the player to filter for- Returns:
- true if it is the player's turn, false otherwise
-
isAlreadyInSelection
Check if a card has already been played this round- Parameters:
ac
- the card to filter for- Returns:
- true if the selected card was already submitted as a selection in
setSelectedCard(PlayerBoard, AssistantCard)
during this round
-
canPlayUniqueCard
Check to see if the player can still play a card that is unique this turn- Parameters:
pb
- the player to filter cards for- Returns:
- true if the player can play at least one not yet selected card this round, false otherwise
-
getMutableCurrentPlayer
Get a reference to the current player- Returns:
- a reference to the
PlayerBoard
of the current player
-
getSelectedCards
Get all of the assistant cards played this round- Returns:
- an Unmodifiable
List
of theAssistantCard
s played this round as of yet
-
stepToNextPlayer
public void stepToNextPlayer()Proceed to the next player in the turn order -
stepNextGamePhase
private void stepNextGamePhase()During the round, switches betweenGamePhase
s -
commitTurnOrder
public void commitTurnOrder()Based on thegetSelectedCards()
set the new turn order for the next round. Players that have not selected a card will be put last in the order. -
cleanSelectedCards
private void cleanSelectedCards()Removes the selected cards from memory
-