Package pacManReloaded.client
Class Client
- java.lang.Object
-
- pacManReloaded.client.Client
-
public class Client extends java.lang.Object
Client class creates client and handles its actions.
-
-
Constructor Summary
Constructors Constructor Description Client(java.lang.String nickname, java.lang.String ipAddress, int port)
Constructor of Client, opens a new socket to be able to connect to the server 3 args: - 1: ip address - 2: port of the socket - 3: name (optional, if no third argument: username of computer used) let you choose your name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changeName(java.lang.String name)
the method changes the name of the client and adds the new name on the playerlist for the same clientboolean
connectToServer()
method which connects the client to the server, if the client already runs a thread opens a new socket with the ip address and the port of the servervoid
disconnectFromServer()
method which disconnects the client from the server, thread stops isConnected status updatedvoid
forwardBeginFailed()
handles the failure of a beginning game (less than 2 players in a game) for the GUIvoid
forwardHighScore(java.lang.String paramValue)
handles the visualization of the highscore for the GUIvoid
forwardJoinLobbyResponse(boolean b)
handles the lobby responsevoid
forwardManual(java.lang.String paramValue)
handles the manual for the GUIjava.util.HashMap<java.lang.String,Player>
getActors()
method which returns all the actors/players in the gameClientThread
getClientThread()
"getter" for client threadGameState
getGameState()
"getter" fot the current game statejava.lang.String
getLobby()
"getter" for the lobby of a clientvoid
handleActorInit(java.lang.String paramValue)
handles the "decision" of which player is going to be which type (PacMan or Ghost?)void
handleActorPos(java.lang.String parm)
handles the position and direction of the player on the field, gives infos to the client GUIvoid
handleGameFinish(GameFinishedMessage gameFinishedMessage)
void
handleGameState(java.lang.String paramValue)
handles the state of the game, containing scores and "superpower"void
handleInitGameState(java.lang.String paramValue)
initialization of the game statevoid
handleMap(MapMessage mapMessage)
gets infos about the map, creates and paints it to the ClientGUI.void
handleRemoveObject(java.lang.String paramValue)
method which handles the removing of an object, which was taken buy a player from the field, deletes the object from the client GUIboolean
isConnected()
check method for the connection statusvoid
sendChatMessage(java.lang.String message)
method which sends the message in the chatvoid
sendGetHighScore()
sends the saved highscorevoid
sendGetManual()
sends the saved manual to Clientvoid
tryToChangeDirection(java.lang.String direction)
handles the change of the players direction, only changes if possible (if there is no wall)
-
-
-
Constructor Detail
-
Client
public Client(java.lang.String nickname, java.lang.String ipAddress, int port)
Constructor of Client, opens a new socket to be able to connect to the server 3 args: - 1: ip address - 2: port of the socket - 3: name (optional, if no third argument: username of computer used) let you choose your name.- Parameters:
nickname
- - name of your clientipAddress
- - ip-address of the serverport
- - port of the server
-
-
Method Detail
-
disconnectFromServer
public void disconnectFromServer()
method which disconnects the client from the server, thread stops isConnected status updated
-
sendChatMessage
public void sendChatMessage(java.lang.String message)
method which sends the message in the chat- Parameters:
message
- - message to be send
-
connectToServer
public boolean connectToServer()
method which connects the client to the server, if the client already runs a thread opens a new socket with the ip address and the port of the server- Returns:
- status (as boolean) if connection worked (true) or failed (false)
-
changeName
public void changeName(java.lang.String name)
the method changes the name of the client and adds the new name on the playerlist for the same client- Parameters:
name
- your new ingame name
-
tryToChangeDirection
public void tryToChangeDirection(java.lang.String direction)
handles the change of the players direction, only changes if possible (if there is no wall)- Parameters:
direction
- the direction the player wants to go
-
sendGetManual
public void sendGetManual()
sends the saved manual to Client
-
sendGetHighScore
public void sendGetHighScore()
sends the saved highscore
-
handleMap
public void handleMap(MapMessage mapMessage) throws java.lang.Exception
gets infos about the map, creates and paints it to the ClientGUI.- Parameters:
mapMessage
- - message with infos about the map that should be created.- Throws:
java.lang.Exception
- - throws exception if something goes wrong with the map-load.
-
handleActorInit
public void handleActorInit(java.lang.String paramValue)
handles the "decision" of which player is going to be which type (PacMan or Ghost?)- Parameters:
paramValue
- information about the initialization of the players
-
handleInitGameState
public void handleInitGameState(java.lang.String paramValue)
initialization of the game state- Parameters:
paramValue
- information about the initialization of the game state
-
handleGameState
public void handleGameState(java.lang.String paramValue)
handles the state of the game, containing scores and "superpower"- Parameters:
paramValue
- information about the current game state
-
handleActorPos
public void handleActorPos(java.lang.String parm)
handles the position and direction of the player on the field, gives infos to the client GUI- Parameters:
parm
- information about the initialisation of the players
-
handleRemoveObject
public void handleRemoveObject(java.lang.String paramValue)
method which handles the removing of an object, which was taken buy a player from the field, deletes the object from the client GUI- Parameters:
paramValue
- information about the initialisation of the players
-
forwardJoinLobbyResponse
public void forwardJoinLobbyResponse(boolean b)
handles the lobby response- Parameters:
b
- status of lobby connection
-
forwardBeginFailed
public void forwardBeginFailed()
handles the failure of a beginning game (less than 2 players in a game) for the GUI
-
forwardHighScore
public void forwardHighScore(java.lang.String paramValue)
handles the visualization of the highscore for the GUI- Parameters:
paramValue
- the highscore as string
-
forwardManual
public void forwardManual(java.lang.String paramValue)
handles the manual for the GUI- Parameters:
paramValue
- the text in the manual
-
handleGameFinish
public void handleGameFinish(GameFinishedMessage gameFinishedMessage)
-
isConnected
public boolean isConnected()
check method for the connection status- Returns:
- connection status (true: connected; false: not connected)
-
getClientThread
public ClientThread getClientThread()
"getter" for client thread- Returns:
- the thread of the client
-
getLobby
public java.lang.String getLobby()
"getter" for the lobby of a client- Returns:
- the lobbyname of the client
-
getActors
public java.util.HashMap<java.lang.String,Player> getActors()
method which returns all the actors/players in the game- Returns:
- the players
-
getGameState
public GameState getGameState()
"getter" fot the current game state- Returns:
- the current game state
-
-