Class Action

java.lang.Object
it.polimi.ingsw.controller.action.Action
Direct Known Subclasses:
ActivateLeaderAction, BaseProductionAction, BuyDevelopCardAction, ChooseInitialResourcesAction, ChooseLeaderOnWhiteMarbleAction, DiscardInitialLeaderAction, DiscardLeaderAction, EndTurnAction, InsertMarbleAction, LeaderProductionAction, PlayerDisconnectionAction, PlayerReconnectionAction, ProductionAction, ShopMarketAction

public abstract class Action
extends java.lang.Object
A generic action that a player can request to perform on the model
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected Action​(ActionType type)  
    protected Action​(ActionType type, java.lang.String username)  
  • Method Summary

    Modifier and Type Method Description
    java.lang.String getUsername()  
    protected boolean isCurrentPlayer​(IGameState gameState)
    Check if the player for which this action must be performed is the current player.
    abstract PhaseType performAction​(IGameState gameState)
    (See concrete subclasses for more specific documentation) Perform the action.
    java.lang.String setUsername​(java.lang.String username)
    Set the player for which this action must be performed.

    Methods inherited from class java.lang.Object

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

    • Action

      protected Action​(ActionType type)
    • Action

      protected Action​(ActionType type, java.lang.String username)
  • Method Details

    • setUsername

      public final java.lang.String setUsername​(java.lang.String username)
      Set the player for which this action must be performed. The player will be set only once.
      Parameters:
      username - the player to set
      Returns:
      the player that owns this action, can be the player just set or another if it was already set.
    • getUsername

      public final java.lang.String getUsername()
      Returns:
      the player for which this action must be performed
    • isCurrentPlayer

      protected final boolean isCurrentPlayer​(IGameState gameState)
      Check if the player for which this action must be performed is the current player.
      Parameters:
      gameState - the current state of this game
      Returns:
      true if this player is the current player, false if it's not
    • performAction

      public abstract PhaseType performAction​(IGameState gameState) throws ControllerException, ModelException
      (See concrete subclasses for more specific documentation) Perform the action.
      Parameters:
      gameState - the current state of this game
      Returns:
      the next phase of this player's turn
      Throws:
      ControllerException - a controller error
      ModelException - a model error