Package pp.battleship.game.server
Klasse ServerGameLogic
java.lang.Object
pp.battleship.game.server.ServerGameLogic
- Alle implementierten Schnittstellen:
ClientInterpreter
Controls the server-side game logic for Battleship.
Manages game states, player interactions, and message handling.
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungServerGameLogic(ServerSender serverSender, BattleshipConfig config) Constructs a ServerGameLogic with the specified sender and configuration. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungaddPlayer(int id) Adds a new player to the game if there are less than two players.getPlayerById(int id) Returns the player representing the client with the specified connection ID.voidreceived(MapMessage msg, int from) Handles the reception of a MapMessage.voidreceived(ShellAnimationFinishedMessage msg, int from) Handles the reception of ShellAnimationFinishedMessage.voidreceived(ShootMessage msg, int from) Handles the reception of a ShootMessage.
-
Konstruktordetails
-
ServerGameLogic
Constructs a ServerGameLogic with the specified sender and configuration.- Parameter:
serverSender- the sender used to send messages to clientsconfig- the game configuration
-
-
Methodendetails
-
getPlayerById
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
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
Handles the reception of a MapMessage. Also tests if Map is in correct format- Angegeben von:
receivedin SchnittstelleClientInterpreter- Parameter:
msg- the received MapMessagefrom- the ID of the sender client
-
received
Handles the reception of a ShootMessage.- Angegeben von:
receivedin SchnittstelleClientInterpreter- Parameter:
msg- the received ShootMessagefrom- the ID of the sender client
-
received
Handles the reception of ShellAnimationFinishedMessage. This method is called when a client signals that its shell animation is complete.- Angegeben von:
receivedin SchnittstelleClientInterpreter- Parameter:
msg- the received ShellAnimationFinishedMessagefrom- the ID of the sender client
-