Class OrderLogicCard

java.lang.Object
it.polimi.ingsw.gc14.Model.OrderLogicCard
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Order2, Order3, Order4, Order5

public abstract class OrderLogicCard extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    protected final List<OrderPlayer>
    The list of OrderPlayer entries tracking turn order and played status.
    private final Queue<Player>
    The queue of Players associated with this order logic card.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an order logic card with the specified list of players.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Applies the building-related effect to the specified player.
    boolean
    Returns whether the given player is currently present in the turn queue.
    protected abstract void
    effect(Player player, int index)
    Applies the effect associated with the specified player and queue position.
    Returns the first player in the queue without removing it.
    Returns an unmodifiable view of the player order list.
    int
    getPosition(String username)
    Returns the position of the player associated with the specified username within the current order list.
    Removes and returns the first player in the queue.
    void
    push(Player player)
    Applies the effect associated with the current queue position of the player and then adds the player to the end of the queue.
    void
    Moves the specified player to the end of the queue without applying effects.
    void
    Removes the given player from both the turn queue and the order list.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • players

      private final Queue<Player> players
      The queue of Players associated with this order logic card.
    • playerList

      protected final List<OrderPlayer> playerList
      The list of OrderPlayer entries tracking turn order and played status. Protected so subclasses can read it for display purposes (e.g., Object.toString()).
  • Constructor Details

    • OrderLogicCard

      public OrderLogicCard(ArrayList<Player> players)
      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

      public List<OrderPlayer> getPlayerList()
      Returns an unmodifiable view of the player order list.
      Returns:
      the list of OrderPlayer entries in turn order.
    • push

      public void push(Player player)
      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

      public void pushNoEffect(Player player)
      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

      public Player 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 null if the queue is empty.
    • getFirst

      public Player getFirst()
      Returns the first player in the queue without removing it.
      Returns:
      the first player in the queue, or null if the queue is empty.
    • effect

      protected abstract void effect(Player player, int index) throws IndexOutOfBoundsException
      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

      protected void buildingEffect(Player player)
      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

      public boolean containsInQueue(Player player)
      Returns whether the given player is currently present in the turn queue.
      Parameters:
      player - the player to look up.
      Returns:
      true if the player is in the queue; false otherwise.
    • removeFromQueue

      public void removeFromQueue(Player player)
      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

      public int getPosition(String username)
      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 -1 if no player with the specified username is present in the order list.
      See Also: