Package it.polimi.ingsw.network.client
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
-
Constructor Summary
Constructors Constructor Description Client() -
Method Summary
Modifier and Type Method Description voidclose()print disconnection message in console, disconnects client socket and terminate client executionbooleanconnectToServer(java.lang.String serverIP, int serverPort)Establishes a connection with the server given IP and port to connect tovoidforwardAction(Action actionToForward)forward action to the next layer where it will be handled by the virtualModelvoidforwardMessage(Message message)forward action to the next layer where it will be handled by the virtualModeljava.lang.StringgetCurrentPlayer()java.lang.StringgetUsername()ViewInterfacegetView()voidhandleError(ErrorType errorType)handles error received from the servervoidhandleMessage(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 nullbooleanisLocal()voidlocalGameSetup()Setup the client to be able to play in local mode (without needing the server)static voidmain(java.lang.String[] args)voidphaseUpdate(TurnState nextPhase)Updates the turnState with the new state received by the servervoidsendLogin(boolean create, java.lang.String roomName)Sends a login message to servervoidsetClientTurnManager(ClientTurnManagerInterface clientTurnManager)voidsetLocal()voidsetState(ClientModelUpdaterInterface state)voidsetUsername(java.lang.String username)voidsetView(ViewInterface view)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
MIN_PORT
public static final int MIN_PORT- See Also:
- Constant Field Values
-
MAX_PORT
public static final int MAX_PORT- See Also:
- Constant Field Values
-
-
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
-
setState
-
setClientTurnManager
-
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 toserverPort- 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 joinroomName- name of the room to create or join
-
forwardAction
forward action to the next layer where it will be handled by the virtualModel- Parameters:
actionToForward- the action to forward
-
forwardMessage
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
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
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
Updates the turnState with the new state received by the server- Specified by:
phaseUpdatein interfacePhaseChangedObserver- Parameters:
nextPhase- the next state received by the server
-
getView
-