From 977a7294ad12586571d47291df17903f7590cea3 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 1 Dec 2024 21:49:11 +0100 Subject: [PATCH] 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; + } +}