From c13152bb293da4b16eff1c9116305581684d13d6 Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Wed, 11 Dec 2024 23:31:52 +0100 Subject: [PATCH] added java docs to model --- .../src/main/java/pp/mdga/game/BonusNode.java | 5 + .../src/main/java/pp/mdga/game/Node.java | 21 ---- .../pp/mdga/message/client/ClientMessage.java | 5 + .../notification/AcquireCardNotification.java | 5 + .../mdga/notification/FinishNotification.java | 11 +- .../mdga/notification/GameNotification.java | 5 + .../mdga/notification/InfoNotification.java | 10 ++ .../notification/MovePieceNotification.java | 12 ++ .../RemoveShieldNotification.java | 12 ++ .../notification/RollDiceNotification.java | 31 ++++- .../SelectableShieldNotification.java | 16 ++- .../java/pp/mdga/server/ServerGameLogic.java | 110 +++++++++++++++++- .../pp/mdga/server/automaton/GameState.java | 29 ++++- .../server/automaton/game/AnimationState.java | 6 + .../game/DetermineStartPlayerState.java | 6 + .../mdga/server/automaton/game/TurnState.java | 20 ++++ .../automaton/game/turn/MovePieceState.java | 23 +++- .../game/turn/PlayPowerCardState.java | 9 +- .../automaton/game/turn/PowerCardState.java | 18 +++ .../automaton/game/turn/RollDiceState.java | 7 ++ .../game/turn/powercard/SwapCardState.java | 6 + .../game/turn/powercard/TurboCardState.java | 12 -- .../game/turn/rolldice/FirstRollState.java | 10 ++ .../game/turn/rolldice/SecondRollState.java | 13 +++ .../game/turn/rolldice/ThirdRollState.java | 13 +++ 25 files changed, 373 insertions(+), 42 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java index 27642566..020cd0bb 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/BonusNode.java @@ -14,6 +14,11 @@ public class BonusNode extends Node { super(null); } + /** + * This method will return true if the node is a bonus node. + * + * @return true if the node is a bonus node. + */ @Override public boolean isBonus() { return true; diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java index 6433a83a..f3b579d1 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Node.java @@ -50,27 +50,6 @@ public boolean isBonus() { return false; } - /** - * This method handles the event when a new occupant is moved to the node, - * it then returns the old occupant. - * - * @param newOccupant the new occupant of the node - * @return the old occupant of the node - */ - public Piece moveOccupant(Piece newOccupant) { - throw new RuntimeException("BÖSE METHODE !!!!"); - -// if (occupant == null) { -// setOccupant(newOccupant); -// return null; -// } else { -// occupant.setShield(ShieldState.NONE); -// occupant.setState(PieceState.WAITING); -// setOccupant(newOccupant); -// return occupant; -// } - } - /** * This method is used to clear the node of its occupant */ diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/client/ClientMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/client/ClientMessage.java index 3773ef6c..4a12057d 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/client/ClientMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/client/ClientMessage.java @@ -22,6 +22,11 @@ protected ClientMessage() { */ public abstract void accept(ClientInterpreter interpreter, int from); + /** + * Returns a string representation of this object. + * + * @return a string representation of this object + */ public String toString() { return getClass().getSimpleName() + "{}"; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java index 4640ca20..612b77ac 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java @@ -16,6 +16,11 @@ public AcquireCardNotification(BonusCard bonusCard) { this.bonusCard = bonusCard; } + /** + * This method will return the bonusCard attribute of AcquireCardNotification class. + * + * @return bonusCard as a BonusCard object. + */ public BonusCard getBonusCard() { return bonusCard; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/FinishNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/FinishNotification.java index 81009b24..9983e464 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/FinishNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/FinishNotification.java @@ -3,12 +3,21 @@ import pp.mdga.game.Color; public class FinishNotification extends Notification { - private Color colorFinished; + private final Color colorFinished; + + /** + * Constructor. + */ public FinishNotification(Color colorFinished) { this.colorFinished = colorFinished; } + /** + * This method will return the colorFinished attribute of FinishNotification class. + * + * @return colorFinished as a Color object. + */ public Color getColorFinished() { return colorFinished; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java index cda64ff0..75dbe613 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java @@ -16,6 +16,11 @@ public GameNotification(Color ownColor) { this.ownColor = ownColor; } + /** + * This method will return the ownColor attribute of GameNotification class. + * + * @return ownColor as a Color object. + */ public Color getOwnColor() { return ownColor; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/InfoNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/InfoNotification.java index b7f1de1e..6c2c0597 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/InfoNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/InfoNotification.java @@ -24,10 +24,20 @@ public InfoNotification(String info, boolean isError) { this.isError = isError; } + /** + * This method will return the message attribute of InfoNotification class. + * + * @return message as a String object. + */ public String getMessage() { return message; } + /** + * This method will return the isError attribute of InfoNotification class. + * + * @return isError as a boolean object. + */ public boolean isError() { return isError; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java index dd8b4bfc..b29aac82 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java @@ -56,18 +56,30 @@ public MovePieceNotification(UUID piece, int startIndex, int moveIndex) { this.moveStart = false; } + /** + * @return the destination node index + */ public int getMoveIndex() { return moveIndex; } + /** + * @return the starting node index + */ public int getStartIndex() { return startIndex; } + /** + * @return the unique identifier of the piece + */ public UUID getPiece() { return piece; } + /** + * @return {@code true} if the piece is moving from the waiting area to the start node + */ public boolean isMoveStart() { return moveStart; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/RemoveShieldNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/RemoveShieldNotification.java index 8c808f5c..cca6bc5c 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/RemoveShieldNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/RemoveShieldNotification.java @@ -3,12 +3,24 @@ import java.util.UUID; public class RemoveShieldNotification extends Notification { + + /** + * The UUID of the piece that has had its shield removed + */ private final UUID pieceUuid; + /** + * Constructor. + * + * @param pieceUuid the UUID of the piece that has had its shield removed + */ public RemoveShieldNotification(UUID pieceUuid) { this.pieceUuid = pieceUuid; } + /** + * @return the UUID of the piece that has had its shield removed + */ public UUID getPieceUuid() { return pieceUuid; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java index 8e12c1e8..2c222055 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java @@ -29,7 +29,13 @@ public RollDiceNotification(Color color, int eyes) { this.isRanking = false; } - //ranking + /** + * Constructor. + * + * @param color the color of the player that rolled the die. + * @param eyes the number of eyes that were rolled. + * @param isRanking whether the roll is for ranking purposes. + */ public RollDiceNotification(Color color, int eyes, boolean isRanking) { this.color = color; this.eyes = eyes; @@ -38,7 +44,13 @@ public RollDiceNotification(Color color, int eyes, boolean isRanking) { this.isRanking = isRanking; } - //turbo + /** + * Constructor. + * + * @param color the color of the player that rolled the die. + * @param eyes the number of eyes that were rolled. + * @param multiplier the multiplier of the roll. + */ public RollDiceNotification(Color color, int eyes, int multiplier) { this.color = color; this.eyes = eyes; @@ -65,14 +77,29 @@ public int getEyes() { return eyes; } + /** + * Get the multiplier of the roll. + * + * @return the multiplier of the roll. + */ public int getMultiplier() { return multiplier; } + /** + * Get whether the roll was a turbo roll. + * + * @return true if the roll was a turbo roll, false otherwise. + */ public boolean isTurbo() { return turbo; } + /** + * Get whether the roll was for ranking purposes. + * + * @return true if the roll was for ranking purposes, false otherwise. + */ public boolean isRanking() { return isRanking; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableShieldNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableShieldNotification.java index 53c11982..6ab7ddd4 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableShieldNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableShieldNotification.java @@ -4,12 +4,26 @@ import java.util.UUID; public class SelectableShieldNotification extends Notification { - private List pieces; + /** + * The list of piece IDs associated with the player. + */ + private final List pieces; + + /** + * Constructor. + * + * @param pieces the list of piece IDs associated with the player. + */ public SelectableShieldNotification(List pieces) { this.pieces = pieces; } + /** + * Get the list of piece IDs associated with the player. + * + * @return the list of piece IDs associated with the player. + */ public List getPieces() { return pieces; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java index 473e46a4..efabb988 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java @@ -16,7 +16,7 @@ public class ServerGameLogic implements ClientInterpreter { private static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName()); /** - * + * Attributes. */ private final ServerSender serverSender; private final Game game; @@ -47,91 +47,199 @@ public ServerGameLogic(ServerSender serverSender, Game game) { } + /** + * Handles the reception of an AnimationEndMessage. + * + * @param msg the received AnimationEndMessage + * @param from the sender of the message + */ @Override public void received(AnimationEndMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a DeselectTSKMessage. + * + * @param msg the received DeselectTSKMessage + * @param from the sender of the message + */ @Override public void received(DeselectTSKMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a StartGameMessage. + * + * @param msg the received StartGameMessage + * @param from the sender of the message + */ @Override public void received(StartGameMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a JoinedLobbyMessage. + * + * @param msg the received JoinedLobbyMessage + * @param from the sender of the message + */ @Override public void received(JoinedLobbyMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a LeaveGameMessage. + * + * @param msg the received LeaveGameMessage + * @param from the sender of the message + */ @Override public void received(LeaveGameMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a LobbyReadyMessage. + * + * @param msg the received LobbyReadyMessage + * @param from the sender of the message + */ @Override public void received(LobbyReadyMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a LobbyNotReadyMessage. + * + * @param msg the received LobbyNotReadyMessage + * @param from the sender of the message + */ @Override public void received(LobbyNotReadyMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a DisconnectedMessage. + * + * @param msg the received DisconnectedMessage + * @param from the sender of the message + */ @Override public void received(DisconnectedMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a RequestBriefingMessage. + * + * @param msg the received RequestBriefingMessage + * @param from the sender of the message + */ @Override public void received(RequestBriefingMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a RequestDieMessage. + * + * @param msg the received RequestDieMessage + * @param from the sender of the message + */ @Override public void received(RequestDieMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a RequestMoveMessage. + * + * @param msg the received RequestMoveMessage + * @param from the sender of the message + */ @Override public void received(RequestMoveMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a RequestPlayCardMessage. + * + * @param msg the received RequestPlayCardMessage + * @param from the sender of the message + */ @Override public void received(RequestPlayCardMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a SelectCardMessage. + * + * @param msg the received SelectCardMessage + * @param from the sender of the message + */ @Override public void received(SelectCardMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a SelectTSKMessage. + * + * @param msg the received SelectTSKMessage + * @param from the sender of the message + */ @Override public void received(SelectTSKMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a ForceContinueGameMessage. + * + * @param msg the received ForceContinueGameMessage + * @param from the sender of the message + */ @Override public void received(ForceContinueGameMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a ClientStartGameMessage. + * + * @param msg the received ClientStartGameMessage + * @param from the sender of the message + */ @Override public void received(ClientStartGameMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a NoPowerCardMessage. + * + * @param msg the received NoPowerCardMessage + * @param from the sender of the message + */ @Override public void received(NoPowerCardMessage msg, int from) { this.currentState.received(msg, from); } + /** + * Handles the reception of a SelectedPiecesMessage. + * + * @param msg the received SelectedPiecesMessage + * @param from the sender of the message + */ @Override public void received(SelectedPiecesMessage msg, int from) { this.currentState.received(msg, from); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/GameState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/GameState.java index 0e28edf5..3de79022 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/GameState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/GameState.java @@ -85,19 +85,46 @@ public void received(LeaveGameMessage msg, int from) { } } + /** + * This method will be called whenever the server received an NoPowerCardMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a NoPowerCardMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(NoPowerCardMessage msg, int from) { this.currentState.received(msg, from); } + /** + * This method will be called whenever the server received a SelectCardMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a SelectCardMessage object. + * @param from as the client id of the player as an Integer. + */ public void received(SelectCardMessage msg, int from) { currentState.received(msg, from); } - + /** + * This method will be called whenever the server received a RequestMoveMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a RequestMoveMessage object. + * @param from as the client id of the player as an Integer. + */ public void received(RequestMoveMessage msg, int from) { this.currentState.received(msg, from); } + /** + * This method will be called whenever the server received a SelectedPiecesMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a SelectedPiecesMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(SelectedPiecesMessage msg, int from) { this.currentState.received(msg, from); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/AnimationState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/AnimationState.java index 28282d10..dcf9c9a9 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/AnimationState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/AnimationState.java @@ -31,11 +31,17 @@ public AnimationState(GameState gameAutomaton, ServerGameLogic logic) { super(gameAutomaton, logic); } + /** + * This method will be used whenever this state will be entered. + */ @Override public void enter() { LOGGER.log(System.Logger.Level.DEBUG, "Entered AnimationState state."); } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { LOGGER.log(System.Logger.Level.DEBUG, "Exited AnimationState state."); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/DetermineStartPlayerState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/DetermineStartPlayerState.java index ef649e38..a91f3e57 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/DetermineStartPlayerState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/DetermineStartPlayerState.java @@ -38,12 +38,18 @@ public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic) super(gameAutomaton, logic); } + /** + * This method will be used whenever this state will be entered. + */ @Override public void enter() { LOGGER.log(System.Logger.Level.INFO, "Entered DetermineStartPlayerState state."); playerToStart = this.logic.getGame().getPlayers().size(); } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { LOGGER.log(Level.INFO, "Exited DetermineStartPlayerState state."); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/TurnState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/TurnState.java index e8b07dc5..0db386ec 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/TurnState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/TurnState.java @@ -45,6 +45,9 @@ public TurnState(GameState gameAutomaton, ServerGameLogic logic) { this.movePieceState = new MovePieceState(this, logic); } + /** + * This method will be used whenever this state will be entered. + */ @Override public void enter() { LOGGER.log(Level.INFO, "Entered TurnState state."); @@ -55,6 +58,9 @@ public void enter() { this.setCurrentState(this.powerCardState); } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { LOGGER.log(Level.DEBUG, "Exited TurnState state."); @@ -108,11 +114,25 @@ public void received(RequestMoveMessage msg, int from) { this.currentState.received(msg, from); } + /** + * This method will be called whenever the server received a AnimationEndMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a AnimationEndMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(AnimationEndMessage msg, int from) { this.currentState.received(msg, from); } + /** + * This method will be called whenever the server received a SelectCardMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a SelectCardMessage object. + * @param from as the client id of the player as an Integer. + */ public void received(SelectCardMessage msg, int from) { currentState.received(msg, from); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/MovePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/MovePieceState.java index c12c89ad..d8d2af29 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/MovePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/MovePieceState.java @@ -30,17 +30,31 @@ public MovePieceState(TurnState turnAutomaton, ServerGameLogic logic) { super(turnAutomaton, logic); } + /** + * This method will be used whenever this state will be entered. + */ @Override public void enter() { LOGGER.log(System.Logger.Level.DEBUG, "Entered MovePieceState state."); } + /** + * Sets the active player to the next player in the game. + * + * @param activePlayer the current active player color + */ private void setActivePlayer(Color activePlayer) { Color newColor = activePlayer.next(logic.getGame()); logic.getGame().setActiveColor(newColor); logic.getServerSender().broadcast(new ActivePlayerMessage(newColor)); } + /** + * Handles the received AnimationEndMessage. + * + * @param msg the received AnimationEndMessage + * @param from the ID of the player who sent the message + */ @Override public void received(AnimationEndMessage msg, int from) { finishedAnimations.add(logic.getGame().getPlayerById(from)); @@ -55,10 +69,12 @@ public void received(AnimationEndMessage msg, int from) { return; } this.turnAutomaton.getGameAutomaton().setCurrentState(this.turnAutomaton.getGameAutomaton().getTurnState()); - } else if (logic.getGame().getDiceEyes() == 6) { + } + else if (logic.getGame().getDiceEyes() == 6) { logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new DiceNowMessage()); this.turnAutomaton.setCurrentState(this.turnAutomaton.getRollDiceState()); - } else { + } + else { logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new EndOfTurnMessage()); setActivePlayer(logic.getGame().getActiveColor()); this.turnAutomaton.getGameAutomaton().setCurrentState(this.turnAutomaton.getGameAutomaton().getTurnState()); @@ -66,6 +82,9 @@ public void received(AnimationEndMessage msg, int from) { } } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { finishedAnimations.clear(); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PlayPowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PlayPowerCardState.java index a70bd9d3..d0cc6a23 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PlayPowerCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PlayPowerCardState.java @@ -17,7 +17,7 @@ public class PlayPowerCardState extends TurnAutomatonState { /** * Create PlayPowerCardState attributes. */ - private Set messageReceived = new HashSet(); + private final Set messageReceived = new HashSet(); /** * Constructs a server state of the specified game logic. @@ -29,13 +29,20 @@ public PlayPowerCardState(TurnState turnAutomaton, ServerGameLogic logic) { super(turnAutomaton, logic); } + /** + * This method will be used whenever this state will be entered. + */ @Override public void enter() { LOGGER.log(System.Logger.Level.DEBUG, "Entered PlayPowerCardState state."); } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { + messageReceived.clear(); LOGGER.log(System.Logger.Level.DEBUG, "Exited PlayPowerCardState state."); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PowerCardState.java index 22edc79f..eb35ddb7 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PowerCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PowerCardState.java @@ -54,6 +54,13 @@ public PowerCardState(TurnState turnAutomaton, ServerGameLogic logic) { } + /** + * Enters the PowerCardState state. + * Clears the checked cards, logs the entry, sets the current state to choosePowerCardState, + * initializes the visitor, and processes the player's hand cards. + * If no cards are available, sends a DiceNowMessage and transitions to RollDiceState. + * Otherwise, sends a PossibleCardsMessage with the available cards. + */ @Override public void enter() { chekedCards.clear(); @@ -75,11 +82,22 @@ public void enter() { } } + /** + * Exits the PowerCardState state. + * Logs the exit. + */ @Override public void exit() { LOGGER.log(System.Logger.Level.DEBUG, "Exit PowerCardState state."); } + /** + * Handles the received NoPowerCardMessage. + * Delegates the message handling to the current state's received method. + * + * @param msg the NoPowerCardMessage received + * @param form the client id of the player who sent the message + */ @Override public void received(NoPowerCardMessage msg, int form) { currentState.received(msg, form); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/RollDiceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/RollDiceState.java index 5dc8823a..6e051ff2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/RollDiceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/RollDiceState.java @@ -64,6 +64,13 @@ public void received(RequestDieMessage msg, int from) { this.currentState.received(msg, from); } + /** + * This method will be called whenever the server received a AnimationEndMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a AnimationEndMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(AnimationEndMessage msg, int from) { this.currentState.received(msg, from); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/SwapCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/SwapCardState.java index ce361b9e..5774543f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/SwapCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/SwapCardState.java @@ -88,6 +88,12 @@ public void received(SelectedPiecesMessage msg, int from) { } } + /** + * This method will swap the pieces of the given messageOwn and messageEnemy. + * + * @param messageOwn as the own piece as a Piece object. + * @param messageEnemy as the enemy piece as a Piece object. + */ private void swapPieces(Piece messageOwn, Piece messageEnemy) { //swap Pieces in Model Board board = logic.getGame().getBoard(); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/TurboCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/TurboCardState.java index 8ab230dd..e8c40b2e 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/TurboCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/powercard/TurboCardState.java @@ -39,16 +39,4 @@ public void enter() { public void exit() { } - - /** - * This method will be called whenever the server received a SelectedPiecesMessage message. - * It will also get the client id of the player who send this message. - * - * @param msg as the message which was sent by the player as a SelectedPiecesMessage object. - * @param from as the client id of the player as an Integer. - */ - @Override - public void received(SelectedPiecesMessage msg, int from) { - // ToDo: We can use this method to catch irregular client messages. - } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollState.java index c0d30c77..33a266a1 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollState.java @@ -45,6 +45,9 @@ public void enter() { } } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { LOGGER.log(System.Logger.Level.INFO, "Exited FirstRollState state."); @@ -69,6 +72,13 @@ public void received(RequestDieMessage msg, int from) { isDied = true; } + /** + * This method will be called whenever the server received a AnimationEndMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a AnimationEndMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(AnimationEndMessage msg, int from) { if (from != this.logic.getGame().getActivePlayerId()) { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/SecondRollState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/SecondRollState.java index d2625fad..6e9df0f4 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/SecondRollState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/SecondRollState.java @@ -25,12 +25,18 @@ public SecondRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) { super(rollDiceAutomaton, logic); } + /** + * This method will be used whenever this state will be entered. + */ @Override public void enter() { this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage()); LOGGER.log(System.Logger.Level.DEBUG, "Entered SecondRollState state."); } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { LOGGER.log(System.Logger.Level.DEBUG, "Exited SecondRollState state."); @@ -54,6 +60,13 @@ public void received(RequestDieMessage msg, int from) { this.logic.getServerSender().broadcast(new DieMessage(roll)); } + /** + * This method will be called whenever the server received a AnimationEndMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a AnimationEndMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(AnimationEndMessage msg, int from) { if (from != this.logic.getGame().getActivePlayerId()) { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/ThirdRollState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/ThirdRollState.java index 72920f2a..f2a0b8ea 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/ThirdRollState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/ThirdRollState.java @@ -23,12 +23,18 @@ public ThirdRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) { super(rollDiceAutomaton, logic); } + /** + * This method will be used whenever this state will be entered. + */ @Override public void enter() { this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage()); LOGGER.log(System.Logger.Level.DEBUG, "Exited ThirdRollState state."); } + /** + * This method will be used whenever this state will be exited. + */ @Override public void exit() { LOGGER.log(System.Logger.Level.DEBUG, "Entered ThirdRollState state."); @@ -52,6 +58,13 @@ public void received(RequestDieMessage msg, int from) { this.logic.getServerSender().broadcast(new DieMessage(roll)); } + /** + * This method will be called whenever the server received a AnimationEndMessage message. + * It will also get the client id of the player who send this message. + * + * @param msg as the message which was sent by the player as a AnimationEndMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(AnimationEndMessage msg, int from) { if (from != this.logic.getGame().getActivePlayerId()) {