Klasse ClientGameLogic

java.lang.Object
pp.battleship.game.client.ClientGameLogic
Alle implementierten Schnittstellen:
ServerInterpreter, GameEventBroker

public class ClientGameLogic extends Object implements ServerInterpreter, GameEventBroker
Controls the client-side game logic for Battleship. Manages the player's ship placement, interactions with the map, and response to server messages.
  • Konstruktordetails

    • ClientGameLogic

      public ClientGameLogic(ClientSender clientSender)
      Constructs a ClientGameLogic with the specified sender object.
      Parameter:
      clientSender - the object used to send messages to the server
  • Methodendetails

    • getOwnMap

      public ShipMap getOwnMap()
      Returns the player's own map.
      Gibt zurück:
      the player's own map
    • getOpponentMap

      public ShipMap getOpponentMap()
      Returns the opponent's map.
      Gibt zurück:
      the opponent's map
    • getHarbor

      public ShipMap getHarbor()
      Returns the harbor map.
      Gibt zurück:
      the harbor map
    • showEditor

      public boolean showEditor()
      Checks if the editor should be shown.
      Gibt zurück:
      true if the editor should be shown, false otherwise
    • showBattle

      public boolean showBattle()
      Checks if the battle state should be shown.
      Gibt zurück:
      true if the battle state should be shown, false otherwise
    • received

      public void received(GameDetails details)
      Sets the game details provided by the server.
      Angegeben von:
      received in Schnittstelle ServerInterpreter
      Parameter:
      details - the game details including map size and ships
    • movePreview

      public void movePreview(IntPoint pos)
      Moves the preview ship to the specified position.
      Parameter:
      pos - the new position for the preview ship
    • clickOwnMap

      public void clickOwnMap(IntPoint pos)
      Handles a click on the player's own map.
      Parameter:
      pos - the position where the click occurred
    • clickHarbor

      public void clickHarbor(IntPoint pos)
      Handles a click on the harbor map.
      Parameter:
      pos - the position where the click occurred
    • clickOpponentMap

      public void clickOpponentMap(IntPoint pos)
      Handles a click on the opponent's map.
      Parameter:
      pos - the position where the click occurred
    • rotateShip

      public void rotateShip()
      Rotates the preview ship.
    • mapFinished

      public void mapFinished()
      Marks the player's map as finished.
    • isMapComplete

      public boolean isMapComplete()
      Checks if the player's map is complete (i.e., all ships are placed).
      Gibt zurück:
      true if all ships are placed, false otherwise
    • movingShip

      public boolean movingShip()
      Checks if there is currently a preview ship.
      Gibt zurück:
      true if there is currently a preview ship, false otherwise
    • received

      public void received(StartBattleMessage msg)
      Starts the battle based on the server message.
      Angegeben von:
      received in Schnittstelle ServerInterpreter
      Parameter:
      msg - the message indicating whose turn it is to shoot
    • received

      public void received(EffectMessage msg)
      Reports the effect of a shot based on the server message.
      Angegeben von:
      received in Schnittstelle ServerInterpreter
      Parameter:
      msg - the message containing the effect of the shot
    • playSound

      public void playSound(Sound sound)
      Emits an event to play the specified sound.
      Parameter:
      sound - the sound to be played.
    • loadMap

      public void loadMap(File file) throws IOException
      Loads a map from the specified file.
      Parameter:
      file - the file to load the map from
      Löst aus:
      IOException - if an I/O error occurs
    • mayLoadMap

      public boolean mayLoadMap()
      Checks if the player's own map may be loaded from a file.
      Gibt zurück:
      true if the own map may be loaded from file, false otherwise
    • maySaveMap

      public boolean maySaveMap()
      Checks if the player's own map may be saved to a file.
      Gibt zurück:
      true if the own map may be saved to file, false otherwise
    • saveMap

      public void saveMap(File file) throws IOException
      Saves the player's own map to the specified file.
      Parameter:
      file - the file to save the map to
      Löst aus:
      IOException - if the map cannot be saved in the current state
    • addListener

      public void addListener(GameEventListener listener)
      Adds a listener to receive game events.
      Parameter:
      listener - the listener to add
    • removeListener

      public void removeListener(GameEventListener listener)
      Removes a listener from receiving game events.
      Parameter:
      listener - the listener to remove
    • notifyListeners

      public void notifyListeners(GameEvent event)
      Notifies all listeners of a game event.
      Angegeben von:
      notifyListeners in Schnittstelle GameEventBroker
      Parameter:
      event - the game event to notify listeners of
    • update

      public void update(float delta)
      Called once per frame by the update loop.
      Parameter:
      delta - time in seconds since the last update call