Class GameController

java.lang.Object
it.polimi.ingsw.gc14.Controller.GameController

public class GameController extends Object
Controller responsible for managing interactions with the Game model.

It provides methods to update the game state by delegating player-related actions and game actions to the underlying model.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Game
    The game model managed by this controller.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a GameController without an associated game model.
    Creates a GameController associated with the specified game model.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addPlayer(String username)
    Attempts to add a new player with the specified username to the game model.
    boolean
    Marks the player associated with the specified username as disconnected.
    boolean
    drawLowerBuildingCard(String playerUsername, int pos)
    Attempts to draw a lower building card for the specified player from the specified position.
    boolean
    drawLowerTribeCard(String playerUsername, int pos)
    Attempts to draw a lower tribe card for the specified player from the specified position.
    boolean
    drawUpperBuildingCard(String playerUsername, int pos)
    Attempts to draw an upper building card for the specified player from the specified position.
    boolean
    drawUpperTribeCard(String playerUsername, int pos)
    Attempts to draw an upper tribe card for the specified player from the specified position.
    void
    Ends the game due to forfeit: all remaining players are absent, so the game is terminated and final scores are computed.
    Returns the game model managed by this controller.
    boolean
    Marks the player associated with the specified username as reconnected.
    void
    setModel(Game model)
    Updates the game model managed by this controller.
    boolean
    skipTurn(String playerUsername)
    Skips the card drawing action for the specified player.
    boolean
    slotChoice(String playerUsername, int pos)
    Attempts to perform the slot choice action for the specified player at the specified position.
    boolean
    totemChoice(String playerUsername, String totem)
    Applies the totem choice made by the player associated with the specified username.

    Methods inherited from class Object

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

    • model

      private Game model
      The game model managed by this controller.
  • Constructor Details

    • GameController

      public GameController(Game model)
      Creates a GameController associated with the specified game model.
      Parameters:
      model - the game model managed by this controller.
    • GameController

      public GameController()
      Creates a GameController without an associated game model.
  • Method Details

    • disconnectedPlayer

      public boolean disconnectedPlayer(String username)
      Marks the player associated with the specified username as disconnected.
      Parameters:
      username - the username of the player who disconnected.
      Returns:
      true if the disconnection is handled successfully, false if no player with the specified username exists or if the operation fails.
    • reconnectPlayer

      public boolean reconnectPlayer(String username)
      Marks the player associated with the specified username as reconnected.
      Parameters:
      username - the username of the player who reconnected.
      Returns:
      true if the reconnection is handled successfully, false if no player with the specified username exists or if the operation fails.
    • getModel

      public Game getModel()
      Returns the game model managed by this controller.
      Returns:
      the game model managed by this controller.
    • setModel

      public void setModel(Game model)
      Updates the game model managed by this controller.
      Parameters:
      model - the new game model managed by this controller.
    • addPlayer

      public boolean addPlayer(String username)
      Attempts to add a new player with the specified username to the game model.
      Parameters:
      username - the username of the player to add.
      Returns:
      true if the player is successfully added, false otherwise.
    • drawUpperTribeCard

      public boolean drawUpperTribeCard(String playerUsername, int pos)
      Attempts to draw an upper tribe card for the specified player from the specified position.
      Parameters:
      playerUsername - the username of the player performing the action.
      pos - the position of the upper tribe card to draw.
      Returns:
      true if the action succeeds, false if the player does not exist or if the draw operation fails.
    • drawLowerTribeCard

      public boolean drawLowerTribeCard(String playerUsername, int pos)
      Attempts to draw a lower tribe card for the specified player from the specified position.
      Parameters:
      playerUsername - the username of the player performing the action.
      pos - the position of the lower tribe card to draw.
      Returns:
      true if the action succeeds, false if the player does not exist or if the draw operation fails.
    • drawUpperBuildingCard

      public boolean drawUpperBuildingCard(String playerUsername, int pos)
      Attempts to draw an upper building card for the specified player from the specified position.
      Parameters:
      playerUsername - the username of the player performing the action.
      pos - the position of the upper building card to draw.
      Returns:
      true if the action succeeds, false if the player does not exist or if the draw operation fails.
    • drawLowerBuildingCard

      public boolean drawLowerBuildingCard(String playerUsername, int pos)
      Attempts to draw a lower building card for the specified player from the specified position.
      Parameters:
      playerUsername - the username of the player performing the action.
      pos - the position of the lower building card to draw.
      Returns:
      true if the action succeeds, false if the player does not exist or if the draw operation fails.
    • skipTurn

      public boolean skipTurn(String playerUsername)
      Skips the card drawing action for the specified player.
      Parameters:
      playerUsername - the username of the player performing the action.
      Returns:
      true if the skip action is valid and successfully performed, false if the player does not exist or if the action is not valid.
    • slotChoice

      public boolean slotChoice(String playerUsername, int pos)
      Attempts to perform the slot choice action for the specified player at the specified position.
      Parameters:
      playerUsername - the username of the player performing the action.
      pos - the position of the chosen slot.
      Returns:
      true if the action succeeds, false if the player does not exist or if the slot choice operation fails.
    • totemChoice

      public boolean totemChoice(String playerUsername, String totem)
      Applies the totem choice made by the player associated with the specified username.
      Parameters:
      playerUsername - the username of the player making the choice.
      totem - the name of the selected totem.
      Returns:
      true if the choice is handled successfully, false if no player with the specified username exists or if the choice operation fails.
    • endGameForfeit

      public void endGameForfeit()
      Ends the game due to forfeit: all remaining players are absent, so the game is terminated and final scores are computed.