Klasse ServerGameLogic

java.lang.Object
pp.battleship.game.server.ServerGameLogic
Alle implementierten Schnittstellen:
ClientInterpreter

public class ServerGameLogic extends Object implements ClientInterpreter
Controls the server-side game logic for Battleship. Manages game states, player interactions, and message handling.
  • Konstruktordetails

    • ServerGameLogic

      public ServerGameLogic(ServerSender serverSender, BattleshipConfig config)
      Constructs a ServerGameLogic with the specified sender and configuration.
      Parameter:
      serverSender - the sender used to send messages to clients
      config - the game configuration
  • Methodendetails

    • getPlayerById

      public Player getPlayerById(int id)
      Returns the player representing the client with the specified connection ID.
      Parameter:
      id - the ID of the client
      Gibt zurück:
      the player associated with the client ID, or null if not found
    • addPlayer

      public Player addPlayer(int id)
      Adds a new player to the game if there are less than two players. Transitions the state to SET_UP if two players are present.
      Parameter:
      id - the connection ID of the new player
      Gibt zurück:
      the player added to the game, or null if the game is not in the right state
    • received

      public void received(MapMessage msg, int from)
      Handles the reception of a MapMessage. Also tests if Map is in correct format
      Angegeben von:
      received in Schnittstelle ClientInterpreter
      Parameter:
      msg - the received MapMessage
      from - the ID of the sender client
    • received

      public void received(ShootMessage msg, int from)
      Handles the reception of a ShootMessage.
      Angegeben von:
      received in Schnittstelle ClientInterpreter
      Parameter:
      msg - the received ShootMessage
      from - the ID of the sender client
    • received

      public void received(ShellAnimationFinishedMessage msg, int from)
      Handles the reception of ShellAnimationFinishedMessage. This method is called when a client signals that its shell animation is complete.
      Angegeben von:
      received in Schnittstelle ClientInterpreter
      Parameter:
      msg - the received ShellAnimationFinishedMessage
      from - the ID of the sender client