Class 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 client
      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
      void disconnectFromServer()
      method which disconnects the client from the server, thread stops isConnected status updated
      void forwardBeginFailed()
      handles the failure of a beginning game (less than 2 players in a game) for the GUI
      void forwardHighScore​(java.lang.String paramValue)
      handles the visualization of the highscore for the GUI
      void forwardJoinLobbyResponse​(boolean b)
      handles the lobby response
      void forwardManual​(java.lang.String paramValue)
      handles the manual for the GUI
      java.util.HashMap<java.lang.String,​Player> getActors()
      method which returns all the actors/players in the game
      ClientThread getClientThread()
      "getter" for client thread
      GameState getGameState()
      "getter" fot the current game state
      java.lang.String getLobby()
      "getter" for the lobby of a client
      void 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 GUI
      void 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 state
      void 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 GUI
      boolean isConnected()
      check method for the connection status
      void sendChatMessage​(java.lang.String message)
      method which sends the message in the chat
      void sendGetHighScore()
      sends the saved highscore
      void sendGetManual()
      sends the saved manual to Client
      void tryToChangeDirection​(java.lang.String direction)
      handles the change of the players direction, only changes if possible (if there is no wall)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 client
        ipAddress - - ip-address of the server
        port - - 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
      • 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