Class OrderLogicCard
java.lang.Object
it.polimi.ingsw.gc14.Model.OrderLogicCard
- All Implemented Interfaces:
Serializable
Abstract base class for all order logic cards.
An order logic card manages the turn order of the players and defines the behavior used to update the order during the game.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<OrderPlayer> The list ofOrderPlayerentries tracking turn order and played status.The queue ofPlayersassociated with this order logic card. -
Constructor Summary
ConstructorsConstructorDescriptionOrderLogicCard(ArrayList<Player> players) Creates an order logic card with the specified list of players. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildingEffect(Player player) Applies the building-related effect to the specified player.booleancontainsInQueue(Player player) Returns whether the given player is currently present in the turn queue.protected abstract voidApplies the effect associated with the specified player and queue position.getFirst()Returns the first player in the queue without removing it.Returns an unmodifiable view of the player order list.intgetPosition(String username) Returns the position of the player associated with the specified username within the current order list.pull()Removes and returns the first player in the queue.voidApplies the effect associated with the current queue position of the player and then adds the player to the end of the queue.voidpushNoEffect(Player player) Moves the specified player to the end of the queue without applying effects.voidremoveFromQueue(Player player) Removes the given player from both the turn queue and the order list.
-
Field Details
-
players
-
playerList
The list ofOrderPlayerentries tracking turn order and played status. Protected so subclasses can read it for display purposes (e.g.,Object.toString()).
-
-
Constructor Details
-
OrderLogicCard
Creates an order logic card with the specified list of players.The input list is shuffled in place to establish a random initial turn order. This is intentional: the caller's list (typically
Game.playersList) is reordered so that the game's canonical player sequence reflects the randomized order.- Parameters:
players- the list of players associated with this order logic card. The list is mutated (shuffled) by this constructor.
-
-
Method Details
-
getPlayerList
Returns an unmodifiable view of the player order list.- Returns:
- the list of
OrderPlayerentries in turn order.
-
push
Applies the effect associated with the current queue position of the player and then adds the player to the end of the queue.- Parameters:
player- the player to be pushed into the queue.
-
pushNoEffect
Moves the specified player to the end of the queue without applying effects.Any previous occurrence of the player is removed from both the queue and the order list before the player is added again.
- Parameters:
player- the player to be pushed into the queue.
-
pull
Removes and returns the first player in the queue.The first order entry that has not yet been marked as played is marked as played before removing the player from the queue.
- Returns:
- the first player in the queue, or
nullif the queue is empty.
-
getFirst
Returns the first player in the queue without removing it.- Returns:
- the first player in the queue, or
nullif the queue is empty.
-
effect
Applies the effect associated with the specified player and queue position.- Parameters:
player- the player to whom the effect is applied.index- the queue position index associated with the effect.- Throws:
IndexOutOfBoundsException- if the specified index is not valid.
-
buildingEffect
Applies the building-related effect to the specified player. For each building card owned by the player with effect id equal to 3, the player gains 1 Food.- Parameters:
player- the player to whom the building effect is applied.
-
containsInQueue
Returns whether the given player is currently present in the turn queue.- Parameters:
player- the player to look up.- Returns:
trueif the player is in the queue;falseotherwise.
-
removeFromQueue
Removes the given player from both the turn queue and the order list. No-op if the player is not present.- Parameters:
player- the player to remove.
-
getPosition
Returns the position of the player associated with the specified username within the current order list.- Parameters:
username- the username of the player whose position is requested.- Returns:
- the player's position, or
-1if no player with the specified username is present in the order list. - See Also:
-