From 5206b039665d7a6b3330ead9c05680ba785b45cd Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 17:03:56 +0100 Subject: [PATCH 1/9] added java docs --- .../java/pp/mdga/client/InterruptState.java | 9 +++++++++ .../java/pp/mdga/client/SettingsState.java | 18 ++++++++++++++++++ .../pp/mdga/client/dialogState/LobbyState.java | 1 + .../choosePieceState/NoPieceState.java | 10 +++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java index 1537b748..8c8d35d8 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/InterruptState.java @@ -8,10 +8,19 @@ public class InterruptState extends ClientState { private ClientState previousState; + /** + * Creates a new InterruptState + * + * @param parent the parent state + * @param logic the game logic + */ public InterruptState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } + /** + * Enters the new state machine + */ @Override public void enter() { previousState = null; diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/SettingsState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/SettingsState.java index 969a08cf..5c399750 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/SettingsState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/SettingsState.java @@ -7,26 +7,44 @@ public class SettingsState extends ClientState { + /** + * The current state of the settings + */ private SettingStates currentState; private final MainSettingsState mainSettingsState = new MainSettingsState(this, logic); private final AudioSettingsState audioSettingsState = new AudioSettingsState(this, logic); private final VideoSettingsState videoSettingsState = new VideoSettingsState(this, logic); + /** + * Creates a new SettingsState + * + * @param parent the parent state + * @param logic the game logic + */ public SettingsState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } + /** + * Enters the current state + */ @Override public void enter() { currentState = mainSettingsState; } + /** + * Exits the current state + */ @Override public void exit() { currentState.exit(); } + /** + * Changes the current state + */ public SettingStates getState(){ return currentState; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java index c744b0e0..747211ae 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java @@ -35,6 +35,7 @@ public void exit() { @Override public void selectLeave() { parent.setState(parent.getStartDialog()); + logic.send(new LeaveGameMessage()); } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/NoPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/NoPieceState.java index bb79480e..60b41e44 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/NoPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/NoPieceState.java @@ -11,6 +11,8 @@ import pp.mdga.notification.WaitMoveNotification; import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; public class NoPieceState extends ChoosePieceStates { @@ -49,7 +51,13 @@ public void received(WaitPieceMessage msg){ @Override public void received(StartPieceMessage msg){ Piece piece = logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()); - //TODO: logic.addNotification(null); + List listPiece = new ArrayList<>(); + List listIndex = new ArrayList<>(); + List homeMove = new ArrayList<>(); + listPiece.add(piece.getUuid()); + listIndex.add(msg.getTargetIndex()); + homeMove.add(false); + logic.addNotification(new SelectableMoveNotification(listPiece, listIndex, homeMove)); parent.setState(parent.getStartPiece()); } From ef450a23f55649f9e78ad49bb0bd7f1259a90667 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 1 Dec 2024 20:35:40 +0100 Subject: [PATCH 2/9] added logger to server state chart --- .../mdga/server/automaton/CeremonyState.java | 7 +- .../pp/mdga/server/automaton/GameState.java | 104 +++++++++++++++++- .../mdga/server/automaton/InterruptState.java | 7 +- .../pp/mdga/server/automaton/LobbyState.java | 28 ++++- 4 files changed, 141 insertions(+), 5 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/CeremonyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/CeremonyState.java index 4182bdb1..42a48d68 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/CeremonyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/CeremonyState.java @@ -6,6 +6,11 @@ * */ public class CeremonyState extends ServerState { + /** + * Create LobbyState constants. + */ + private static final System.Logger LOGGER = System.getLogger(CeremonyState.class.getName()); + /** * Constructor. * @@ -20,7 +25,7 @@ public CeremonyState(ServerGameLogic logic) { */ @Override public void enter() { - // ToDo: Close server. + LOGGER.log(System.Logger.Level.DEBUG, "Entered CeremonyState state."); } /** 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 a95ebdb7..cb2859f4 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 @@ -1,14 +1,32 @@ package pp.mdga.server.automaton; +import pp.mdga.message.client.AnimationEndMessage; import pp.mdga.message.client.DisconnectedMessage; import pp.mdga.message.client.LeaveGameMessage; +import pp.mdga.message.client.RequestDieMessage; import pp.mdga.message.server.PauseGameMessage; +import pp.mdga.server.automaton.game.AnimationState; +import pp.mdga.server.automaton.game.DetermineStartPlayerState; import pp.mdga.server.ServerGameLogic; /** - * + * This class represents the game state of this application. + * In Addition, it will be used as a state machine for the game process. */ public class GameState extends ServerState { + /** + * Create LobbyState constants. + */ + private static final System.Logger LOGGER = System.getLogger(GameState.class.getName()); + + /** + * Create GameState states. + */ + private GameAutomatonState currentState; + private final GameAutomatonState determineStartPlayerState; + private final GameAutomatonState animationState; + private final GameAutomatonState turnState; + /** * Constructor. * @@ -16,6 +34,10 @@ public class GameState extends ServerState { */ public GameState(ServerGameLogic logic) { super(logic); + this.determineStartPlayerState = new DetermineStartPlayerState(this, logic); + this.animationState = new AnimationState(this, logic); + this.turnState = new TurnState(this, logic); + this.setCurrentState(this.determineStartPlayerState); } /** @@ -23,7 +45,7 @@ public GameState(ServerGameLogic logic) { */ @Override public void enter() { - + LOGGER.log(System.Logger.Level.DEBUG, "Entered GameState state."); } /** @@ -35,6 +57,8 @@ public void exit() { } /** + * This method will be called whenever the server received a DisconnectedMessage 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 Disconnected object. * @param from as the client id of the player as an Integer. @@ -46,6 +70,8 @@ public void received(DisconnectedMessage msg, int from) { } /** + * This method will be called whenever the server received an LeaveGameMessage 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 LeaveGame object. * @param from as the client id of the player as an Integer. @@ -57,4 +83,78 @@ public void received(LeaveGameMessage msg, int from) { this.logic.setCurrentState(this.logic.getCeremonyState()); } } + + /** + * This method will be called whenever the server received a RequestDieMessage 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 RequestDieMessage object. + * @param from as the client id of the player as an Integer. + */ + @Override + public void received(RequestDieMessage msg, int from) { + this.currentState.received(msg, from); + } + + /** + * This method will be called whenever the server received an 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 used to return currentState attribute of GameState class. + * + * @return currentState as a GameAutomatonState object. + */ + public GameAutomatonState getCurrentState() { + return this.currentState; + } + + /** + * This method will be used to return determineStartPlayerState attribute of GameState class. + * + * @return determineStartPlayerState as a GameAutomatonState object. + */ + public GameAutomatonState getDetermineStartPlayerState() { + return this.determineStartPlayerState; + } + + /** + * This method will be used to return animationState attribute of GameState class. + * + * @return animationState as a GameAutomatonState object. + */ + public GameAutomatonState getAnimationState() { + return this.animationState; + } + + /** + * This method will be used to return turnState attribute of GameState class. + * + * @return turnState as a GameAutomatonState object. + */ + public GameAutomatonState getTurnState() { + return this.turnState; + } + + /** + * This method will be used to set currentState attribute of GameState class to the given state parameter. + * In Addition, the currentState will be exited, changed and entered. + * + * @param state as the new currentState attribute as a GameAutomatonState object. + */ + public void setCurrentState(GameAutomatonState state) { + if (this.currentState != null) { + this.currentState.exit(); + } + this.currentState = state; + this.currentState.enter(); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java index 59dfb299..420269d1 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java @@ -9,6 +9,11 @@ * */ public class InterruptState extends ServerState { + /** + * Create LobbyState constants. + */ + private static final System.Logger LOGGER = System.getLogger(InterruptState.class.getName()); + /** * Attributes. */ @@ -28,7 +33,7 @@ public InterruptState(ServerGameLogic logic) { */ @Override public void enter() { - // Create timer and connect signal. + LOGGER.log(System.Logger.Level.DEBUG, "Entered InterruptState state."); } /** diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/LobbyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/LobbyState.java index cbc2af1b..f47d8fe6 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/LobbyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/LobbyState.java @@ -13,6 +13,11 @@ * It will handle all join and disconnect messages, as well the selection of the color of the player. */ public class LobbyState extends ServerState { + /** + * Create LobbyState constants. + */ + private static final System.Logger LOGGER = System.getLogger(ServerState.class.getName()); + /** * Constructs a server state of the specified game logic. * @@ -27,7 +32,7 @@ public LobbyState(ServerGameLogic logic) { */ @Override public void enter() { - + LOGGER.log(System.Logger.Level.DEBUG, "Entered LobbyState state."); } /** @@ -39,17 +44,24 @@ public void exit() { } /** + * This method will be called whenever the server received a JoinedLobbyMessage message. + * It will also get the client id of the player who send this messag + * * @param msg as the message which was sent by the player as a JoinedLobbyMessage object. * @param from as the client id of the player as an Integer. */ @Override public void received(JoinedLobbyMessage msg, int from) { Player player = new Player(msg.getName()); + player.setColor(Color.getColorByIndex(this.logic.getGame().getPlayers().size())); this.logic.getGame().addPlayer(from, player); this.logic.getServerSender().broadcast(new LobbyPlayerJoinedMessage(from, player)); } /** + * This method will be called whenever the server received a SelectTSKMessage 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 SelectTSK object. * @param from as the client id of the player as an Integer. */ @@ -65,6 +77,9 @@ public void received(SelectTSKMessage msg, int from) { } /** + * This method will be called whenever the server received a DeselectTSKMessage 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 DeselectTSK object. * @param from as the client id of the player as an Integer. */ @@ -75,6 +90,9 @@ public void received(DeselectTSKMessage msg, int from) { } /** + * This method will be called whenever the server received a LobbyReadyMessage 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 LobbyReady object. * @param from as the client id of the player as an Integer. */ @@ -92,6 +110,9 @@ public void received(LobbyReadyMessage msg, int from) { } /** + * This method will be called whenever the server received a LobbyNotReadyMessage 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 LobbyNotReady object. * @param from as the client id of the player as an Integer. */ @@ -103,6 +124,8 @@ public void received(LobbyNotReadyMessage msg, int from) { } /** + * This method will be called whenever the server received an LeaveGameMessage 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 LeaveGameMessage object. * @param from as the client id of the player as an Integer. @@ -115,6 +138,9 @@ public void received(LeaveGameMessage msg, int from) { } /** + * This method will be called whenever the server received a StartGame 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 ForceStartGame object. * @param from as the client id of the player as an Integer. */ From 8369797120ea3b0666cd94c030da104a8e0e8da5 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 1 Dec 2024 20:41:30 +0100 Subject: [PATCH 3/9] added JavaDocs for the 'InterruptState' classe --- .../main/java/pp/mdga/server/automaton/InterruptState.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java index 420269d1..1a3ed72d 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/InterruptState.java @@ -44,6 +44,13 @@ public void exit() { } + /** + * This method will be called whenever the server received a ForceContinueGameMessage 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 ForceContinueGameMessage object. + * @param from as the client id of the player as an Integer. + */ @Override public void received(ForceContinueGameMessage msg, int from) { this.logic.getServerSender().broadcast(new ResumeGameMessage()); From c3fdcf4dc75bcdd7a859ef3f5101262ec999ee98 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 1 Dec 2024 21:01:37 +0100 Subject: [PATCH 4/9] added the states of the server automaton for testing purposes --- .../turnState/PlayPowerCardState.java | 6 -- .../server/DetermineStartPlayerState.java | 9 --- .../pp/mdga/server/FirstRollStateState.java | 7 -- .../java/pp/mdga/server/MovePieceState.java | 7 -- .../java/pp/mdga/server/NoPieceState.java | 7 -- .../main/java/pp/mdga/server/NoTurnState.java | 7 -- .../java/pp/mdga/server/PowerCardState.java | 7 -- .../java/pp/mdga/server/RollDiceState.java | 7 -- .../java/pp/mdga/server/SecondRollState.java | 7 -- .../java/pp/mdga/server/SelectPieceState.java | 7 -- .../java/pp/mdga/server/StartPieceState.java | 7 -- .../java/pp/mdga/server/ThirdRollState.java | 7 -- .../main/java/pp/mdga/server/TurnState.java | 9 --- .../pp/mdga/server/WaitingPieceState.java | 7 -- .../pp/mdga/server/automaton/GameState.java | 2 + .../server/automaton/game/AnimationState.java | 45 ++++++++++++ .../game/DetermineStartPlayerState.java | 69 +++++++++++++++++++ .../automaton/game/GameAutomatonState.java | 26 +++++++ .../mdga/server/automaton/game/TurnState.java | 26 +++++++ .../game/turn}/ChoosePieceState.java | 5 +- .../automaton/game/turn/MovePieceState.java | 10 +++ .../automaton/game/turn/PowerCardState.java | 10 +++ .../automaton/game/turn/RollDiceState.java | 10 +++ .../game/turn/choosepiece/NoPieceState.java | 10 +++ .../game/turn/choosepiece/NoTurnState.java | 10 +++ .../turn/choosepiece/SelectPieceState.java | 10 +++ .../turn/choosepiece/StartPieceState.java | 10 +++ .../turn/choosepiece/WaitingPieceState.java | 10 +++ .../turn/rolldice/FirstRollStateState.java | 10 +++ .../game/turn/rolldice/SecondRollState.java | 10 +++ .../game/turn/rolldice/ThirdRollState.java | 10 +++ 31 files changed, 282 insertions(+), 102 deletions(-) delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/DetermineStartPlayerState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/FirstRollStateState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/MovePieceState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/NoPieceState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/NoTurnState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/PowerCardState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/RollDiceState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/SecondRollState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/SelectPieceState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/StartPieceState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/ThirdRollState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/TurnState.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/WaitingPieceState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/AnimationState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/DetermineStartPlayerState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/TurnState.java rename Projekte/mdga/model/src/main/java/pp/mdga/server/{ => automaton/game/turn}/ChoosePieceState.java (50%) create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/MovePieceState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PowerCardState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/RollDiceState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/SecondRollState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/ThirdRollState.java diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PlayPowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PlayPowerCardState.java index 424cfc0c..b3f66cbd 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PlayPowerCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PlayPowerCardState.java @@ -3,15 +3,9 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; import pp.mdga.client.gameState.TurnState; -import pp.mdga.game.BonusCard; -import pp.mdga.game.Piece; -import pp.mdga.game.ShieldState; import pp.mdga.message.client.AnimationEndMessage; import pp.mdga.message.server.PlayCardMessage; import pp.mdga.notification.PlayCardNotification; -import pp.mdga.notification.ShieldActiveNotification; -import pp.mdga.notification.ShieldSuppressedNotification; -import pp.mdga.notification.SwapPieceNotification; public class PlayPowerCardState extends TurnStates { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/DetermineStartPlayerState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/DetermineStartPlayerState.java deleted file mode 100644 index 9f041111..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/DetermineStartPlayerState.java +++ /dev/null @@ -1,9 +0,0 @@ -package pp.mdga.server; - -import pp.mdga.server.automaton.GameState; - -public class DetermineStartPlayerState extends GameState { - public DetermineStartPlayerState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/FirstRollStateState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/FirstRollStateState.java deleted file mode 100644 index b8d91c26..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/FirstRollStateState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class FirstRollStateState extends RollDiceState { - public FirstRollStateState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/MovePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/MovePieceState.java deleted file mode 100644 index 27aac8fd..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/MovePieceState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class MovePieceState extends TurnState { - public MovePieceState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/NoPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/NoPieceState.java deleted file mode 100644 index a4120ecb..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/NoPieceState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class NoPieceState extends ChoosePieceState { - public NoPieceState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/NoTurnState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/NoTurnState.java deleted file mode 100644 index d96a3e78..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/NoTurnState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class NoTurnState extends ChoosePieceState { - public NoTurnState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/PowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/PowerCardState.java deleted file mode 100644 index d5db6a11..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/PowerCardState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class PowerCardState extends TurnState { - public PowerCardState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/RollDiceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/RollDiceState.java deleted file mode 100644 index cf1edf5c..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/RollDiceState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class RollDiceState extends TurnState { - public RollDiceState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/SecondRollState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/SecondRollState.java deleted file mode 100644 index f612cd2c..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/SecondRollState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class SecondRollState extends RollDiceState { - public SecondRollState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/SelectPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/SelectPieceState.java deleted file mode 100644 index 37a0c8f9..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/SelectPieceState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class SelectPieceState extends ChoosePieceState { - public SelectPieceState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/StartPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/StartPieceState.java deleted file mode 100644 index fff134ce..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/StartPieceState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class StartPieceState extends ChoosePieceState { - public StartPieceState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/ThirdRollState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/ThirdRollState.java deleted file mode 100644 index d5607225..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/ThirdRollState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class ThirdRollState extends RollDiceState { - public ThirdRollState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/TurnState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/TurnState.java deleted file mode 100644 index cbf0f999..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/TurnState.java +++ /dev/null @@ -1,9 +0,0 @@ -package pp.mdga.server; - -import pp.mdga.server.automaton.GameState; - -public class TurnState extends GameState { - public TurnState(ServerGameLogic logic) { - super(logic); - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/WaitingPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/WaitingPieceState.java deleted file mode 100644 index 64095bf1..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/WaitingPieceState.java +++ /dev/null @@ -1,7 +0,0 @@ -package pp.mdga.server; - -public class WaitingPieceState extends ChoosePieceState { - public WaitingPieceState(ServerGameLogic logic) { - super(logic); - } -} 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 cb2859f4..5d0830f4 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 @@ -8,6 +8,8 @@ import pp.mdga.server.automaton.game.AnimationState; import pp.mdga.server.automaton.game.DetermineStartPlayerState; import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.GameAutomatonState; +import pp.mdga.server.automaton.game.TurnState; /** * This class represents the game state of this application. 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 new file mode 100644 index 00000000..2a3db194 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/AnimationState.java @@ -0,0 +1,45 @@ +package pp.mdga.server.automaton.game; + +import pp.mdga.message.client.AnimationEndMessage; +import pp.mdga.message.server.DiceNowMessage; +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.GameState; + +/** + * This class represents the animation state of the game state. + * + */ +public class AnimationState extends GameAutomatonState { + /** + * Constructs a server state of the specified game logic. + * + * @param gameAutomaton as the automaton of the game state as a GameState object. + * @param logic the game logic + */ + public AnimationState(GameState gameAutomaton, ServerGameLogic logic) { + super(gameAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } + + /** + * This method will be called whenever the server received an 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.logic.getServerSender().send(from, new DiceNowMessage()); + this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState()); + } +} 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 new file mode 100644 index 00000000..c72fdfb7 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/DetermineStartPlayerState.java @@ -0,0 +1,69 @@ +package pp.mdga.server.automaton.game; + +import pp.mdga.game.Player; +import pp.mdga.message.client.RequestDieMessage; +import pp.mdga.message.server.DieMessage; +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.GameState; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class DetermineStartPlayerState extends GameAutomatonState { + /** + * Create DetermineStartPlayerState attributes. + */ + private Map diceResults = new HashMap<>(); + + /** + * Constructs a server state of the specified game logic. + * + * @param gameAutomaton as the automaton of the game state as a GameState object. + * @param logic the game logic + */ + public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic) { + super(gameAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } + + /** + * This method will be called whenever the server received a RequestDieMessage 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 RequestDieMessage object. + * @param from as the client id of the player as an Integer. + */ + @Override + public void received(RequestDieMessage msg, int from) { + int roll = this.logic.getGame().getDie().shuffle(); + this.diceResults.put(this.logic.getGame().getPlayerById(from), roll); + if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) { + Map frequencyMap = diceResults.values().stream() + .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + Map.Entry result = frequencyMap.entrySet().stream() + .max(Map.Entry.comparingByKey()) + .orElseThrow(() -> new IllegalStateException("Die Map ist leer")); + } + this.logic.getServerSender().send(from, new DieMessage(roll)); + } + + /** + * This method will be used to return diceResults attribute of DetermineStartPlayerState class. + * + * @return diceResults as a Map combing Player objects and Integers. + */ + public Map getDiceResults() { + return this.diceResults; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java new file mode 100644 index 00000000..791a8ffb --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java @@ -0,0 +1,26 @@ +package pp.mdga.server.automaton.game; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.GameState; +import pp.mdga.server.automaton.ServerState; + +/** + * This abstract class represents the game automaton state of the game state automaton. + */ +public abstract class GameAutomatonState extends ServerState { + /** + * Create GameAutomatonState attributes. + */ + protected final GameState gameAutomaton; + + /** + * Constructs a server state of the specified game logic. + * + * @param gameAutomaton as the automaton of the game state as a GameState object. + * @param logic the game logic + */ + public GameAutomatonState(GameState gameAutomaton, ServerGameLogic logic) { + super(logic); + this.gameAutomaton = gameAutomaton; + } +} 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 new file mode 100644 index 00000000..ecca1cb8 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/TurnState.java @@ -0,0 +1,26 @@ +package pp.mdga.server.automaton.game; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.GameState; + +public class TurnState extends GameAutomatonState { + /** + * Constructs a server state of the specified game logic. + * + * @param gameAutomaton as the automaton of the game state as a GameState object. + * @param logic the game logic + */ + public TurnState(GameState gameAutomaton, ServerGameLogic logic) { + super(gameAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/ChoosePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java similarity index 50% rename from Projekte/mdga/model/src/main/java/pp/mdga/server/ChoosePieceState.java rename to Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java index beb19efa..e51a45b4 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/ChoosePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java @@ -1,4 +1,7 @@ -package pp.mdga.server; +package pp.mdga.server.automaton.game.turn; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.TurnState; public class ChoosePieceState extends TurnState { public ChoosePieceState(ServerGameLogic logic) { 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 new file mode 100644 index 00000000..234e9fb4 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/MovePieceState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.TurnState; + +public class MovePieceState extends TurnState { + public MovePieceState(ServerGameLogic logic) { + super(logic); + } +} 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 new file mode 100644 index 00000000..5e6ad32d --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PowerCardState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.TurnState; + +public class PowerCardState extends TurnState { + public PowerCardState(ServerGameLogic logic) { + super(logic); + } +} 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 new file mode 100644 index 00000000..c8fe266d --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/RollDiceState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.TurnState; + +public class RollDiceState extends TurnState { + public RollDiceState(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java new file mode 100644 index 00000000..236fea5e --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.choosepiece; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.ChoosePieceState; + +public class NoPieceState extends ChoosePieceState { + public NoPieceState(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java new file mode 100644 index 00000000..fc630dbf --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.choosepiece; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.ChoosePieceState; + +public class NoTurnState extends ChoosePieceState { + public NoTurnState(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java new file mode 100644 index 00000000..9c3d0c90 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.choosepiece; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.ChoosePieceState; + +public class SelectPieceState extends ChoosePieceState { + public SelectPieceState(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java new file mode 100644 index 00000000..18e64f22 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.choosepiece; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.ChoosePieceState; + +public class StartPieceState extends ChoosePieceState { + public StartPieceState(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java new file mode 100644 index 00000000..d0ebdfd8 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.choosepiece; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.ChoosePieceState; + +public class WaitingPieceState extends ChoosePieceState { + public WaitingPieceState(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java new file mode 100644 index 00000000..dc1840cd --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.rolldice; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.RollDiceState; + +public class FirstRollStateState extends RollDiceState { + public FirstRollStateState(ServerGameLogic logic) { + super(logic); + } +} 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 new file mode 100644 index 00000000..35af3cd8 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/SecondRollState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.rolldice; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.RollDiceState; + +public class SecondRollState extends RollDiceState { + public SecondRollState(ServerGameLogic logic) { + super(logic); + } +} 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 new file mode 100644 index 00000000..a30826c6 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/ThirdRollState.java @@ -0,0 +1,10 @@ +package pp.mdga.server.automaton.game.turn.rolldice; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.turn.RollDiceState; + +public class ThirdRollState extends RollDiceState { + public ThirdRollState(ServerGameLogic logic) { + super(logic); + } +} From 95a1f8d858fae30e6ab1dbdcedabbe3abcd7e657 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 1 Dec 2024 21:05:22 +0100 Subject: [PATCH 5/9] removed all inheritance of the automaton for testing purposes --- .../mdga/server/automaton/game/turn/ChoosePieceState.java | 5 +---- .../pp/mdga/server/automaton/game/turn/MovePieceState.java | 6 ++---- .../pp/mdga/server/automaton/game/turn/PowerCardState.java | 5 +---- .../pp/mdga/server/automaton/game/turn/RollDiceState.java | 5 +---- .../automaton/game/turn/choosepiece/NoPieceState.java | 5 +---- .../server/automaton/game/turn/choosepiece/NoTurnState.java | 5 +---- .../automaton/game/turn/choosepiece/SelectPieceState.java | 6 ++---- .../automaton/game/turn/choosepiece/StartPieceState.java | 5 +---- .../automaton/game/turn/choosepiece/WaitingPieceState.java | 5 +---- .../automaton/game/turn/rolldice/FirstRollStateState.java | 5 +---- .../automaton/game/turn/rolldice/SecondRollState.java | 5 +---- .../server/automaton/game/turn/rolldice/ThirdRollState.java | 5 +---- 12 files changed, 14 insertions(+), 48 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java index e51a45b4..6fe8457e 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class ChoosePieceState extends TurnState { - public ChoosePieceState(ServerGameLogic logic) { - super(logic); - } +public class ChoosePieceState { } 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 234e9fb4..31c75346 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 @@ -3,8 +3,6 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class MovePieceState extends TurnState { - public MovePieceState(ServerGameLogic logic) { - super(logic); - } +public class MovePieceState { + } 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 5e6ad32d..3e18ad69 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 @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class PowerCardState extends TurnState { - public PowerCardState(ServerGameLogic logic) { - super(logic); - } +public class PowerCardState { } 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 c8fe266d..4d69301d 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 @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class RollDiceState extends TurnState { - public RollDiceState(ServerGameLogic logic) { - super(logic); - } +public class RollDiceState { } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java index 236fea5e..57c027f0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoPieceState.java @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.ChoosePieceState; -public class NoPieceState extends ChoosePieceState { - public NoPieceState(ServerGameLogic logic) { - super(logic); - } +public class NoPieceState { } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java index fc630dbf..a9a99841 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/NoTurnState.java @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.ChoosePieceState; -public class NoTurnState extends ChoosePieceState { - public NoTurnState(ServerGameLogic logic) { - super(logic); - } +public class NoTurnState { } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java index 9c3d0c90..dc668f22 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java @@ -3,8 +3,6 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.ChoosePieceState; -public class SelectPieceState extends ChoosePieceState { - public SelectPieceState(ServerGameLogic logic) { - super(logic); - } +public class SelectPieceState { + } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java index 18e64f22..df3771c2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/StartPieceState.java @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.ChoosePieceState; -public class StartPieceState extends ChoosePieceState { - public StartPieceState(ServerGameLogic logic) { - super(logic); - } +public class StartPieceState { } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java index d0ebdfd8..0ee99927 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/WaitingPieceState.java @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.ChoosePieceState; -public class WaitingPieceState extends ChoosePieceState { - public WaitingPieceState(ServerGameLogic logic) { - super(logic); - } +public class WaitingPieceState { } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java index dc1840cd..f3e34bf9 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/FirstRollStateState.java @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.RollDiceState; -public class FirstRollStateState extends RollDiceState { - public FirstRollStateState(ServerGameLogic logic) { - super(logic); - } +public class FirstRollStateState { } 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 35af3cd8..095872b8 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 @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.RollDiceState; -public class SecondRollState extends RollDiceState { - public SecondRollState(ServerGameLogic logic) { - super(logic); - } +public class SecondRollState { } 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 a30826c6..7be9dced 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 @@ -3,8 +3,5 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.turn.RollDiceState; -public class ThirdRollState extends RollDiceState { - public ThirdRollState(ServerGameLogic logic) { - super(logic); - } +public class ThirdRollState { } From 71d5701cc70aafec315c6ebd61d3b113dbc73a0c Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 1 Dec 2024 21:44:35 +0100 Subject: [PATCH 6/9] added javadoc for the classes in the notification package --- .../java/pp/mdga/client/gui/GuiHandler.java | 5 ++-- .../notification/AcquireCardNotification.java | 14 ++++++++-- .../ActivePlayerNotification.java | 8 ++++-- .../notification/CeremonyNotification.java | 7 +++-- .../notification/DiceNowNotification.java | 1 - .../mdga/notification/DicingNotification.java | 10 +++++-- .../notification/DrawCardNotification.java | 14 +++++++--- .../mdga/notification/GameNotification.java | 2 +- .../notification/HomeMoveNotification.java | 12 ++++++-- .../notification/InterruptNotification.java | 6 ++-- .../notification/LobbyDialogNotification.java | 7 +---- .../notification/MovePieceNotification.java | 3 -- .../notification/NoShieldNotification.java | 6 ++-- .../pp/mdga/notification/Notification.java | 3 ++ .../notification/PlayCardNotification.java | 15 ++++++++-- .../PlayerInGameNotification.java | 28 +++++++++++++++---- .../mdga/notification/ResumeNotification.java | 8 ++++-- .../notification/RollDiceNotification.java | 26 +++++++++++++---- .../SelectableCardsNotification.java | 6 ++-- .../SelectableMoveNotification.java | 15 +++++----- .../SelectableSwapNotification.java | 3 +- .../ShieldActiveNotification.java | 8 ++++-- .../ShieldSuppressedNotification.java | 6 ++-- .../notification/StartDialogNotification.java | 7 +---- .../notification/SwapPieceNotification.java | 17 ++++++++--- .../notification/ThrowPieceNotification.java | 18 ++++++++---- .../notification/TskSelectNotification.java | 19 +++++++++++-- .../notification/TskUnselectNotification.java | 17 +++++++---- .../notification/WaitMoveNotification.java | 10 +++++-- 29 files changed, 207 insertions(+), 94 deletions(-) diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java index 8393653f..153221d9 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java @@ -7,6 +7,7 @@ import com.jme3.texture.Texture2D; import pp.mdga.client.MdgaApp; import pp.mdga.game.Color; +import pp.mdga.game.BonusCard; import java.util.List; @@ -70,7 +71,7 @@ public void hideDice() { cardLayerHandler.hideDice(); } - public void addCard(pp.mdga.game.BonusCard card) { + public void addCard(BonusCard card) { cardLayerHandler.addCard(card); } @@ -78,7 +79,7 @@ public void clearSelectableCards() { cardLayerHandler.clearSelectableCards(); } - public void setSelectableCards(List select) { + public void setSelectableCards(List select) { cardLayerHandler.setSelectableCards(select); } 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 5a4afff7..8d658084 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 @@ -7,13 +7,20 @@ /** * Notification that is sent when a card is acquired. */ -public class AcquireCardNotification extends Notification{ +public class AcquireCardNotification extends Notification { + /** + * The id of the card that was acquired. + */ + private final UUID cardId; - private UUID cardId; - private BonusCard bonusCard; + /** + * The bonus card that was acquired. + */ + private final BonusCard bonusCard; /** * Constructor. + * * @param cardId The id of the card that was acquired. */ public AcquireCardNotification(BonusCard bonusCard, UUID cardId) { @@ -23,6 +30,7 @@ public AcquireCardNotification(BonusCard bonusCard, UUID cardId) { /** * Get the id of the card that was acquired. + * * @return The id of the card that was acquired. */ public UUID getCardId() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java index 4efdb343..171be0c2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java @@ -6,12 +6,16 @@ * Notification that the active player has changed */ public class ActivePlayerNotification extends Notification { - /** * The color of the active player */ - private Color color; + private final Color color; + /** + * Constructor. + * + * @param color the color of the active player + */ public ActivePlayerNotification(Color color) { this.color = color; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java index f7210f69..6865f4ca 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java @@ -7,7 +7,7 @@ /** * Class CeremonyNotification * Represents a notification for a ceremony in the game. - * + *

* Index mapping: * index = 0 ==> winner * index = 1 ==> 2nd @@ -16,6 +16,9 @@ * index = 4 ==> total */ public class CeremonyNotification extends Notification { + /** + * Attributes. + */ private ArrayList colors; private ArrayList names; private ArrayList piecesThrown; @@ -40,8 +43,6 @@ public CeremonyNotification() { this.bonusNodes = new ArrayList<>(); } - // Getters and Setters - /** * @return the list of colors */ diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java index 68064cfe..8780f636 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java @@ -4,7 +4,6 @@ * Notification that the dice is now. */ public class DiceNowNotification extends Notification { - /** * Constructor. */ diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java index 4e9f3145..b2254605 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java @@ -5,12 +5,15 @@ /** * Notification that is sent when a player has diced. */ -public class DicingNotification extends Notification{ - - private Color color; +public class DicingNotification extends Notification { + /** + * The color of the player that diced. + */ + private final Color color; /** * Constructor. + * * @param color The color of the player that diced. */ public DicingNotification(Color color) { @@ -19,6 +22,7 @@ public DicingNotification(Color color) { /** * Get the color of the player that diced. + * * @return The color of the player that diced. */ public Color getColor() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java index 5114fd15..3540d810 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java @@ -6,14 +6,20 @@ /** * Notification that a card has been drawn */ -public class DrawCardNotification extends Notification { +public class DrawCardNotification extends Notification { + /** + * The color of the player who drew the card + */ + private final Color color; - private Color color; - private BonusCard card; + /** + * The card that was drawn + */ + private final BonusCard card; /** * @param color the color of the player who drew the card - * @param card the card that was drawn + * @param card the card that was drawn */ public DrawCardNotification(Color color, BonusCard card) { this.color = color; 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 d1864bbd..91fc5aea 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 @@ -3,7 +3,7 @@ /** * GameNotification class */ -public class GameNotification extends Notification{ +public class GameNotification extends Notification { /** * Constructor */ diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java index ffa7d2e1..1b222e62 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java @@ -6,14 +6,20 @@ * Notification that a piece has moved to a home. */ public class HomeMoveNotification extends Notification { + /** + * The unique identifier of the piece. + */ + private final UUID pieceId; - private UUID pieceId; - private int homeIndex; + /** + * The index of the home position. + */ + private final int homeIndex; /** * Constructor. * - * @param pieceId the piece id + * @param pieceId the piece id * @param homeIndex the home index */ public HomeMoveNotification(UUID pieceId, int homeIndex) { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java index bb8fb784..ef1543b0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java @@ -6,8 +6,10 @@ * Notification that a card has been drawn */ public class InterruptNotification extends Notification { - - private Color color; + /** + * The color of the player who disconnected + */ + private final Color color; /** * @param color the color of the player who disconnected diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java index dcea5094..604af4f8 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java @@ -3,10 +3,5 @@ /** * Notification that a dialog has been started */ -public class LobbyDialogNotification extends Notification{ - /** - * Constructor - */ - public LobbyDialogNotification() { - } +public class LobbyDialogNotification extends Notification { } 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 610a9182..455c6baa 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 @@ -1,14 +1,11 @@ package pp.mdga.notification; -import pp.mdga.game.Color; - import java.util.UUID; /** * Notification that a piece has been moved. */ public class MovePieceNotification extends Notification { - /** * The unique identifier of the piece being moved. */ diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/NoShieldNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/NoShieldNotification.java index e17d0b33..8c7fa970 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/NoShieldNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/NoShieldNotification.java @@ -6,8 +6,10 @@ * Notification that a piece has no shield. */ public class NoShieldNotification extends Notification{ - - private UUID pieceId; + /** + * The id of the piece that has no shield. + */ + private final UUID pieceId; /** * Constructor. diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java index 3f8be5da..ee41c6dd 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java @@ -1,4 +1,7 @@ package pp.mdga.notification; +/** + * Represents a notification that can be sent to a player. + */ public abstract class Notification { } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java index dd9cf9d4..9d78eac2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java @@ -7,14 +7,21 @@ * Notification that a card has been played. */ public class PlayCardNotification extends Notification { + /** + * The color of the player that played the card. + */ + private final Color color; - private Color color; - private BonusCard card; + /** + * The card that was played. + */ + private final BonusCard card; /** * Constructor. + * * @param color the color of the player that played the card. - * @param card the card that was played. + * @param card the card that was played. */ public PlayCardNotification(Color color, BonusCard card) { this.color = color; @@ -23,6 +30,7 @@ public PlayCardNotification(Color color, BonusCard card) { /** * Get the color of the player that played the card. + * * @return the color of the player that played the card. */ public Color getColor() { @@ -31,6 +39,7 @@ public Color getColor() { /** * Get the card that was played. + * * @return the card that was played. */ public BonusCard getCard() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java index 57552a0c..db660d28 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java @@ -9,17 +9,28 @@ * Notification that a player is in the game. */ public class PlayerInGameNotification extends Notification { + /** + * The color of the player that is in the game. + */ + private final Color color; - private Color color; - private String name; - private List piecesList; + /** + * The name of the player that is in the game. + */ + private final String name; + + /** + * The list of piece IDs associated with the player. + */ + private final List piecesList; /** * Constructor. + * * @param color the color of the player that is in the game. - * @param name the name of the player that is in the game. + * @param name the name of the player that is in the game. */ - public PlayerInGameNotification(Color color, List piecesList, String name) { + public PlayerInGameNotification(Color color, List piecesList, String name) { this.color = color; this.name = name; this.piecesList = piecesList; @@ -27,6 +38,7 @@ public PlayerInGameNotification(Color color, List piecesList, String name /** * Get the color of the player that is in the game. + * * @return the color of the player that is in the game. */ public Color getColor() { @@ -35,12 +47,18 @@ public Color getColor() { /** * Get the name of the player that is in the game. + * * @return the name of the player that is in the game. */ public String getName() { return name; } + /** + * Get the list of piece IDs associated with the player. + * + * @return the list of piece IDs associated with the player. + */ public List getPiecesList() { return piecesList; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java index 5ef4bd34..f15cacd7 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java @@ -6,11 +6,14 @@ * Notification that a player is in the game. */ public class ResumeNotification extends Notification { - - private Color color; + /** + * The color of the player that is in the game. + */ + private final Color color; /** * Constructor. + * * @param color the color of the player that is in the game. */ public ResumeNotification(Color color) { @@ -19,6 +22,7 @@ public ResumeNotification(Color color) { /** * Get the color of the player that is in the game. + * * @return the color of the player that is in the game. */ public Color getColor() { 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 3f778d3f..7c233a36 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 @@ -5,16 +5,27 @@ /** * Notification that a die has been rolled. */ -public class RollDiceNotification extends Notification{ +public class RollDiceNotification extends Notification { + /** + * The color of the player that rolled the die. + */ + private final Color color; - private Color color; - private int eyes; - private int moveNumber; + /** + * The number of eyes that were rolled. + */ + private final int eyes; + + /** + * The number of the move that was made. + */ + private final int moveNumber; /** * Constructor. - * @param color the color of the player that rolled the die. - * @param eyes the number of eyes that were rolled. + * + * @param color the color of the player that rolled the die. + * @param eyes the number of eyes that were rolled. * @param moveNumber the number of the move that was made. */ public RollDiceNotification(Color color, int eyes, int moveNumber) { @@ -25,6 +36,7 @@ public RollDiceNotification(Color color, int eyes, int moveNumber) { /** * Get the color of the player that rolled the die. + * * @return the color of the player that rolled the die. */ public Color getColor() { @@ -33,6 +45,7 @@ public Color getColor() { /** * Get the number of eyes that were rolled. + * * @return the number of eyes that were rolled. */ public int getEyes() { @@ -41,6 +54,7 @@ public int getEyes() { /** * Get the number of the move that was made. + * * @return the number of the move that was made. */ public int getMoveNumber() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java index 308edce2..efcbc37e 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java @@ -7,8 +7,10 @@ * Notification that contains a list of cards that the player can choose from. */ public class SelectableCardsNotification extends Notification { - - private List cards; + /** + * The list of cards that the player can choose from. + */ + private final List cards; /** * Constructor. diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java index cd7fe627..ce1ca590 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java @@ -6,8 +6,7 @@ /** * Notification for selecting pieces and their possible moves. */ -public class SelectableMoveNotification extends Notification{ - +public class SelectableMoveNotification extends Notification { /** * List of UUIDs representing the pieces that can be moved based on the dice roll. */ @@ -16,7 +15,7 @@ public class SelectableMoveNotification extends Notification{ /** * List of integers representing the target nodes the pieces can move to. */ - private final List moveIndexe; + private final List moveIndices; /** * List of booleans indicating whether the corresponding target nodes are in the home area. @@ -28,12 +27,12 @@ public class SelectableMoveNotification extends Notification{ * Constructs a notification for selectable piece moves. * * @param pieces the list of pieces that can be moved - * @param moveIndexe the list of target nodes for the moves + * @param moveIndices the list of target nodes for the moves * @param homeMoves the list indicating if the target nodes are in the home area */ - public SelectableMoveNotification(List pieces, List moveIndexe, List homeMoves) { + public SelectableMoveNotification(List pieces, List moveIndices, List homeMoves) { this.pieces = pieces; - this.moveIndexe = moveIndexe; + this.moveIndices = moveIndices; this.homeMoves = homeMoves; } @@ -51,8 +50,8 @@ public List getPieces() { * * @return a list of integers representing the target nodes */ - public List getMoveIndexe() { - return moveIndexe; + public List getMoveIndices() { + return moveIndices; } /** diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java index b7102bd7..cdd51780 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java @@ -6,8 +6,7 @@ /** * Notification for selecting pieces for swapcard. */ -public class SelectableSwapNotification extends Notification{ - +public class SelectableSwapNotification extends Notification { /** * List of UUIDs representing the player's own pieces available for selection. */ diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldActiveNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldActiveNotification.java index 0cb6c15b..7d17b8eb 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldActiveNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldActiveNotification.java @@ -5,9 +5,11 @@ /** * This class will be used to hold all ShieldActiveNotification relevant data. */ -public class ShieldActiveNotification extends Notification{ - - private UUID pieceId; +public class ShieldActiveNotification extends Notification { + /** + * The pieceId + */ + private final UUID pieceId; /** * This constructor is used to create a new ShieldActiveNotification diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldSuppressedNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldSuppressedNotification.java index ce7f7a8f..78d6b068 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldSuppressedNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ShieldSuppressedNotification.java @@ -6,8 +6,10 @@ * This class will be used to hold all ShieldSuppressedNotification relevant data. */ public class ShieldSuppressedNotification extends Notification { - - private UUID pieceId; + /** + * The pieceId + */ + private final UUID pieceId; /** * This constructor is used to create a new ShieldSuppressedNotification diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java index 3e72cc29..380246c0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java @@ -3,10 +3,5 @@ /** * Notification that a dialog has been started */ -public class StartDialogNotification extends Notification{ - /** - * Constructor - */ - public StartDialogNotification() { - } +public class StartDialogNotification extends Notification { } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java index c66597b0..c6095175 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java @@ -6,23 +6,31 @@ * Notification that two pieces have been swapped. */ public class SwapPieceNotification extends Notification { + /** + * The UUID of the first piece that has been swapped. + */ + private final UUID firstPiece; - private UUID firstPiece; - private UUID secondPiece; + /** + * The UUID of the second piece that has been swapped. + */ + private final UUID secondPiece; /** * Constructor. - * @param firstPiece the UUID of the first piece that has been swapped. + * + * @param firstPiece the UUID of the first piece that has been swapped. * @param secondPiece the UUID of the second piece that has been swapped. */ public SwapPieceNotification(UUID firstPiece, UUID secondPiece) { - assert(!firstPiece.equals(secondPiece)); + assert (!firstPiece.equals(secondPiece)); this.firstPiece = firstPiece; this.secondPiece = secondPiece; } /** * Get the UUID of the first piece that has been swapped. + * * @return the UUID of the first piece that has been swapped. */ public UUID getFirstPiece() { @@ -31,6 +39,7 @@ public UUID getFirstPiece() { /** * Get the UUID of the second piece that has been swapped. + * * @return the UUID of the second piece that has been swapped. */ public UUID getSecondPiece() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ThrowPieceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ThrowPieceNotification.java index c99b079e..9b0ddd28 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ThrowPieceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ThrowPieceNotification.java @@ -1,12 +1,15 @@ package pp.mdga.notification; -import pp.mdga.game.Color; - import java.util.UUID; -public class ThrowPieceNotification extends Notification{ - - private UUID pieceId; +/** + * Notification that is sent when a piece is thrown. + */ +public class ThrowPieceNotification extends Notification { + /** + * The id of the piece that was thrown. + */ + private final UUID pieceId; /** * This constructor is used to create a new ThrowPieceNotification @@ -15,6 +18,11 @@ public ThrowPieceNotification(UUID pieceId) { this.pieceId = pieceId; } + /** + * Get the id of the piece that was thrown. + * + * @return The id of the piece that was thrown. + */ public UUID getPieceId() { return pieceId; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskSelectNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskSelectNotification.java index bf339e0c..cebe8b58 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskSelectNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskSelectNotification.java @@ -5,16 +5,27 @@ /** * Class TskSelectNotification */ -public class TskSelectNotification extends Notification{ - +public class TskSelectNotification extends Notification { + /** + * The color of the player that is in the game. + */ private final Color color; + + /** + * The name of the player that is in the game. + */ private final String name; + + /** + * Indicates if the select notification affects the own user. + */ private final boolean isSelf; /** * Constructor. + * * @param color the color of the player that is in the game. - * @param name the name of the player that is in the game. + * @param name the name of the player that is in the game. */ public TskSelectNotification(Color color, String name, boolean isSelf) { this.color = color; @@ -24,6 +35,7 @@ public TskSelectNotification(Color color, String name, boolean isSelf) { /** * Get the color of the player that is in the game. + * * @return the color of the player that is in the game. */ public Color getColor() { @@ -32,6 +44,7 @@ public Color getColor() { /** * Get the name of the player that is in the game. + * * @return the name of the player that is in the game. */ public String getName() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java index 4a036d46..923eb7b1 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java @@ -2,20 +2,27 @@ import pp.mdga.game.Color; -public class TskUnselectNotification extends Notification{ - - private Color color; +/** + * Notification for unselecting a player + */ +public class TskUnselectNotification extends Notification { + /** + * The color of the player + */ + private final Color color; /** * Constructor - * @param color + * + * @param color the color of the player */ - public TskUnselectNotification(Color color){ + public TskUnselectNotification(Color color) { this.color = color; } /** * Get the color + * * @return color */ public Color getColor() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/WaitMoveNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/WaitMoveNotification.java index bb2e9e8a..9ebc9380 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/WaitMoveNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/WaitMoveNotification.java @@ -5,12 +5,15 @@ /** * Notification to inform the player that he has to wait for the other player to move. */ -public class WaitMoveNotification extends Notification{ - - private UUID pieceId; +public class WaitMoveNotification extends Notification { + /** + * The id of the piece that has to move. + */ + private final UUID pieceId; /** * Constructor. + * * @param pieceId the id of the piece that has to move. */ public WaitMoveNotification(UUID pieceId) { @@ -19,6 +22,7 @@ public WaitMoveNotification(UUID pieceId) { /** * Get the id of the piece that has to move. + * * @return the id of the piece that has to move. */ public UUID getPieceId() { From 977a7294ad12586571d47291df17903f7590cea3 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 1 Dec 2024 21:49:11 +0100 Subject: [PATCH 7/9] updated server state diagram and added missing classes --- .../java/pp/mdga/server/ServerGameLogic.java | 24 ++--- .../automaton/game/GameAutomatonState.java | 2 +- .../mdga/server/automaton/game/TurnState.java | 88 +++++++++++++++++++ .../automaton/game/turn/ChoosePieceState.java | 21 ++++- .../automaton/game/turn/MovePieceState.java | 21 ++++- .../game/turn/PlayPowerCardState.java | 26 ++++++ .../automaton/game/turn/PowerCardState.java | 21 ++++- .../automaton/game/turn/RollDiceState.java | 21 ++++- .../game/turn/TurnAutomatonState.java | 23 +++++ .../ChoosePieceAutomatonState.java | 22 +++++ .../turn/rolldice/RollDiceAutomatonState.java | 22 +++++ 11 files changed, 274 insertions(+), 17 deletions(-) create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PlayPowerCardState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/TurnAutomatonState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/ChoosePieceAutomatonState.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/RollDiceAutomatonState.java 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 c3d15ae9..9b2ed7e4 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 @@ -25,10 +25,10 @@ public class ServerGameLogic implements ClientInterpreter { * States */ private ServerState currentState; - private final ServerState lobbyState; - private final ServerState gameState; - private final ServerState interruptState; - private final ServerState ceremonyState; + private final LobbyState lobbyState; + private final GameState gameState; + private final InterruptState interruptState; + private final CeremonyState ceremonyState; /** * Constructor. @@ -167,36 +167,36 @@ public ServerState getCurrentState() { /** * This method will be used to return lobbyState attribute of ServerGameLogic class. * - * @return lobbyState as a ServerState object. + * @return lobbyState as a LobbyState object. */ - public ServerState getLobbyState() { + public LobbyState getLobbyState() { return this.lobbyState; } /** * This method will be used to return gameState attribute of ServerGameLogic class. * - * @return gameState as a ServerState object. + * @return gameState as a GameState object. */ - public ServerState getGameState() { + public GameState getGameState() { return this.gameState; } /** * This method will be used to return interruptState attribute of ServerGameLogic class. * - * @return interruptState as a ServerState object. + * @return interruptState as a InterruptState object. */ - public ServerState getInterruptState() { + public InterruptState getInterruptState() { return this.interruptState; } /** * This method will be used to return ceremonyState attribute of ServerGameLogic class. * - * @return ceremonyState as a ServerState object. + * @return ceremonyState as a CeremonyState object. */ - public ServerState getCeremonyState() { + public CeremonyState getCeremonyState() { return this.ceremonyState; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java index 791a8ffb..56eac48f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/GameAutomatonState.java @@ -17,7 +17,7 @@ public abstract class GameAutomatonState extends ServerState { * Constructs a server state of the specified game logic. * * @param gameAutomaton as the automaton of the game state as a GameState object. - * @param logic the game logic + * @param logic the game logic */ public GameAutomatonState(GameState gameAutomaton, ServerGameLogic logic) { super(logic); 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 ecca1cb8..7f5c58a5 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 @@ -2,8 +2,23 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.GameState; +import pp.mdga.server.automaton.game.turn.*; +/** + * This class represents the turn state of the server state automaton. + * It will also be used as the turn automaton. + */ public class TurnState extends GameAutomatonState { + /** + * Create TurnState states. + */ + private TurnAutomatonState currentState; + private final PowerCardState powerCardState; + private final PlayPowerCardState playPowerCardState; + private final RollDiceState rollDiceState; + private final ChoosePieceState choosePieceState; + private final MovePieceState movePieceState; + /** * Constructs a server state of the specified game logic. * @@ -12,6 +27,11 @@ public class TurnState extends GameAutomatonState { */ public TurnState(GameState gameAutomaton, ServerGameLogic logic) { super(gameAutomaton, logic); + this.powerCardState = new PowerCardState(this, logic); + this.playPowerCardState = new PlayPowerCardState(this, logic); + this.rollDiceState = new RollDiceState(this, logic); + this.choosePieceState = new ChoosePieceState(this, logic); + this.movePieceState = new MovePieceState(this, logic); } @Override @@ -23,4 +43,72 @@ public void enter() { public void exit() { } + + /** + * This method will be used to return currentState attribute of TurnState class. + * + * @return currentState as a TurnAutomatonState object. + */ + public TurnAutomatonState getCurrentState() { + return this.currentState; + } + + /** + * This method will be used to return powerCardState attribute of TurnState class. + * + * @return powerCardState as a PowerCardState object. + */ + public PowerCardState getPowerCardState() { + return this.powerCardState; + } + + /** + * This method will be used to return playPowerCardState attribute of TurnState class. + * + * @return playPowerState as a PlayPowerCardState object. + */ + public PlayPowerCardState getPlayPowerCardState() { + return this.playPowerCardState; + } + + /** + * This method will be used to return rollDiceState attribute of TurnState class. + * + * @return rollDiceState as a RollDiceState object. + */ + public RollDiceState getRollDiceState() { + return this.rollDiceState; + } + + /** + * This method will be used to return choosePieceState attribute of TurnState class. + * + * @return choosePieceState as a ChoosePieceState object. + */ + public ChoosePieceState getChoosePieceState() { + return this.choosePieceState; + } + + /** + * This method will be used to return movePieceState attribute of TurnState class. + * + * @return movePieceState as a MovePieceState object. + */ + public MovePieceState getMovePieceState() { + return this.movePieceState; + } + + /** + * This method will be used to set currentState attribute of TurnState class to the given state parameter. + * In Addition, the currentState will be exited, changed and entered. + * + * @param state as the new currentState attribute as a TurnAutomatonState object. + */ + public void setCurrentState(TurnAutomatonState state) { + if (this.currentState != null) { + this.currentState.exit(); + } + this.currentState = state; + this.currentState.enter(); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java index 6fe8457e..768360c3 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/ChoosePieceState.java @@ -3,5 +3,24 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class ChoosePieceState { +public class ChoosePieceState extends TurnAutomatonState { + /** + * Constructs a server state of the specified game logic. + * + * @param turnAutomaton as the automaton of the turn state as a GameState object. + * @param logic the game logic + */ + public ChoosePieceState(TurnState turnAutomaton, ServerGameLogic logic) { + super(turnAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } } 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 31c75346..cede3202 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 @@ -3,6 +3,25 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class MovePieceState { +public class MovePieceState extends TurnAutomatonState { + /** + * Constructs a server state of the specified game logic. + * + * @param turnAutomaton as the automaton of the turn state as a GameState object. + * @param logic the game logic + */ + public MovePieceState(TurnState turnAutomaton, ServerGameLogic logic) { + super(turnAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } } 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 new file mode 100644 index 00000000..b4b05a5d --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/PlayPowerCardState.java @@ -0,0 +1,26 @@ +package pp.mdga.server.automaton.game.turn; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.game.TurnState; + +public class PlayPowerCardState extends TurnAutomatonState { + /** + * Constructs a server state of the specified game logic. + * + * @param turnAutomaton as the automaton of the turn state as a GameState object. + * @param logic the game logic + */ + public PlayPowerCardState(TurnState turnAutomaton, ServerGameLogic logic) { + super(turnAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } +} 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 3e18ad69..19d9d5b3 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 @@ -3,5 +3,24 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class PowerCardState { +public class PowerCardState extends TurnAutomatonState { + /** + * Constructs a server state of the specified game logic. + * + * @param turnAutomaton as the automaton of the turn state as a GameState object. + * @param logic the game logic + */ + public PowerCardState(TurnState turnAutomaton, ServerGameLogic logic) { + super(turnAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } } 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 4d69301d..cf9648c2 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 @@ -3,5 +3,24 @@ import pp.mdga.server.ServerGameLogic; import pp.mdga.server.automaton.game.TurnState; -public class RollDiceState { +public class RollDiceState extends TurnAutomatonState { + /** + * Constructs a server state of the specified game logic. + * + * @param turnAutomaton as the automaton of the turn state as a GameState object. + * @param logic the game logic + */ + public RollDiceState(TurnState turnAutomaton, ServerGameLogic logic) { + super(turnAutomaton, logic); + } + + @Override + public void enter() { + + } + + @Override + public void exit() { + + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/TurnAutomatonState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/TurnAutomatonState.java new file mode 100644 index 00000000..db0b6989 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/TurnAutomatonState.java @@ -0,0 +1,23 @@ +package pp.mdga.server.automaton.game.turn; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.ServerState; +import pp.mdga.server.automaton.game.TurnState; + +public abstract class TurnAutomatonState extends ServerState { + /** + * Create TurnAutomatonState attributes. + */ + protected final TurnState turnAutomaton; + + /** + * Constructs a server state of the specified game logic. + * + * @param turnAutomaton as the automaton of the turn state as a GameState object. + * @param logic the game logic + */ + public TurnAutomatonState(TurnState turnAutomaton, ServerGameLogic logic) { + super(logic); + this.turnAutomaton = turnAutomaton; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/ChoosePieceAutomatonState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/ChoosePieceAutomatonState.java new file mode 100644 index 00000000..0f701179 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/ChoosePieceAutomatonState.java @@ -0,0 +1,22 @@ +package pp.mdga.server.automaton.game.turn.choosepiece; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.ServerState; +import pp.mdga.server.automaton.game.turn.ChoosePieceState; + +public abstract class ChoosePieceAutomatonState extends ServerState { + /** + * Create ChoosePieceAutomatonState attributes. + */ + protected final ChoosePieceState choosePieceAutomaton; + + /** + * Constructs a server state of the specified game logic. + * + * @param logic the game logic + */ + public ChoosePieceAutomatonState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic) { + super(logic); + this.choosePieceAutomaton = choosePieceAutomaton; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/RollDiceAutomatonState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/RollDiceAutomatonState.java new file mode 100644 index 00000000..ae31094f --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/rolldice/RollDiceAutomatonState.java @@ -0,0 +1,22 @@ +package pp.mdga.server.automaton.game.turn.rolldice; + +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.automaton.ServerState; +import pp.mdga.server.automaton.game.turn.RollDiceState; + +public abstract class RollDiceAutomatonState extends ServerState { + /** + * Create RollDiceAutomatonState attributes. + */ + protected final RollDiceState rollDiceAutomaton; + + /** + * Constructs a server state of the specified game logic. + * + * @param logic the game logic + */ + public RollDiceAutomatonState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) { + super(logic); + this.rollDiceAutomaton = rollDiceAutomaton; + } +} From 133f900ec7b73bcf8e54ef709dafa0987e3cfde7 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 21:50:28 +0100 Subject: [PATCH 8/9] added the server and network functionality for mdga and fixed the communication in the Lobby --- .../src/main/java/pp/mdga/client/MdgaApp.java | 37 +++++++- .../pp/mdga/client/ModelSynchronizer.java | 41 +++------ .../java/pp/mdga/client/NetworkSupport.java | 91 +++++++++++++++++++ .../mdga/client/NotificationSynchronizer.java | 11 +-- .../pp/mdga/client/button/LobbyButton.java | 1 - .../pp/mdga/client/dialog/HostDialog.java | 15 ++- .../pp/mdga/client/dialog/JoinDialog.java | 11 ++- .../pp/mdga/client/dialog/NetworkDialog.java | 73 +++++++++++++++ .../pp/mdga/client/server/MdgaServer.java | 11 ++- .../pp/mdga/client/server/UUIDSerializer.java | 26 ++++++ .../java/pp/mdga/client/view/MainView.java | 17 ++++ .../java/pp/mdga/client/ClientGameLogic.java | 17 +++- .../main/java/pp/mdga/client/ClientState.java | 2 +- .../java/pp/mdga/client/DialogsState.java | 11 ++- .../java/pp/mdga/client/ServerConnection.java | 9 ++ .../mdga/client/dialogState/LobbyState.java | 5 +- .../dialogState/NetworkDialogState.java | 7 +- .../client/dialogState/StartDialogState.java | 6 ++ .../src/main/java/pp/mdga/game/Player.java | 3 + .../src/main/java/pp/mdga/game/Statistic.java | 3 + .../mdga/message/client/StartGameMessage.java | 2 +- .../notification/LobbyReadyNotification.java | 43 +++++++++ 22 files changed, 383 insertions(+), 59 deletions(-) create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/NetworkSupport.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/server/UUIDSerializer.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/client/ServerConnection.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyReadyNotification.java diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java index f0d55121..ba967ba8 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java @@ -6,6 +6,10 @@ import pp.mdga.client.animation.AnimationHandler; import com.jme3.system.AppSettings; import pp.mdga.client.view.*; +import pp.mdga.message.server.ServerInterpreter; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * Main application class for the MdgaApp game. @@ -49,6 +53,18 @@ public class MdgaApp extends SimpleApplication { /** The ceremony view. */ private MdgaView ceremonyView; + /** The client game logic. */ + private final ClientGameLogic clientGameLogic; + + private ExecutorService executor; + + private ServerConnection networkConnection; + + private MdgaApp() { + networkConnection = new NetworkSupport(this); + this.clientGameLogic = new ClientGameLogic(networkConnection); + } + /** * Main entry point for the application. * Configures settings and starts the application. @@ -59,8 +75,8 @@ public static void main(String[] args) { AppSettings settings = new AppSettings(true); settings.setSamples(128); settings.setCenterWindow(true); - settings.setWidth(1920); - settings.setHeight(1080); + settings.setWidth(1080); + settings.setHeight(720); settings.setVSync(false); MdgaApp app = new MdgaApp(); @@ -219,5 +235,22 @@ public NotificationSynchronizer getNotificationSynchronizer() { public void setup() { } + + public ClientGameLogic getGameLogic() { + return clientGameLogic; + } + + + public ExecutorService getExecutor() { + if (this.executor == null) { + this.executor = Executors.newCachedThreadPool(); + } + + return this.executor; + } + + public ServerConnection getNetworkSupport() { + return networkConnection; + } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSynchronizer.java index 6049063f..950dfaa6 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSynchronizer.java @@ -1,6 +1,7 @@ package pp.mdga.client; import pp.mdga.client.acoustic.MdgaSound; +import pp.mdga.client.server.MdgaServer; import pp.mdga.client.view.CeremonyView; import pp.mdga.client.view.GameView; import pp.mdga.client.view.LobbyView; @@ -31,7 +32,7 @@ public class ModelSynchronizer { private int test = 0; public void animationEnd() { - + app.getGameLogic().selectAnimationEnd(); } public void selectSwap(UUID a, UUID b) { @@ -82,13 +83,14 @@ public void confirm() { GameView gameView = (GameView) app.getView(); if(a != null && b != null) { - //swap + selectPiece(a); + selectPiece(b); gameView.getBoardHandler().clearSelectable(); } else if (a != null) { - //piece + selectPiece(a); gameView.getBoardHandler().clearSelectable(); } else if (card != null){ - //card + selectCard(card); gameView.getGuiHandler().clearSelectableCards(); } else { throw new RuntimeException("nothing to confirm"); @@ -98,50 +100,33 @@ public void confirm() { } public void selectTsk(Color color) { - // TODO call from somewhere - LOGGER.log(Level.INFO, "selectTsk: {0}", color); - LobbyView view = (LobbyView) app.getView(); - view.setTaken(color, true, true, "OwnPlayerName"); - testColor = color; + app.getGameLogic().selectTsk(color); } public void unselectTsk() { - // TODO call from somewhere - LOGGER.log(Level.INFO, "unselectTsk"); + app.getGameLogic().selectTsk(Color.NONE); } public void rolledDice() { - // TODO call from somewhere - LOGGER.log(Level.INFO, "rolledDice"); + app.getGameLogic().selectDice(); } public void setName(String name) { // TODO call from somewhere LOGGER.log(Level.INFO, "setName: {0}", name); + app.getGameLogic().selectName(name); } public void setReady(boolean ready) { - LOGGER.log(Level.INFO, "setReady"); - LobbyView view = (LobbyView) app.getView(); - view.setReady(testColor, ready); - test++; - - if(test > 2) { - test = 0; - enter(MdgaState.GAME); - } + app.getGameLogic().selectReady(ready); } public void setHost(int port) { - // TODO call from somewhere - LOGGER.log(Level.INFO, "setHost: {0}", port); - enter(MdgaState.LOBBY); + app.getGameLogic().selectJoin(""); } public void setJoin(String ip, int port) { - // TODO call from somewhere - LOGGER.log(Level.INFO, "setJoin with IP: {0}, Port: {1}", new Object[]{ip, port}); - enter(MdgaState.LOBBY); + app.getGameLogic().selectJoin(ip); } public void leave() { diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/NetworkSupport.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/NetworkSupport.java new file mode 100644 index 00000000..8f1140db --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/NetworkSupport.java @@ -0,0 +1,91 @@ +package pp.mdga.client; + +import com.jme3.network.*; +import pp.mdga.message.client.ClientMessage; +import pp.mdga.message.server.ServerMessage; + +import java.io.IOException; + +public class NetworkSupport implements MessageListener, ClientStateListener, ServerConnection { + private static final System.Logger LOGGER = System.getLogger(NetworkSupport.class.getName()); + private final MdgaApp app; + private Client client; + + public NetworkSupport(MdgaApp app) { + this.app = app; + } + + public MdgaApp getApp() { + return this.app; + } + + public boolean isConnected() { + return this.client != null && this.client.isConnected(); + } + + public void connect() { + if (this.client != null) { + throw new IllegalStateException("trying to join a game again"); + } else { + try { + this.initNetwork("localhost", 2345); + } catch (IOException e) { + LOGGER.log(System.Logger.Level.ERROR, "could not connect to server", e); + } + } + + } + + public void disconnect() { + if (this.client != null) { + this.client.close(); + this.client = null; + LOGGER.log(System.Logger.Level.INFO, "client closed"); + } + } + + public void initNetwork(String host, int port) throws IOException { + if (this.client != null) { + throw new IllegalStateException("trying to join a game again"); + } else { + this.client = Network.connectToServer(host, port); + this.client.start(); + this.client.addMessageListener(this); + this.client.addClientStateListener(this); + } + } + + public void messageReceived(Client client, Message message) { + LOGGER.log(System.Logger.Level.INFO, "message received from server: {0}", new Object[]{message}); + if (message instanceof ServerMessage serverMessage) { + this.app.enqueue(() -> serverMessage.accept(this.app.getGameLogic())); + } + + } + + public void clientConnected(Client client) { + LOGGER.log(System.Logger.Level.INFO, "Client connected: {0}", new Object[]{client}); + } + + public void clientDisconnected(Client client, ClientStateListener.DisconnectInfo disconnectInfo) { + LOGGER.log(System.Logger.Level.INFO, "Client {0} disconnected: {1}", new Object[]{client, disconnectInfo}); + if (this.client != client) { + throw new IllegalArgumentException("parameter value must be client"); + } else { + LOGGER.log(System.Logger.Level.INFO, "client still connected: {0}", new Object[]{client.isConnected()}); + this.client = null; + this.disconnect(); + } + } + + @Override + public void send(ClientMessage message) { + LOGGER.log(System.Logger.Level.INFO, "sending {0}", new Object[]{message}); + if (this.client == null) { + LOGGER.log(System.Logger.Level.WARNING, "client not connected"); + } else { + this.client.send(message); + } + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java index 3ab0999d..c214ecc8 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java @@ -24,8 +24,8 @@ public void addTestNotification(Notification n) { } public void update() { - //TODO fetch model notifications - for (Notification n : notifications) { + Notification n = app.getGameLogic().getNotification(); + if(n != null) { switch (app.getState()) { case MAIN: handleMain(n); @@ -43,14 +43,13 @@ public void update() { throw new RuntimeException("no notification expected: " + n.toString()); } } - notifications.clear(); } private void handleMain(Notification notification) { if (notification instanceof LobbyDialogNotification) { app.enter(MdgaState.LOBBY); } else { - throw new RuntimeException("notification not expected: " + notification.toString()); + throw new RuntimeException("notification not expected: "); } } @@ -62,8 +61,8 @@ private void handleLobby(Notification notification) { lobbyView.setTaken(n.getColor(), true, false, n.getName()); } else if (notification instanceof TskUnselectNotification n) { lobbyView.setTaken(n.getColor(), false, false, null); - //} else if(notification instanceof LobbyReadyNotification lobbyReadyNotification) { - //lobbyView.setReady(lobbyReadyNotification.getColor(), lobbyReadyNotification.isReady()): + } else if(notification instanceof LobbyReadyNotification lobbyReadyNotification) { + lobbyView.setReady(lobbyReadyNotification.getColor(), lobbyReadyNotification.isReady()); } else if (notification instanceof GameNotification) { app.enter(MdgaState.GAME); } else { diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java index d9b96a1b..2d6e4a13 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java @@ -317,7 +317,6 @@ public void setTaken(Taken taken, String name) { } else { label.setText(name); } - onUnHover(); } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java index 674d74f2..829aff09 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java @@ -3,6 +3,7 @@ import com.jme3.math.Vector2f; import com.jme3.scene.Node; import pp.mdga.client.MdgaApp; +import pp.mdga.client.NetworkSupport; import pp.mdga.client.button.ButtonLeft; import pp.mdga.client.button.ButtonRight; import pp.mdga.client.button.InputButton; @@ -11,7 +12,7 @@ import java.util.prefs.Preferences; -public class HostDialog extends Dialog { +public class HostDialog extends NetworkDialog { private InputButton portInput; private ButtonRight hostButton; @@ -22,7 +23,7 @@ public class HostDialog extends Dialog { private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class); public HostDialog(MdgaApp app, Node node, MainView view) { - super(app, node); + super(app, node, (NetworkSupport) app.getNetworkSupport()); this.view = view; @@ -58,6 +59,7 @@ public void update() { public String getPort() { prefs.put("hostPort", portInput.getString()); + setPortNumber(Integer.parseInt(portInput.getString())); return portInput.getString(); } @@ -65,4 +67,13 @@ public void resetPort() { portInput.reset(); prefs.put("hostPort", "11111"); } + + public void hostServer() { + startServer(); + } + + public void connectServerAsClient() { + connectServer(); + } + } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java index 6e830e2a..067ba3c7 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java @@ -3,6 +3,7 @@ import com.jme3.math.Vector2f; import com.jme3.scene.Node; import pp.mdga.client.MdgaApp; +import pp.mdga.client.NetworkSupport; import pp.mdga.client.acoustic.AcousticHandler; import pp.mdga.client.button.ButtonLeft; import pp.mdga.client.button.ButtonRight; @@ -12,7 +13,7 @@ import java.util.prefs.Preferences; -public class JoinDialog extends Dialog { +public class JoinDialog extends NetworkDialog { private InputButton ipInput; private InputButton portInput; @@ -24,7 +25,7 @@ public class JoinDialog extends Dialog { private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class); public JoinDialog(MdgaApp app, Node node, MainView view) { - super(app, node); + super(app, node, (NetworkSupport) app.getNetworkSupport()); this.view = view; @@ -68,6 +69,7 @@ public void update() { public String getIpt() { prefs.put("joinIp", ipInput.getString()); + setHostname(ipInput.getString()); return ipInput.getString(); } @@ -78,6 +80,7 @@ public void resetIp() { public String getPort() { prefs.put("joinPort", portInput.getString()); + setPortNumber(Integer.parseInt(portInput.getString())); return portInput.getString(); } @@ -85,4 +88,8 @@ public void resetPort() { portInput.reset(); prefs.put("joinPort", "11111"); } + + public void connectToServer() { + connectServer(); + } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java new file mode 100644 index 00000000..94f2bbc2 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/NetworkDialog.java @@ -0,0 +1,73 @@ +package pp.mdga.client.dialog; + +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; +import pp.mdga.client.NetworkSupport; +import pp.mdga.client.server.MdgaServer; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public abstract class NetworkDialog extends Dialog { + + private NetworkSupport network; + private String hostname; + private int portNumber; + private Future connectionFuture; + + public NetworkDialog(MdgaApp app, Node node, NetworkSupport network) { + super(app, node); + this.network = network; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + public void setPortNumber(int portNumber) { + this.portNumber = portNumber; + } + + + protected Object initNetwork() { + try { + this.network.initNetwork(this.hostname, this.portNumber); + return null; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected void connectServer() { + + try { + connectionFuture = this.network.getApp().getExecutor().submit(this::initNetwork); + } catch (NumberFormatException var2) { + throw new NumberFormatException("Port must be a number"); + } + + } + + protected void startServer() { + (new Thread(() -> { + try { + MdgaServer mdgaServer = new MdgaServer(portNumber); + mdgaServer.run(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + })).start(); + } + + public void update(float delta) { + if (this.connectionFuture != null && this.connectionFuture.isDone()) { + try { + this.connectionFuture.get(); + } catch (ExecutionException ignored) { + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java index f1780baf..f63de56a 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java @@ -4,6 +4,7 @@ import com.jme3.network.serializing.Serializer; import pp.mdga.game.Game; import pp.mdga.game.Player; +import pp.mdga.game.Statistic; import pp.mdga.message.client.*; import pp.mdga.message.server.*; import pp.mdga.server.ServerGameLogic; @@ -13,8 +14,8 @@ import java.io.IOException; import java.lang.System.Logger; import java.lang.System.Logger.Level; -import java.sql.Connection; import java.util.Map; +import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.logging.LogManager; @@ -51,7 +52,6 @@ public MdgaServer(int port) { LOGGER.log(Level.INFO, "Creating MdgaServer"); //NON-NLS logic = new ServerGameLogic(this, new Game()); } - /** * */ @@ -89,6 +89,7 @@ private void processNextMessage() { } private void initializeSerializables() { + Serializer.registerClass(UUID.class, new UUIDSerializer()); Serializer.registerClass(AnimationEndMessage.class); Serializer.registerClass(ClientStartGameMessage.class); Serializer.registerClass(DeselectTSKMessage.class); @@ -106,7 +107,6 @@ private void initializeSerializables() { Serializer.registerClass(SelectCardMessage.class); Serializer.registerClass(SelectedPiecesMessage.class); Serializer.registerClass(SelectTSKMessage.class); - Serializer.registerClass(ActivePlayerMessage.class); Serializer.registerClass(AnyPieceMessage.class); Serializer.registerClass(BriefingMessage.class); @@ -134,12 +134,15 @@ private void initializeSerializables() { Serializer.registerClass(UpdateReadyMessage.class); Serializer.registerClass(UpdateTSKMessage.class); Serializer.registerClass(WaitPieceMessage.class); + Serializer.registerClass(Player.class); + Serializer.registerClass(Statistic.class); } private void registerListeners() { myServer.addMessageListener(this, AnimationEndMessage.class); myServer.addMessageListener(this, ClientStartGameMessage.class); myServer.addMessageListener(this, DeselectTSKMessage.class); + myServer.addMessageListener(this, DisconnectedMessage.class); myServer.addMessageListener(this, ForceContinueGameMessage.class); myServer.addMessageListener(this, StartGameMessage.class); myServer.addMessageListener(this, JoinedLobbyMessage.class); @@ -187,7 +190,7 @@ private void messageReceived(HostedConnection source, ClientMessage message) { @Override public void connectionAdded(Server server, HostedConnection hostedConnection) { - LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS + LOGGER.log(Level.DEBUG, "new connection {0}", hostedConnection); //NON-NLS } @Override diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/UUIDSerializer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/UUIDSerializer.java new file mode 100644 index 00000000..c892e6d7 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/UUIDSerializer.java @@ -0,0 +1,26 @@ +package pp.mdga.client.server; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.UUID; + +import com.jme3.network.serializing.Serializer; + +public class UUIDSerializer extends Serializer +{ + @Override + public T readObject(ByteBuffer data, Class c) throws IOException +{ + byte[] uuid = new byte[36]; + data.get(uuid); + + return (T) UUID.fromString(new String(uuid)); +} + + @Override + public void writeObject(ByteBuffer buffer, Object object) throws IOException + { + UUID uuid = (UUID) object; + buffer.put(uuid.toString().getBytes()); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java index 4cec73a7..6aa5161d 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java @@ -7,6 +7,9 @@ import pp.mdga.client.dialog.JoinDialog; import pp.mdga.client.dialog.StartDialog; +import java.net.Inet4Address; +import java.net.UnknownHostException; + public class MainView extends MdgaView { private enum SubState { HOST, @@ -99,12 +102,25 @@ private void tryHost() { if(port >= 1 && port <= 65535) { app.getModelSynchronize().setName(startDialog.getName()); + hostDialog.setHostname(Inet4Address.getLocalHost().getHostAddress()); + hostDialog.hostServer(); + try { + Thread.sleep(1000); + } catch (InterruptedException ignored) { + } + hostDialog.connectServerAsClient(); + try { + Thread.sleep(1000); + } catch (InterruptedException ignored) { + } app.getModelSynchronize().setHost(port); //app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT); return; } } catch (NumberFormatException e) { //nothing + } catch (UnknownHostException e) { + throw new RuntimeException(e); } hostDialog.resetPort(); @@ -127,6 +143,7 @@ private void tryJoin() { if (isValidIpAddress(ip)) { app.getModelSynchronize().setName(startDialog.getName()); app.getModelSynchronize().setJoin(ip, port); + joinDialog.connectToServer(); return; } } catch (IllegalArgumentException e) { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java index 33cbc035..eeb76f55 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java @@ -28,9 +28,10 @@ public class ClientGameLogic implements ServerInterpreter { private final InterruptState interruptState = new InterruptState(null, this); private final SettingsState settingsState = new SettingsState(null, this); - public ClientGameLogic(Game game, ClientSender clientSender) { - this.game = game; + public ClientGameLogic(ClientSender clientSender) { + this.game = new Game(); this.clientSender = clientSender; + dialogsState.enter(); state = dialogsState; } @@ -244,7 +245,11 @@ public void selectName(String name){ } public void selectReady(boolean ready){ - state.selectReady(ready); + if(ready){ + state.selectReady(); + } else { + state.selectUnready(); + } } public void selectHost(String name){ @@ -304,7 +309,11 @@ public SettingsState getSettings(){ } public Notification getNotification(){ - return notifications.remove(0); + if(!notifications.isEmpty()){ + return notifications.remove(0); + } else { + return null; + } } public void addNotification(Notification notification){ diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java index 8cb19bc1..e53a5d92 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java @@ -200,7 +200,7 @@ public void setName(String name) { LOGGER.log(Level.DEBUG, "Setting name not allowed."); } - public void selectReady(boolean ready) { + public void selectReady() { LOGGER.log(Level.DEBUG, "Selecting ready not allowed."); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java index 101b8d73..b72c1294 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/DialogsState.java @@ -37,7 +37,7 @@ public void enter(){ public void setState(DialogStates newState){ currentState.exit(); - currentState.enter(); + newState.enter(); currentState = newState; } @@ -75,6 +75,11 @@ public void selectLeave(){ currentState.selectLeave(); } + @Override + public void setName(String name){ + currentState.setName(name); + } + @Override public void selectTSK(Color color){ currentState.selectTSK(color); @@ -86,8 +91,8 @@ public void deselectTSK(Color color){ } @Override - public void selectReady(boolean ready){ - currentState.selectReady(ready); + public void selectReady(){ + currentState.selectReady(); } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ServerConnection.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ServerConnection.java new file mode 100644 index 00000000..3f096c74 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ServerConnection.java @@ -0,0 +1,9 @@ +package pp.mdga.client; + +public interface ServerConnection extends ClientSender { + boolean isConnected(); + + void connect(); + + void disconnect(); +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java index 747211ae..9064fee0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/LobbyState.java @@ -11,6 +11,7 @@ import pp.mdga.message.server.ServerStartGameMessage; import pp.mdga.message.server.UpdateReadyMessage; import pp.mdga.message.server.UpdateTSKMessage; +import pp.mdga.notification.LobbyReadyNotification; import pp.mdga.notification.TskSelectNotification; import pp.mdga.notification.TskUnselectNotification; @@ -49,7 +50,7 @@ public void deselectTSK(Color color) { } @Override - public void selectReady(boolean ready) { + public void selectReady() { logic.send(new LobbyReadyMessage()); } @@ -76,6 +77,7 @@ public void received(ServerStartGameMessage msg){ @Override public void received(LobbyPlayerJoinedMessage msg){ + logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), parent.getOwnPlayerId()== msg.getId())); logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer()); } @@ -94,6 +96,7 @@ public void received(LobbyPlayerLeaveMessage msg){ @Override public void received(UpdateReadyMessage msg){ + logic.addNotification(new LobbyReadyNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor(), msg.isReady())); logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/NetworkDialogState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/NetworkDialogState.java index f23abd9d..09212dee 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/NetworkDialogState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/NetworkDialogState.java @@ -3,6 +3,7 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; import pp.mdga.client.DialogsState; +import pp.mdga.notification.LobbyDialogNotification; public class NetworkDialogState extends DialogStates { @@ -55,9 +56,7 @@ public void selectLeave() { } public void selectJoin(String IP) { - if(checkIP(IP)){ - parent.setState(parent.getLobby()); - } - + parent.setState(parent.getLobby()); + logic.addNotification(new LobbyDialogNotification()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/StartDialogState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/StartDialogState.java index a9e5d148..47b9944a 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/StartDialogState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/dialogState/StartDialogState.java @@ -37,6 +37,12 @@ public void selectHost(String name) { logic.setHost(true); } + @Override + public void setName(String name) { + parent.setState(parent.getNetworkDialog()); + parent.setOwnPlayerName(name); + } + @Override public void selectLeave() { parent.exit(); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java index 7537333b..0dd875f0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java @@ -1,10 +1,13 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + import java.util.ArrayList; /** * This class will be used to handle general PlayerData */ +@Serializable public class Player { /** * The name of the player. diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java index 40675707..5acd5d14 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java @@ -1,8 +1,11 @@ package pp.mdga.game; +import com.jme3.network.serializing.Serializable; + /** * This class will be used to store Statistics during the Game; */ +@Serializable public class Statistic { /** * The number of cards played. diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/client/StartGameMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/client/StartGameMessage.java index bad3286c..4436225d 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/client/StartGameMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/client/StartGameMessage.java @@ -18,7 +18,7 @@ public StartGameMessage(boolean forceStartGame){ /** * Constructs a new ForceStartGame message. */ - public StartGameMessage() { + private StartGameMessage() { super(); forceStartGame = false; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyReadyNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyReadyNotification.java new file mode 100644 index 00000000..eeccd24f --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyReadyNotification.java @@ -0,0 +1,43 @@ +package pp.mdga.notification; + +import pp.mdga.game.Color; + +public class LobbyReadyNotification extends Notification{ + + /** + * The color of the player. + */ + private Color color; + + /** + * Indicates if the player is ready. + */ + private boolean ready; + + /** + * Constructor + */ + public LobbyReadyNotification(Color color, boolean ready) { + this.color = color; + this.ready = ready; + } + + /** + * This method is used to get the color of the player + * + * @return the color of the player + */ + public Color getColor() { + return color; + } + + /** + * This method is used to get the ready state of the player + * + * @return the ready state of the player + */ + public boolean isReady() { + return ready; + } + +} From 5a68d3b146f01221db20732da1c1e9f38f906ee9 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 21:52:28 +0100 Subject: [PATCH 9/9] fixed a method call for getMoveIndices --- .../src/main/java/pp/mdga/client/NotificationSynchronizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java index c214ecc8..2f0ae1ff 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java @@ -164,7 +164,7 @@ private void handleGame(Notification notification) { } else if (notification instanceof WaitMoveNotification) { //TODO ??? } else if (notification instanceof SelectableMoveNotification n) { - boardHandler.outlineMove(n.getPieces(), n.getMoveIndexe(), n.getHomeMoves()); + boardHandler.outlineMove(n.getPieces(), n.getMoveIndices(), n.getHomeMoves()); } else if (notification instanceof SelectableSwapNotification n) { boardHandler.outlineSwap(n.getOwnPieces(), n.getEnemyPieces()); // } //else if (notification instanceof SelectableShieldNotification n) {