Class TurnOrder

java.lang.Object
it.polimi.ingsw.Model.TurnOrder
All Implemented Interfaces:
Serializable

public class TurnOrder extends Object implements Serializable
Represents the order in which players will play a round, and organizes the next round based on played AssistantCards
See Also:
  • Field Details

  • Constructor Details

    • TurnOrder

      public TurnOrder(List<PlayerBoard> playerBoards)
      Creates the turn order object and assigns a random starting turn formation for players.
      Parameters:
      playerBoards - the players in the game
  • Method Details

    • getCurrentTurnOrder

      public List<PlayerBoard> getCurrentTurnOrder()
      Get the current pecking order for the turn
      Returns:
      an Unmodifiable List ordered from index 0 being the first player, onwards
    • getMutableSelectedCard

      public OptionalValue<AssistantCard> getMutableSelectedCard(PlayerBoard pb)
      Get the card a user played to define the pecking order
      Parameters:
      pb - the player to filter the played AssistantCards for
      Returns:
      a OptionalValue containing the selected AssistantCard, if one has been played by the user this round.
    • setSelectedCard

      public void setSelectedCard(PlayerBoard pb, AssistantCard ac) throws ForbiddenOperationException
      Select the AssistantCard used by the player this round
      Parameters:
      pb - the player to set the card for
      ac - the card selected by the player
      Throws:
      ForbiddenOperationException - if the card was already used, if the GamePhase is not in GamePhase.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

      public GamePhase getGamePhase()
      Get the phase of the current round
      Returns:
      the GamePhase of the current round
    • isOwnTurn

      public boolean isOwnTurn(PlayerBoard pb)
      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

      public boolean isAlreadyInSelection(AssistantCard ac)
      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

      public boolean canPlayUniqueCard(PlayerBoard pb)
      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

      public PlayerBoard getMutableCurrentPlayer()
      Get a reference to the current player
      Returns:
      a reference to the PlayerBoard of the current player
    • getSelectedCards

      public List<AssistantCard> getSelectedCards()
      Get all of the assistant cards played this round
      Returns:
      an Unmodifiable List of the AssistantCards 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 between GamePhases
    • commitTurnOrder

      public void commitTurnOrder()
      Based on the getSelectedCards() 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