Package pp.battleship.game.client
Klasse ClientGameLogic
java.lang.Object
pp.battleship.game.client.ClientGameLogic
- Alle implementierten Schnittstellen:
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.
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungClientGameLogic(ClientSender clientSender) Constructs a ClientGameLogic with the specified sender object. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidaddListener(GameEventListener listener) Adds a listener to receive game events.voidclickHarbor(IntPoint pos) Handles a click on the harbor map.voidclickOpponentMap(IntPoint pos) Handles a click on the opponent's map.voidclickOwnMap(IntPoint pos) Handles a click on the player's own map.Returns the harbor map.Returns the opponent's map.Returns the player's own map.booleanChecks if the player's map is complete (i.e., all ships are placed).voidLoads a map from the specified file.voidMarks the player's map as finished.booleanChecks if the player's own map may be loaded from a file.booleanChecks if the player's own map may be saved to a file.voidmovePreview(IntPoint pos) Moves the preview ship to the specified position.booleanChecks if there is currently a preview ship.voidnotifyListeners(GameEvent event) Notifies all listeners of a game event.voidEmits an event to play the specified sound.voidreceived(EffectMessage msg) Reports the effect of a shot based on the server message.voidreceived(GameDetails details) Sets the game details provided by the server.voidStarts the battle based on the server message.voidremoveListener(GameEventListener listener) Removes a listener from receiving game events.voidRotates the preview ship.voidSaves the player's own map to the specified file.booleanChecks if the battle state should be shown.booleanChecks if the editor should be shown.voidupdate(float delta) Called once per frame by the update loop.
-
Konstruktordetails
-
ClientGameLogic
Constructs a ClientGameLogic with the specified sender object.- Parameter:
clientSender- the object used to send messages to the server
-
-
Methodendetails
-
getOwnMap
Returns the player's own map.- Gibt zurück:
- the player's own map
-
getOpponentMap
Returns the opponent's map.- Gibt zurück:
- the opponent's map
-
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
Sets the game details provided by the server.- Angegeben von:
receivedin SchnittstelleServerInterpreter- Parameter:
details- the game details including map size and ships
-
movePreview
Moves the preview ship to the specified position.- Parameter:
pos- the new position for the preview ship
-
clickOwnMap
Handles a click on the player's own map.- Parameter:
pos- the position where the click occurred
-
clickHarbor
Handles a click on the harbor map.- Parameter:
pos- the position where the click occurred
-
clickOpponentMap
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
Starts the battle based on the server message.- Angegeben von:
receivedin SchnittstelleServerInterpreter- Parameter:
msg- the message indicating whose turn it is to shoot
-
received
Reports the effect of a shot based on the server message.- Angegeben von:
receivedin SchnittstelleServerInterpreter- Parameter:
msg- the message containing the effect of the shot
-
playSound
Emits an event to play the specified sound.- Parameter:
sound- the sound to be played.
-
loadMap
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
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
Adds a listener to receive game events.- Parameter:
listener- the listener to add
-
removeListener
Removes a listener from receiving game events.- Parameter:
listener- the listener to remove
-
notifyListeners
Notifies all listeners of a game event.- Angegeben von:
notifyListenersin SchnittstelleGameEventBroker- 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
-