Klasse ServerConnectionMockup

java.lang.Object
pp.battleship.game.singlemode.ServerConnectionMockup
Alle implementierten Schnittstellen:
ClientSender, ServerConnection, ServerSender

public class ServerConnectionMockup extends Object implements ServerConnection, ServerSender
A mock implementation of the ServerConnection interface for single mode. Simulates a server connection without actual network communication. Handles a mock player named RobotClient and schedules its shots when due.
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
    Constructs a ServerConnectionMockup instance for the given Battleship application.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    void
    Simulates connecting to a server by adding the PlayerClient and the RobotClient to the serverGameLogic.
    void
    Does nothing upon shutdown of the app.
    boolean
    Always returns true as this is a mock connection.
    void
    send(int id, ServerMessage message)
    Forwards the specified message received from the server logic either to the player client or to the robot client, depending on the specified id.
    void
    Forwards the specified message received from the player client to the server logic.

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Konstruktordetails

    • ServerConnectionMockup

      public ServerConnectionMockup(BattleshipClient playerClient)
      Constructs a ServerConnectionMockup instance for the given Battleship application. Creates a RobotClient instance and an instance of ServerGameLogic.
      Parameter:
      playerClient - The Battleship client instance, e.g., a BattleshipApp instance.
  • Methodendetails

    • isConnected

      public boolean isConnected()
      Always returns true as this is a mock connection.
      Angegeben von:
      isConnected in Schnittstelle ServerConnection
      Gibt zurück:
      true, indicating the mock connection is always considered connected.
    • connect

      public void connect()
      Simulates connecting to a server by adding the PlayerClient and the RobotClient to the serverGameLogic. Loads the map of the PlayerClient and triggers sending it to the serverGameLogic.
      Angegeben von:
      connect in Schnittstelle ServerConnection
    • disconnect

      public void disconnect()
      Does nothing upon shutdown of the app.
      Angegeben von:
      disconnect in Schnittstelle ServerConnection
    • send

      public void send(ClientMessage message)
      Forwards the specified message received from the player client to the server logic.
      Angegeben von:
      send in Schnittstelle ClientSender
      Parameter:
      message - The message from the player client to be processed.
    • send

      public void send(int id, ServerMessage message)
      Forwards the specified message received from the server logic either to the player client or to the robot client, depending on the specified id.
      Angegeben von:
      send in Schnittstelle ServerSender
      Parameter:
      id - The recipient id
      message - The server message to be processed
      Siehe auch:
      • PLAYER_CLIENT
      • ROBOT_CLIENT