Class Client

java.lang.Object
it.polimi.ingsw.network.client.Client
All Implemented Interfaces:
PhaseChangedObserver

public class Client
extends java.lang.Object
implements PhaseChangedObserver
Main class to manage the client side of the application. Performs the message handling of messages coming from server.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int MAX_PORT  
    static int MIN_PORT  
  • Constructor Summary

    Constructors
    Constructor Description
    Client()  
  • Method Summary

    Modifier and Type Method Description
    void close()
    print disconnection message in console, disconnects client socket and terminate client execution
    boolean connectToServer​(java.lang.String serverIP, int serverPort)
    Establishes a connection with the server given IP and port to connect to
    void forwardAction​(Action actionToForward)
    forward action to the next layer where it will be handled by the virtualModel
    void forwardMessage​(Message message)
    forward action to the next layer where it will be handled by the virtualModel
    java.lang.String getCurrentPlayer()  
    java.lang.String getUsername()  
    ViewInterface getView()  
    void handleError​(ErrorType errorType)
    handles error received from the server
    void handleMessage​(Message msg)
    Takes the message and handles it performing the expected action based on the message type and the payload content NOTE: msg cannot be null
    boolean isLocal()  
    void localGameSetup()
    Setup the client to be able to play in local mode (without needing the server)
    static void main​(java.lang.String[] args)  
    void phaseUpdate​(TurnState nextPhase)
    Updates the turnState with the new state received by the server
    void sendLogin​(boolean create, java.lang.String roomName)
    Sends a login message to server
    void setClientTurnManager​(ClientTurnManagerInterface clientTurnManager)  
    void setLocal()  
    void setState​(ClientModelUpdaterInterface state)  
    void setUsername​(java.lang.String username)  
    void setView​(ViewInterface view)  

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • Client

      public Client()
  • Method Details

    • main

      public static void main​(java.lang.String[] args)
    • setLocal

      public void setLocal()
    • isLocal

      public boolean isLocal()
    • setView

      public void setView​(ViewInterface view)
    • setState

      public void setState​(ClientModelUpdaterInterface state)
    • setClientTurnManager

      public void setClientTurnManager​(ClientTurnManagerInterface clientTurnManager)
    • connectToServer

      public boolean connectToServer​(java.lang.String serverIP, int serverPort)
      Establishes a connection with the server given IP and port to connect to
      Parameters:
      serverIP - the server IP to connect to
      serverPort - the server port to connect to
      Returns:
      true if connection is successful, false otherwise
    • sendLogin

      public void sendLogin​(boolean create, java.lang.String roomName)
      Sends a login message to server
      Parameters:
      create - this parameter should be true if you want to create a game, false if you want to join
      roomName - name of the room to create or join
    • forwardAction

      public void forwardAction​(Action actionToForward)
      forward action to the next layer where it will be handled by the virtualModel
      Parameters:
      actionToForward - the action to forward
    • forwardMessage

      public void forwardMessage​(Message message)
      forward action to the next layer where it will be handled by the virtualModel
      Parameters:
      message - the message to forward
    • close

      public void close()
      print disconnection message in console, disconnects client socket and terminate client execution
    • getUsername

      public java.lang.String getUsername()
    • setUsername

      public void setUsername​(java.lang.String username)
    • getCurrentPlayer

      public java.lang.String getCurrentPlayer()
    • handleMessage

      public void handleMessage​(Message msg)
      Takes the message and handles it performing the expected action based on the message type and the payload content NOTE: msg cannot be null
      Parameters:
      msg - the message to be handled, received from the server
    • handleError

      public void handleError​(ErrorType errorType)
      handles error received from the server
      Parameters:
      errorType - the error type
    • localGameSetup

      public void localGameSetup()
      Setup the client to be able to play in local mode (without needing the server)
    • phaseUpdate

      public void phaseUpdate​(TurnState nextPhase)
      Updates the turnState with the new state received by the server
      Specified by:
      phaseUpdate in interface PhaseChangedObserver
      Parameters:
      nextPhase - the next state received by the server
    • getView

      public ViewInterface getView()