Class ClientController

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

public class ClientController extends Object
Controller responsible for coordinating the client-side components, including the view, the network client and the local mini model.

It receives user actions from the view, performs basic client-side checks and forwards valid requests to the network client.

  • Field Details

    • miniModel

      private MiniModel miniModel
      Local mini model representing the client-side game state.
    • view

      private final IView view
      View of the client.
    • client

      private IClient client
      Network client, either TCP or RMI.
    • myUsername

      private String myUsername
      Username associated with this client.
  • Constructor Details

    • ClientController

      public ClientController(IView view)
      Constructs a client controller with the specified view.

      The network client is initially unset and an empty local mini model is created.

      Parameters:
      view - the client view, either TUI or GUI.
  • Method Details

    • getMiniModel

      public MiniModel getMiniModel()
      Returns the local mini model.
      Returns:
      the local mini model.
    • getView

      public IView getView()
      Returns the client view.
      Returns:
      the client view.
    • getMyUsername

      public String getMyUsername()
      Returns the username associated with this client.
      Returns:
      the username.
    • setClient

      public void setClient(IClient client)
      Sets the network client.
      Parameters:
      client - the client to set, either TCP or RMI.
    • getClient

      public IClient getClient()
      Gets the network client.
      Returns:
      client return the client, either TCP or RMI.
    • setModel

      public void setModel(MiniModel model)
      Sets the local mini model and updates the view accordingly.
      Parameters:
      model - the mini model to set.
    • setMyUsername

      public void setMyUsername(String username)
      Sets the username associated with this client.
      Parameters:
      username - the username to set.
    • drawUpperTribeCard

      public void drawUpperTribeCard(int pos)
      Requests to draw a tribe card from the upper list.

      The request is forwarded to the network client; the server validates it.

      Parameters:
      pos - the index of the card to draw.
    • drawLowerTribeCard

      public void drawLowerTribeCard(int pos)
      Requests to draw a tribe card from the lower list.

      The request is forwarded to the network client; the server validates it.

      Parameters:
      pos - the index of the card to draw.
    • drawUpperBuildingCard

      public void drawUpperBuildingCard(int pos)
      Requests to draw a building card from the upper list.

      The request is forwarded to the network client; the server validates it.

      Parameters:
      pos - the index of the card to draw.
    • drawLowerBuildingCard

      public void drawLowerBuildingCard(int pos)
      Requests to draw a building card from the lower list.

      The request is forwarded to the network client; the server validates it.

      Parameters:
      pos - the index of the card to draw.
    • skipTurn

      public void skipTurn()
      Requests to skip the current turn.

      The request is forwarded to the network client; the server validates it.

    • slotChoice

      public void slotChoice(int pos)
      Requests the selection of a slot by the specified player.

      The request is forwarded to the network client; the server validates it.

      Parameters:
      pos - the index of the selected slot.
    • totemChoice

      public void totemChoice(int pos)
      Handles the selection of a totem by the specified player.

      If the specified player is not the current player, an error message is shown. Otherwise, the selected totem is retrieved from the available totems list and the choice is forwarded to the network client.

      Parameters:
      pos - the index of the selected totem in the available totems list.
    • disconnect

      public void disconnect()
      Notifies the server of a voluntary disconnection and closes the network client connection.