From 0297193be1b5678f8d647920b5924ca6c173cd25 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 16:23:09 +0100 Subject: [PATCH 01/10] added more functionality to the client state machine and implemeted the first notifications --- .../mdga/client/NotificationSynchronizer.java | 8 ++--- .../java/pp/mdga/client/ClientGameLogic.java | 29 +++++++++++++--- .../main/java/pp/mdga/client/ClientState.java | 2 +- .../java/pp/mdga/client/DialogsState.java | 33 +++++++++++++++++-- .../main/java/pp/mdga/client/GameState.java | 12 +++++++ .../java/pp/mdga/client/InterruptState.java | 20 ++++++++++- .../mdga/client/dialogState/LobbyState.java | 21 ++++++++++-- .../client/dialogState/StartDialogState.java | 9 +++-- .../gameState/turnState/ChoosePieceState.java | 6 +++- .../gameState/turnState/PowerCardState.java | 4 +++ .../mdga/message/server/PauseGameMessage.java | 23 +++++++++++++ .../mdga/message/server/UpdateTSKMessage.java | 2 +- .../notification/TskSelectNotification.java | 17 ++++++++-- 13 files changed, 162 insertions(+), 24 deletions(-) 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 76767434..1472f920 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 @@ -89,13 +89,13 @@ private void handleGame(Notification notification) { } else if (notification instanceof MovePieceNotification) { MovePieceNotification n = (MovePieceNotification)notification; //gameView.getBoardHandler().movePiece(n.get); //TODO - } else if (notification instanceof MoveThrowPieceNotification) { - MoveThrowPieceNotification n = (MoveThrowPieceNotification)notification; + //TODO: } else if (notification instanceof MoveThrowPieceNotification) { + //TODO: MoveThrowPieceNotification n = (MoveThrowPieceNotification)notification; //gameView.getBoardHandler().throwPiece(n.); //TODO } else if (notification instanceof NoShieldNotification) { NoShieldNotification n = (NoShieldNotification)notification; gameView.getBoardHandler().unshieldPiece(n.getPieceId()); - } else if (notification instanceof PieceInGameNotification) { + //TODO:} else if (notification instanceof PieceInGameNotification) { // Handle PieceInGameNotification } else if (notification instanceof PlayCardNotification) { // Handle PlayCardNotification @@ -107,7 +107,7 @@ private void handleGame(Notification notification) { // Handle RollDiceNotification } else if (notification instanceof SelectableCardsNotification) { // Handle SelectableCardsNotification - } else if (notification instanceof SelectablePiecesNotification) { + //TODO: } else if (notification instanceof SelectablePiecesNotification) { // Handle SelectablePiecesNotification } else if (notification instanceof ShieldActiveNotification) { ShieldActiveNotification n = (ShieldActiveNotification)notification; 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 c40f7e02..32cf9754 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 @@ -1,5 +1,6 @@ package pp.mdga.client; +import pp.mdga.game.BonusCard; import pp.mdga.game.Color; import pp.mdga.game.Game; import pp.mdga.game.Piece; @@ -19,6 +20,7 @@ public class ClientGameLogic implements ServerInterpreter { private final ClientSender clientSender; private ClientState state; private final ArrayList notifications = new ArrayList<>(); + private boolean isHost; private final DialogsState dialogsState = new DialogsState(null, this); private final GameState gameState = new GameState(null, this); @@ -59,6 +61,14 @@ public ClientState getState(){ return state; } + public boolean isHost(){ + return isHost; + } + + public void setHost(boolean isHost){ + this.isHost = isHost; + } + @Override public void received(ActivePlayerMessage msg) { state.received(msg); @@ -201,16 +211,15 @@ public void received(SpectatorMessage msg) { @Override public void received(SelectPieceMessage msg) { - + state.received(msg); } public void selectPiece(UUID pieceId){ state.selectPiece(getPiece(pieceId)); } - //TODO: implement - public void selectCard(UUID cardId){ - state.selectCard(null); + public void selectCard(BonusCard card){ + state.selectCard(card); } public void selectTsk(Color color){ @@ -226,7 +235,7 @@ public void selectName(String name){ } public void selectReady(boolean ready){ - state.selectReady(); + state.selectReady(ready); } public void selectHost(String name){ @@ -255,6 +264,12 @@ public void setState(ClientState state){ this.state = state; } + public void enterInterrupt(){ + interruptState.enter(); + interruptState.setPreviousState(state); + this.state = interruptState; + } + public GameState getGameState(){ return gameState; } @@ -275,4 +290,8 @@ public Notification getNotification(){ return notifications.remove(0); } + public void addNotification(Notification notification){ + notifications.add(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 a9accf58..e16b9c91 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 @@ -199,7 +199,7 @@ public void setName(String name) { LOGGER.log(Level.DEBUG, "Setting name not allowed."); } - public void selectReady() { + public void selectReady(boolean ready) { 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 7f30a8c4..ca8cb4ef 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 @@ -7,12 +7,15 @@ import pp.mdga.game.Player; import pp.mdga.message.server.LobbyPlayerJoinMessage; import pp.mdga.message.server.LobbyPlayerLeaveMessage; +import pp.mdga.message.server.UpdateReadyMessage; +import pp.mdga.message.server.UpdateTSKMessage; public class DialogsState extends ClientState { private DialogStates currentState; - private Player ownPlayer; + private int ownPlayerID; + private String ownPlayerName; private final LobbyState lobbyState = new LobbyState(this, logic); private final NetworkDialogState networkDialogState = new NetworkDialogState(this, logic); @@ -31,6 +34,8 @@ public void exit(){ @Override public void enter(){ currentState = startDialogState; + ownPlayerID = 0; + ownPlayerName = null; } public void setState(DialogStates newState){ @@ -39,8 +44,16 @@ public void setState(DialogStates newState){ currentState = newState; } - public Player getOwnPlayer() { - return ownPlayer; + public int getOwnPlayerId() { + return ownPlayerID; + } + + public String getOwnPlayerName() { + return ownPlayerName; + } + + public void setOwnPlayerName(String ownPlayerName) { + this.ownPlayerName = ownPlayerName; } public LobbyState getLobby() { @@ -69,4 +82,18 @@ public void received(LobbyPlayerJoinMessage msg){ public void received(LobbyPlayerLeaveMessage msg){ currentState.received(msg); } + + @Override + public void received(UpdateTSKMessage msg){ + currentState.received(msg); + } + + @Override + public void received(UpdateReadyMessage msg){ + currentState.received(msg); + } + + public DialogStates getState() { + return currentState; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java index 56901970..fa8827ed 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java @@ -1,6 +1,8 @@ package pp.mdga.client; import pp.mdga.client.gameState.*; +import pp.mdga.message.server.PauseGameMessage; +import pp.mdga.notification.InterruptNotification; public class GameState extends ClientState { @@ -38,6 +40,16 @@ public void selectAnimationEnd(){ state.selectAnimationEnd(); } + @Override + public void received(PauseGameMessage msg){ + logic.enterInterrupt(); + logic.addNotification(new InterruptNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor())); + } + + public GameStates getState(){ + return state; + } + public AnimationState getAnimation() { return animationState; } 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 f58e2fe7..7ea0e21d 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 @@ -1,18 +1,36 @@ package pp.mdga.client; +import pp.mdga.message.server.ResumeGameMessage; +import pp.mdga.notification.ResumeNotification; + public class InterruptState extends ClientState { + private ClientState previousState; + public InterruptState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } @Override public void enter() { - + previousState = null; } @Override public void exit() { + previousState = null; + } + public void setPreviousState(ClientState previousState) { + this.previousState = previousState; + } + + public ClientState getPreviousState() { + return previousState; + } + + public void received(ResumeGameMessage msg) { + //TODO: logic.addNotification(new ResumeNotification()); + logic.setState(previousState); } } 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 5f09da11..81c5fa6c 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 @@ -9,6 +9,10 @@ import pp.mdga.message.server.LobbyPlayerJoinMessage; import pp.mdga.message.server.LobbyPlayerLeaveMessage; import pp.mdga.message.server.ServerStartGameMessage; +import pp.mdga.message.server.UpdateReadyMessage; +import pp.mdga.message.server.UpdateTSKMessage; +import pp.mdga.notification.TskSelectNotification; +import pp.mdga.notification.TskUnselectNotification; public class LobbyState extends DialogStates { @@ -21,12 +25,10 @@ public LobbyState(ClientState parent, ClientGameLogic logic) { @Override public void enter() { - } @Override public void exit() { - } @Override @@ -45,7 +47,7 @@ public void deselectTSK(Color color) { } @Override - public void selectReady() { + public void selectReady(boolean ready) { logic.send(new LobbyReadyMessage()); } @@ -69,8 +71,21 @@ public void received(LobbyPlayerJoinMessage msg){ logic.getGame().getPlayers().put(msg.getId(), new Player(msg.getName())); } + @Override + public void received(UpdateTSKMessage msg){ + logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor())); + logic.getGame().getPlayers().get(msg.getId()).setColor(msg.getColor()); + logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), parent.getOwnPlayerId()== msg.getId())); + } + @Override public void received(LobbyPlayerLeaveMessage msg){ + logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor())); logic.getGame().getPlayers().remove(msg.getId()); } + + @Override + public void received(UpdateReadyMessage msg){ + logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady()); + } } 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 7e2bcc86..a9e5d148 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 @@ -23,16 +23,21 @@ public void exit() { } + @Override public void selectJoin(String name) { - parent.getOwnPlayer().setName(name); + parent.setOwnPlayerName(name); parent.setState(parent.getNetworkDialog()); + logic.setHost(false); } + @Override public void selectHost(String name) { - parent.getOwnPlayer().setName(name); + parent.setOwnPlayerName(name); parent.setState(parent.getLobby()); + logic.setHost(true); } + @Override public void selectLeave() { parent.exit(); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java index d5d86ffd..1c501853 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java @@ -27,7 +27,7 @@ public void enter() { @Override public void exit() { - + currentState= null; } public void setState(ChoosePieceStates state){ @@ -52,6 +52,10 @@ public WaitingPieceState getWaitingPiece(){ return waitingPieceState; } + public ChoosePieceStates getState(){ + return currentState; + } + public TurnState getParent(){ return parent; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java index 1a880df4..b2cc1c7f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java @@ -54,4 +54,8 @@ public SwapState getSwap() { public TurnState getParent() { return parent; } + + public PowerCardStates getState() { + return state; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PauseGameMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PauseGameMessage.java index de9c6a8f..536a918f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PauseGameMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PauseGameMessage.java @@ -7,6 +7,12 @@ */ @Serializable public class PauseGameMessage extends ServerMessage { + + /** + * the id of the player who has disconnected + */ + private int playerId; + /** * Constructs a new PauseGame instance. */ @@ -14,6 +20,23 @@ public PauseGameMessage() { super(); } + /** + * Constructs a new PauseGame instance. + */ + public PauseGameMessage(int playerId) { + super(); + this.playerId = playerId; + } + + /** + * Returns the player id of the disconnected player + * + * @return the id of the disconnected player as an int + */ + public int getPlayerId() { + return playerId; + } + /** * Accepts a visitor to process this message. * diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/UpdateTSKMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/UpdateTSKMessage.java index 8597a1e2..bbbdf14b 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/UpdateTSKMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/UpdateTSKMessage.java @@ -19,7 +19,7 @@ public class UpdateTSKMessage extends ServerMessage { private final Color color; /** - * Constructs a new UpdateTSK instance with the specified name and color. + * Constructs a new UpdateTSK instance with the specified id and color. * * @param id the name associated with the update * @param color the color associated with the update 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 2d0f1c49..bf339e0c 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 @@ -7,17 +7,19 @@ */ public class TskSelectNotification extends Notification{ - private Color color; - private String name; + private final Color color; + private final String name; + 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. */ - public TskSelectNotification(Color color, String name) { + public TskSelectNotification(Color color, String name, boolean isSelf) { this.color = color; this.name = name; + this.isSelf = isSelf; } /** @@ -35,4 +37,13 @@ public Color getColor() { public String getName() { return name; } + + /** + * returns a boolean based of if the select notification affects the own user + * + * @return boolean isSelf + */ + public boolean isSelf() { + return isSelf; + } } From b3d754e77f1c532107f893e7501a89f411de4365 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 16:42:24 +0100 Subject: [PATCH 02/10] added all current State getter in every client state machine --- .../java/pp/mdga/client/CeremonyState.java | 28 +++- .../java/pp/mdga/client/ClientGameLogic.java | 5 + .../java/pp/mdga/client/SettingsState.java | 29 +++- .../client/ceremonyState/PodiumState.java | 9 ++ .../gameState/DetermineStartPlayerState.java | 4 + .../pp/mdga/client/gameState/TurnState.java | 4 + .../settingsState/MainSettingsState.java | 2 +- .../notification/CeremonyNotification.java | 146 +++++++++++++++++- 8 files changed, 223 insertions(+), 4 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java index dd83c91e..12ff870a 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java @@ -1,7 +1,15 @@ package pp.mdga.client; +import pp.mdga.client.ceremonyState.CeremonyStates; +import pp.mdga.client.ceremonyState.PodiumState; +import pp.mdga.client.ceremonyState.StatisticsState; + public class CeremonyState extends ClientState { + private CeremonyStates currentState; + + private final PodiumState podiumState = new PodiumState(this, logic); + private final StatisticsState statisticsState = new StatisticsState(this, logic); public CeremonyState(ClientState parent, ClientGameLogic logic) { super(parent, logic); @@ -9,11 +17,29 @@ public CeremonyState(ClientState parent, ClientGameLogic logic) { @Override public void enter() { - + currentState = podiumState; } @Override public void exit() { + currentState.exit(); + } + public void setState(CeremonyStates state){ + this.currentState.exit(); + state.enter(); + currentState = state; + } + + public PodiumState getPodiumState(){ + return podiumState; + } + + public StatisticsState getStatisticsState(){ + return statisticsState; + } + + public CeremonyStates getState(){ + return currentState; } } 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 32cf9754..ad560205 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 @@ -26,6 +26,7 @@ public class ClientGameLogic implements ServerInterpreter { private final GameState gameState = new GameState(null, this); private final CeremonyState ceremonyState = new CeremonyState(null, this); 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; @@ -286,6 +287,10 @@ public DialogsState getDialogs(){ return dialogsState; } + public SettingsState getSettings(){ + return settingsState; + } + public Notification getNotification(){ return notifications.remove(0); } 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 88800cc8..969a08cf 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 @@ -1,18 +1,45 @@ package pp.mdga.client; +import pp.mdga.client.settingsState.AudioSettingsState; +import pp.mdga.client.settingsState.MainSettingsState; +import pp.mdga.client.settingsState.SettingStates; +import pp.mdga.client.settingsState.VideoSettingsState; + public class SettingsState extends ClientState { + 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); + public SettingsState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } @Override public void enter() { - + currentState = mainSettingsState; } @Override public void exit() { + currentState.exit(); + } + public SettingStates getState(){ + return currentState; + } + + public MainSettingsState getMainSettingsState(){ + return mainSettingsState; + } + + public AudioSettingsState getAudioSettingsState(){ + return audioSettingsState; + } + + public VideoSettingsState getVideoSettingsState(){ + return videoSettingsState; } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java index b6a5c535..199fde11 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java @@ -1,11 +1,16 @@ package pp.mdga.client.ceremonyState; +import pp.mdga.client.CeremonyState; import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; public class PodiumState extends CeremonyStates { + + private final CeremonyState parent; + public PodiumState(ClientState parent, ClientGameLogic logic) { super(parent, logic); + this.parent = (CeremonyState) parent; } @Override @@ -17,4 +22,8 @@ public void enter() { public void exit() { } + + public void selectNext(){ + parent.setState(parent.getStatisticsState()); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java index 0413ad9b..8b6480c6 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java @@ -43,4 +43,8 @@ public RollRankingDiceState getRollRankingDice() { public WaitRankingState getWaitRanking() { return waitRankingState; } + + public DetermineStartPlayerStates getState(){ + return state; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java index c0af142d..055986cf 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java @@ -89,4 +89,8 @@ public RollDiceState getRollDice() { public GameState getParent(){ return parent; } + + public TurnStates getState(){ + return state; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/settingsState/MainSettingsState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/settingsState/MainSettingsState.java index 8e1b3f25..5b1bde44 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/settingsState/MainSettingsState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/settingsState/MainSettingsState.java @@ -3,7 +3,7 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; -public class MainSettingsState extends ClientState { +public class MainSettingsState extends SettingStates { public MainSettingsState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } 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 20a270dc..f7210f69 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 @@ -1,12 +1,156 @@ package pp.mdga.notification; +import pp.mdga.game.Color; + +import java.util.ArrayList; + /** * Class CeremonyNotification + * Represents a notification for a ceremony in the game. + * + * Index mapping: + * index = 0 ==> winner + * index = 1 ==> 2nd + * index = 2 ==> third place + * index = 3 ==> loser + * index = 4 ==> total */ -public class CeremonyNotification extends Notification{ +public class CeremonyNotification extends Notification { + private ArrayList colors; + private ArrayList names; + private ArrayList piecesThrown; + private ArrayList piecesLost; + private ArrayList bonusCardsPlayed; + private ArrayList sixes; + private ArrayList nodesMoved; + private ArrayList bonusNodes; + /** * Constructor + * Initializes all lists. */ public CeremonyNotification() { + this.colors = new ArrayList<>(); + this.names = new ArrayList<>(); + this.piecesThrown = new ArrayList<>(); + this.piecesLost = new ArrayList<>(); + this.bonusCardsPlayed = new ArrayList<>(); + this.sixes = new ArrayList<>(); + this.nodesMoved = new ArrayList<>(); + this.bonusNodes = new ArrayList<>(); + } + + // Getters and Setters + + /** + * @return the list of colors + */ + public ArrayList getColors() { + return colors; + } + + /** + * @param colors the list of colors to set + */ + public void setColors(ArrayList colors) { + this.colors = colors; + } + + /** + * @return the list of player names + */ + public ArrayList getNames() { + return names; + } + + /** + * @param names the list of player names to set + */ + public void setNames(ArrayList names) { + this.names = names; + } + + /** + * @return the list of pieces thrown + */ + public ArrayList getPiecesThrown() { + return piecesThrown; + } + + /** + * @param piecesThrown the list of pieces thrown to set + */ + public void setPiecesThrown(ArrayList piecesThrown) { + this.piecesThrown = piecesThrown; + } + + /** + * @return the list of pieces lost + */ + public ArrayList getPiecesLost() { + return piecesLost; + } + + /** + * @param piecesLost the list of pieces lost to set + */ + public void setPiecesLost(ArrayList piecesLost) { + this.piecesLost = piecesLost; + } + + /** + * @return the list of bonus cards played + */ + public ArrayList getBonusCardsPlayed() { + return bonusCardsPlayed; + } + + /** + * @param bonusCardsPlayed the list of bonus cards played to set + */ + public void setBonusCardsPlayed(ArrayList bonusCardsPlayed) { + this.bonusCardsPlayed = bonusCardsPlayed; + } + + /** + * @return the list of sixes rolled + */ + public ArrayList getSixes() { + return sixes; + } + + /** + * @param sixes the list of sixes rolled to set + */ + public void setSixes(ArrayList sixes) { + this.sixes = sixes; + } + + /** + * @return the list of nodes moved + */ + public ArrayList getNodesMoved() { + return nodesMoved; + } + + /** + * @param nodesMoved the list of nodes moved to set + */ + public void setNodesMoved(ArrayList nodesMoved) { + this.nodesMoved = nodesMoved; + } + + /** + * @return the list of bonus nodes + */ + public ArrayList getBonusNodes() { + return bonusNodes; + } + + /** + * @param bonusNodes the list of bonus nodes to set + */ + public void setBonusNodes(ArrayList bonusNodes) { + this.bonusNodes = bonusNodes; } } From 422e94ec4814ebb08d69a3159495cd0644aa624e Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 19:49:52 +0100 Subject: [PATCH 03/10] Dialog state machine is now fully functional --- .../java/pp/mdga/client/ClientGameLogic.java | 4 +- .../main/java/pp/mdga/client/ClientState.java | 2 +- .../java/pp/mdga/client/DialogsState.java | 51 +++++++++++++++++-- .../mdga/client/dialogState/LobbyState.java | 8 ++- .../gameState/turnState/ChoosePieceState.java | 1 + .../gameState/turnState/MovePieceState.java | 30 +++++++++++ .../turnState/PlayPowerCardState.java | 10 +++- .../gameState/turnState/PowerCardState.java | 2 +- .../gameState/turnState/RollDiceState.java | 21 ++++++++ .../turnState/powerCardState/ShieldState.java | 2 +- .../turnState/powerCardState/SwapState.java | 2 +- .../pp/mdga/message/server/DieMessage.java | 16 ------ 12 files changed, 121 insertions(+), 28 deletions(-) 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 ad560205..a50ecf53 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 @@ -247,8 +247,8 @@ public void selectLeave(){ state.selectLeave(); } - public void selectJoin(String name){ - state.selectJoin(name); + public void selectJoin(String ip){ + state.selectJoin(ip); } public void selectAnimationEnd(){ 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 e16b9c91..190e4c45 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 @@ -207,7 +207,7 @@ public void selectHost(String name) { LOGGER.log(Level.DEBUG, "Selecting host not allowed."); } - public void selectJoin(String name) { + public void selectJoin(String string) { LOGGER.log(Level.DEBUG, "Selecting join 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 ca8cb4ef..39ca5170 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 @@ -4,11 +4,9 @@ import pp.mdga.client.dialogState.LobbyState; import pp.mdga.client.dialogState.NetworkDialogState; import pp.mdga.client.dialogState.StartDialogState; +import pp.mdga.game.Color; import pp.mdga.game.Player; -import pp.mdga.message.server.LobbyPlayerJoinMessage; -import pp.mdga.message.server.LobbyPlayerLeaveMessage; -import pp.mdga.message.server.UpdateReadyMessage; -import pp.mdga.message.server.UpdateTSKMessage; +import pp.mdga.message.server.*; public class DialogsState extends ClientState { @@ -73,6 +71,46 @@ public void startGame(){ logic.setState(logic.getGameState()); } + @Override + public void selectLeave(){ + currentState.selectLeave(); + } + + @Override + public void selectTSK(Color color){ + currentState.selectTSK(color); + } + + @Override + public void deselectTSK(Color color){ + currentState.deselectTSK(color); + } + + @Override + public void selectReady(boolean ready){ + currentState.selectReady(ready); + } + + @Override + public void selectUnready(){ + currentState.selectUnready(); + } + + @Override + public void selectStart(){ + currentState.selectStart(); + } + + @Override + public void selectJoin(String string){ + currentState.selectJoin(string); + } + + @Override + public void selectHost(String name){ + currentState.selectHost(name); + } + @Override public void received(LobbyPlayerJoinMessage msg){ currentState.received(msg); @@ -93,6 +131,11 @@ public void received(UpdateReadyMessage msg){ currentState.received(msg); } + @Override + public void received(ServerStartGameMessage msg){ + currentState.received(msg); + } + public DialogStates 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 81c5fa6c..5ced9a3d 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 @@ -58,7 +58,13 @@ public void selectUnready(){ @Override public void selectStart(){ - logic.send(new StartGameMessage()); + if(logic.isHost() && logic.getGame().allReady()){ + logic.send(new StartGameMessage(false)); + } else if(logic.isHost() && !logic.getGame().allReady()) { + logic.send(new StartGameMessage(true)); + } else { + LOGGER.log(System.Logger.Level.ERROR, "You are not the host"); + } } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java index 1c501853..6861399f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java @@ -27,6 +27,7 @@ public void enter() { @Override public void exit() { + currentState.exit(); currentState= null; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java index 9747e656..f6e2ff0c 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java @@ -2,10 +2,16 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; +import pp.mdga.client.gameState.TurnState; +import pp.mdga.message.server.*; public class MovePieceState extends TurnStates { + + private final TurnState parent; + public MovePieceState(ClientState parent, ClientGameLogic logic) { super(parent, logic); + this.parent = (TurnState) parent; } @Override @@ -17,4 +23,28 @@ public void enter() { public void exit() { } + + @Override + public void received(CeremonyMessage msg){ + logic.setState(logic.getCeremony()); + } + + @Override + public void received(EndOfTurnMessage msg){ + parent.getParent().setState(parent.getParent().getWaiting()); + } + + @Override + public void received(SpectatorMessage msg){ + parent.getParent().setState(parent.getParent().getSpectator()); + } + + @Override + public void received(DiceAgainMessage msg){ + parent.setState(parent.getRollDice()); + } + + public TurnState getParent() { + return parent; + } } 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 4457dd72..ef69c671 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,7 +3,9 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; import pp.mdga.client.gameState.TurnState; +import pp.mdga.message.client.AnimationEndMessage; import pp.mdga.message.server.PlayCardMessage; +import pp.mdga.notification.PlayCardNotification; public class PlayPowerCardState extends TurnStates { @@ -18,7 +20,7 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) { @Override public void enter() { - + logic.addNotification(new PlayCardNotification(null , playCardMessage.getCard())); //TODO: get color } @Override @@ -29,4 +31,10 @@ public void exit() { public void setPlayCard(PlayCardMessage playCardMessage) { this.playCardMessage = playCardMessage; } + + @Override + public void selectAnimationEnd(){ + parent.setState(parent.getRollDice()); + logic.send(new AnimationEndMessage()); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java index b2cc1c7f..9ff3a521 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java @@ -28,8 +28,8 @@ public void enter() { state = choosePowerCardState; } - @Override public void exit() { + state.exit(); state = null; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/RollDiceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/RollDiceState.java index f83ba268..dbdecae3 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/RollDiceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/RollDiceState.java @@ -2,10 +2,17 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; +import pp.mdga.client.gameState.TurnState; +import pp.mdga.message.server.DieMessage; +import pp.mdga.message.server.NoTurnMessage; public class RollDiceState extends TurnStates { + + private final TurnState parent; + public RollDiceState(ClientState parent, ClientGameLogic logic) { super(parent, logic); + this.parent = (TurnState) parent; } @Override @@ -15,6 +22,20 @@ public void enter() { @Override public void exit() { + logic.getGame().setDiceModifier(1); + } + public TurnState getParent() { + return parent; + } + + public void received(DieMessage msg){ + logic.getGame().setDiceEyes(msg.getDiceEye()); + parent.setState(parent.getChoosePiece()); + } + + @Override + public void received(NoTurnMessage msg){ + parent.getParent().setState(parent.getParent().getWaiting()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java index dfe1fc04..870d6add 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java @@ -46,7 +46,7 @@ public void selectPiece(Piece piece) { @Override public void received(PlayCardMessage msg) { - parent.getParent().setState(parent.getParent().getPlayPowerCard()); parent.getParent().getPlayPowerCard().setPlayCard(msg); + parent.getParent().setState(parent.getParent().getPlayPowerCard()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java index cce1556e..93914db8 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java @@ -57,7 +57,7 @@ public void selectPiece(Piece piece){ @Override public void received(PlayCardMessage msg) { - parent.getParent().setState(parent.getParent().getPlayPowerCard()); parent.getParent().getPlayPowerCard().setPlayCard(msg); + parent.getParent().setState(parent.getParent().getPlayPowerCard()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java index d4d8c896..11cf206e 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java @@ -14,11 +14,6 @@ public class DieMessage extends ServerMessage { */ private final int diceEye; - /** - * The pieces that can be moved - */ - private final List moveablePieces; - /** * Constructor for Dice * @@ -28,7 +23,6 @@ public class DieMessage extends ServerMessage { public DieMessage(int diceEye, List moveablePieces) { super(); this.diceEye = diceEye; - this.moveablePieces = moveablePieces; } /** @@ -36,7 +30,6 @@ public DieMessage(int diceEye, List moveablePieces) { */ private DieMessage() { diceEye = 0; - moveablePieces = null; } /** @@ -69,15 +62,6 @@ public int getDiceEye() { return diceEye; } - /** - * Getter for the pieces that can be moved - * - * @return the pieces that can be moved - */ - public List getMoveablePieces() { - return moveablePieces; - } - /** * Accepts a visitor to process this message. * From 81d037d2321894234b8f7fbe765c2bb160ec6071 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 20:50:57 +0100 Subject: [PATCH 04/10] made the determinstartplayer machine fully functional --- .../java/pp/mdga/client/CeremonyState.java | 11 ++++++++ .../main/java/pp/mdga/client/GameState.java | 23 ++++++++++++++++ .../gameState/DetermineStartPlayerState.java | 27 +++++++++++++++++++ .../RollRankingDiceState.java | 3 ++- .../WaitRankingState.java | 5 +++- .../server/RankingResponseMessage.java | 21 +++++++++++++++ 6 files changed, 88 insertions(+), 2 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java index 12ff870a..a34d765c 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java @@ -3,6 +3,7 @@ import pp.mdga.client.ceremonyState.CeremonyStates; import pp.mdga.client.ceremonyState.PodiumState; import pp.mdga.client.ceremonyState.StatisticsState; +import pp.mdga.notification.CeremonyNotification; public class CeremonyState extends ClientState { @@ -15,9 +16,19 @@ public CeremonyState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } + + private CeremonyNotification prepareNotification(){ + CeremonyNotification notification = new CeremonyNotification(); + + //TODO: creation of the notification + + return notification; + } + @Override public void enter() { currentState = podiumState; + logic.addNotification(prepareNotification()); } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java index fa8827ed..41e3f0f0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java @@ -1,7 +1,10 @@ package pp.mdga.client; import pp.mdga.client.gameState.*; +import pp.mdga.message.server.DieMessage; import pp.mdga.message.server.PauseGameMessage; +import pp.mdga.message.server.RankingResponseMessage; +import pp.mdga.message.server.RankingRollAgainMessage; import pp.mdga.notification.InterruptNotification; public class GameState extends ClientState { @@ -40,12 +43,32 @@ public void selectAnimationEnd(){ state.selectAnimationEnd(); } + @Override + public void selectDice(){ + state.selectDice(); + } + @Override public void received(PauseGameMessage msg){ logic.enterInterrupt(); logic.addNotification(new InterruptNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor())); } + @Override + public void received(DieMessage msg){ + state.received(msg); + } + + @Override + public void received(RankingRollAgainMessage msg){ + state.received(msg); + } + + @Override + public void received(RankingResponseMessage msg){ + state.received(msg); + } + public GameStates getState(){ return state; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java index 8b6480c6..cf3c48c2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayerState.java @@ -6,6 +6,9 @@ import pp.mdga.client.gameState.determineStartPlayerState.DetermineStartPlayerStates; import pp.mdga.client.gameState.determineStartPlayerState.RollRankingDiceState; import pp.mdga.client.gameState.determineStartPlayerState.WaitRankingState; +import pp.mdga.message.server.DieMessage; +import pp.mdga.message.server.RankingResponseMessage; +import pp.mdga.message.server.RankingRollAgainMessage; public class DetermineStartPlayerState extends GameStates { @@ -36,6 +39,26 @@ public void setState(DetermineStartPlayerStates state) { this.state = state; } + @Override + public void selectDice() { + state.selectDice(); + } + + @Override + public void received(DieMessage msg){ + state.received(msg); + } + + @Override + public void received(RankingRollAgainMessage msg){ + state.received(msg); + } + + @Override + public void received(RankingResponseMessage msg){ + state.received(msg); + } + public RollRankingDiceState getRollRankingDice() { return rollRankingDiceState; } @@ -47,4 +70,8 @@ public WaitRankingState getWaitRanking() { public DetermineStartPlayerStates getState(){ return state; } + + public GameState getParent() { + return parent; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/RollRankingDiceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/RollRankingDiceState.java index 43796e7a..3c1ec5b9 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/RollRankingDiceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/RollRankingDiceState.java @@ -5,6 +5,7 @@ import pp.mdga.client.gameState.DetermineStartPlayerState; import pp.mdga.message.client.RequestDieMessage; import pp.mdga.message.server.DieMessage; +import pp.mdga.notification.DiceNowNotification; public class RollRankingDiceState extends DetermineStartPlayerStates { @@ -17,7 +18,7 @@ public RollRankingDiceState(ClientState parent, ClientGameLogic logic) { @Override public void enter() { - + logic.addNotification(new DiceNowNotification()); } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/WaitRankingState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/WaitRankingState.java index 6f470ba3..6e2a96b3 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/WaitRankingState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/WaitRankingState.java @@ -5,6 +5,7 @@ import pp.mdga.client.gameState.DetermineStartPlayerState; import pp.mdga.message.server.RankingResponseMessage; import pp.mdga.message.server.RankingRollAgainMessage; +import pp.mdga.notification.ActivePlayerNotification; public class WaitRankingState extends DetermineStartPlayerStates { @@ -32,6 +33,8 @@ public void received(RankingRollAgainMessage msg){ @Override public void received(RankingResponseMessage msg){ - //TODO: implement + logic.addNotification(new ActivePlayerNotification(logic.getGame().getPlayers().get(msg.getStartingPlayerId()).getColor())); + logic.getGame().setActiveColor(logic.getGame().getPlayers().get(msg.getStartingPlayerId()).getColor()); + parent.getParent().setState(parent.getParent().getWaiting()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/RankingResponseMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/RankingResponseMessage.java index 397ddcb1..3c8e263d 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/RankingResponseMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/RankingResponseMessage.java @@ -7,11 +7,32 @@ */ @Serializable public class RankingResponseMessage extends ServerMessage { + + private final int startingPlayerId; + + /** + * Constructs a new RankingResponse instance. + */ + public RankingResponseMessage(int startingPlayerId) { + super(); + this.startingPlayerId = startingPlayerId; + } + /** * Constructs a new RankingResponse instance. */ public RankingResponseMessage() { super(); + this.startingPlayerId = 0; + } + + /** + * The id of the starting Player. + * + * @return the id of the starting player as an int + */ + public int getStartingPlayerId() { + return startingPlayerId; } /** From 5ff56ed9d8dfccd95c3ba25c8502ab6655360c1d Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 22:23:40 +0100 Subject: [PATCH 05/10] added all necessary logic for the turn waiting class and adjusted some messages --- .../src/main/java/pp/mdga/client/MdgaApp.java | 2 +- .../mdga/client/gameState/WaitingState.java | 65 +++++++++++++++++++ .../mdga/message/server/PlayCardMessage.java | 30 ++++++++- .../notification/ThrowPieceNotification.java | 5 -- 4 files changed, 93 insertions(+), 9 deletions(-) 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 25319ac4..6ab1e04e 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 @@ -17,7 +17,7 @@ public class MdgaApp extends SimpleApplication { MdgaView view = null; private MdgaState state = MdgaState.MAIN; - private static float resolutionFactor = 1.8f; + private static float resolutionFactor = 1.0f; public static void main(String[] args) { AppSettings settings = new AppSettings(true); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java index a936fb79..2af5c94a 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java @@ -3,7 +3,12 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; import pp.mdga.client.GameState; +import pp.mdga.game.BonusCard; +import pp.mdga.game.Piece; +import pp.mdga.game.Player; +import pp.mdga.game.ShieldState; import pp.mdga.message.server.*; +import pp.mdga.notification.*; public class WaitingState extends GameStates { @@ -14,6 +19,30 @@ public WaitingState(ClientState parent, ClientGameLogic logic) { this.parent = (GameState) parent; } + private CeremonyNotification createCeremonyNotification(){ + CeremonyNotification notification = new CeremonyNotification(); + for (var player : logic.getGame().getPlayers().entrySet()){ + notification.getColors().add(player.getValue().getColor()); + notification.getNames().add(player.getValue().getName()); + notification.getSixes().add(player.getValue().getPlayerStatistic().getDiced6()); + notification.getBonusNodes().add(player.getValue().getPlayerStatistic().getActivatedBonusNodes()); + notification.getPiecesLost().add(player.getValue().getPlayerStatistic().getPiecesBeingThrown()); + notification.getPiecesThrown().add(player.getValue().getPlayerStatistic().getPiecesThrown()); + notification.getNodesMoved().add(player.getValue().getPlayerStatistic().getTraveledNodes()); + notification.getBonusCardsPlayed().add(player.getValue().getPlayerStatistic().getCardsPlayed()); + } + + notification.getNames().add("GAME OVERALL"); + notification.getNodesMoved().add(logic.getGame().getGameStatistics().getTraveledNodes()); + notification.getSixes().add(logic.getGame().getGameStatistics().getDiced6()); + notification.getPiecesThrown().add(logic.getGame().getGameStatistics().getPiecesThrown()); + notification.getPiecesLost().add(logic.getGame().getGameStatistics().getPiecesBeingThrown()); + notification.getBonusNodes().add(logic.getGame().getGameStatistics().getActivatedBonusNodes()); + notification.getBonusCardsPlayed().add(logic.getGame().getGameStatistics().getCardsPlayed()); + + return notification; + } + @Override public void enter() { @@ -26,31 +55,67 @@ public void exit() { @Override public void received(CeremonyMessage msg){ + logic.addNotification(createCeremonyNotification()); logic.setState(logic.getCeremony()); } @Override public void received(DiceNowMessage msg){ + logic.addNotification(new DiceNowNotification()); parent.setState(parent.getTurn()); } @Override public void received(DieMessage msg){ + logic.getGame().setDiceEyes(msg.getDiceEye()); + logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier())); parent.setState(parent.getAnimation()); } @Override public void received(PlayCardMessage msg){ + logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); + if (msg.getCard().equals(BonusCard.TURBO)){ + logic.getGame().setDiceModifier(msg.getDiceModifier()); + } else if (msg.getCard().equals(BonusCard.SHIELD)){ + if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier())) % 10 != 0) { + logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED); + logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); + } else { + logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.ACTIVE); + logic.addNotification(new ShieldActiveNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); + } + } else { + Piece ownPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()); + Piece enemyPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifierEnemy()); + int ownIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(ownPiece); + logic.addNotification(new SwapPieceNotification(ownPiece.getUuid(), enemyPiece.getUuid())); + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece); + logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece); + } parent.setState(parent.getAnimation()); } @Override public void received(ActivePlayerMessage msg){ + logic.addNotification(new ActivePlayerNotification(msg.getColor())); + logic.getGame().setActiveColor(msg.getColor()); parent.setState(parent.getAnimation()); } @Override public void received(MoveMessage msg){ + Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); + if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ + logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true)); + } else if (msg.isHomeMove()){ + logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); + } else { + if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { + logic.addNotification(new ThrowPieceNotification(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant().getUuid())); + } + logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove), msg.getTargetIndex())); + } parent.setState(parent.getAnimation()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PlayCardMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PlayCardMessage.java index 8c5717cf..3e1f2076 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PlayCardMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/PlayCardMessage.java @@ -20,17 +20,20 @@ public class PlayCardMessage extends ServerMessage { private final String pieceIdentifierEnemy; + private final int diceModifier; + /** * Constructs a new PlayCard message. * * @param card the card that should be played * @param pieceIdentifier the identifier of the piece that should be moved */ - public PlayCardMessage(BonusCard card, String pieceIdentifier, String pieceIdentifierEnemy) { + public PlayCardMessage(BonusCard card, String pieceIdentifier, String pieceIdentifierEnemy, int diceModifier) { super(); this.card = card; this.pieceIdentifier = pieceIdentifier; this.pieceIdentifierEnemy = pieceIdentifierEnemy; + this.diceModifier = diceModifier; } /** @@ -40,6 +43,7 @@ private PlayCardMessage() { this.pieceIdentifierEnemy = null; card = null; pieceIdentifier = null; + diceModifier = 1; } /** @@ -50,7 +54,7 @@ private PlayCardMessage() { * @return a new PlayCard message */ public static PlayCardMessage swap(String pieceIdentifier, String pieceIdentifierEnemy) { - return new PlayCardMessage(BonusCard.SWAP, pieceIdentifier, pieceIdentifierEnemy); + return new PlayCardMessage(BonusCard.SWAP, pieceIdentifier, pieceIdentifierEnemy, 1); } /** @@ -60,7 +64,17 @@ public static PlayCardMessage swap(String pieceIdentifier, String pieceIdentifie * @return a new PlayCard message */ public static PlayCardMessage shield(String pieceIdentifier) { - return new PlayCardMessage(BonusCard.SHIELD, pieceIdentifier, null); + return new PlayCardMessage(BonusCard.SHIELD, pieceIdentifier, null, 1); + } + + /** + * creates a new PlayCardMessage for a turbo card + * + * @param diceModifier the new modifier of the dice + * @return newly constructed message + */ + public static PlayCardMessage turbo(int diceModifier){ + return new PlayCardMessage(BonusCard.TURBO, null, null, diceModifier); } /** @@ -90,6 +104,16 @@ public String getPieceIdentifierEnemy() { return pieceIdentifierEnemy; } + + /** + * this method returns the dice modifier + * + * @return the dice modifier as int + */ + public int getDiceModifier(){ + return diceModifier; + } + /** * Accepts a visitor to process this message. * 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 ad81f2f8..c99b079e 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 @@ -10,11 +10,6 @@ public class ThrowPieceNotification extends Notification{ /** * This constructor is used to create a new ThrowPieceNotification - * - * @param pieceId1 the pieceId1 - * @param pieceId2 the pieceId2 - * @param nodeIndex the nodeIndex - * @param colorPiece2 the color */ public ThrowPieceNotification(UUID pieceId) { this.pieceId = pieceId; From bdc527b83ef25ccba90e4c5e514eb2f5105ef5b7 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 08:40:16 +0100 Subject: [PATCH 06/10] added more logic to the client (choosepiece and powercard) --- .../java/pp/mdga/client/ClientGameLogic.java | 4 +++ .../pp/mdga/client/gameState/GameStates.java | 30 +++++++++++++++++++ .../mdga/client/gameState/WaitingState.java | 19 +----------- .../gameState/turnState/MovePieceState.java | 6 ++++ .../turnState/PlayPowerCardState.java | 9 +++++- .../choosePieceState/NoPieceState.java | 11 ++++++- .../choosePieceState/SelectPieceState.java | 9 ++++++ .../powerCardState/ChoosePowerCardState.java | 16 ++++++++-- .../turnState/powerCardState/ShieldState.java | 4 ++- .../turnState/powerCardState/SwapState.java | 9 ++++-- .../message/server/SelectPieceMessage.java | 18 +++++++++++ .../mdga/message/server/WaitPieceMessage.java | 23 ++++++++++++++ 12 files changed, 133 insertions(+), 25 deletions(-) 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 a50ecf53..e86e1bf6 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 @@ -66,6 +66,10 @@ public boolean isHost(){ return isHost; } + public int getCalculatedMoves(){ + return game.getDiceEyes() * game.getDiceModifier(); + } + public void setHost(boolean isHost){ this.isHost = isHost; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java index 05d1c404..6be90533 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java @@ -2,9 +2,39 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; +import pp.mdga.game.BonusCard; +import pp.mdga.game.Piece; +import pp.mdga.game.ShieldState; +import pp.mdga.message.server.PlayCardMessage; +import pp.mdga.notification.ShieldActiveNotification; +import pp.mdga.notification.ShieldSuppressedNotification; +import pp.mdga.notification.SwapPieceNotification; public abstract class GameStates extends ClientState { public GameStates(ClientState parent, ClientGameLogic logic) { super(parent, logic); } + + protected void handlePowerCard(PlayCardMessage msg){ + if (msg.getCard().equals(BonusCard.TURBO)){ + logic.getGame().setDiceModifier(msg.getDiceModifier()); + } else if (msg.getCard().equals(BonusCard.SHIELD)){ + if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier())) % 10 != 0) { + logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED); + logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); + } else { + logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.ACTIVE); + logic.addNotification(new ShieldActiveNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); + } + } else { + Piece ownPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()); + Piece enemyPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifierEnemy()); + int ownIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(ownPiece); + logic.addNotification(new SwapPieceNotification(ownPiece.getUuid(), enemyPiece.getUuid())); + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece); + logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece); + } + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).removeHandCard(msg.getCard()); + logic.getGame().getDiscardPile().add(msg.getCard()); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java index 2af5c94a..8c43233e 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java @@ -75,24 +75,7 @@ public void received(DieMessage msg){ @Override public void received(PlayCardMessage msg){ logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); - if (msg.getCard().equals(BonusCard.TURBO)){ - logic.getGame().setDiceModifier(msg.getDiceModifier()); - } else if (msg.getCard().equals(BonusCard.SHIELD)){ - if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier())) % 10 != 0) { - logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED); - logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); - } else { - logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.ACTIVE); - logic.addNotification(new ShieldActiveNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); - } - } else { - Piece ownPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()); - Piece enemyPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifierEnemy()); - int ownIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(ownPiece); - logic.addNotification(new SwapPieceNotification(ownPiece.getUuid(), enemyPiece.getUuid())); - logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece); - logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece); - } + handlePowerCard(msg); parent.setState(parent.getAnimation()); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java index f6e2ff0c..a04d7e56 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/MovePieceState.java @@ -3,6 +3,7 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; import pp.mdga.client.gameState.TurnState; +import pp.mdga.message.client.AnimationEndMessage; import pp.mdga.message.server.*; public class MovePieceState extends TurnStates { @@ -24,6 +25,11 @@ public void exit() { } + @Override + public void selectAnimationEnd(){ + logic.send(new AnimationEndMessage()); + } + @Override public void received(CeremonyMessage msg){ logic.setState(logic.getCeremony()); 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 ef69c671..424cfc0c 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,9 +3,15 @@ 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 { @@ -20,7 +26,8 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) { @Override public void enter() { - logic.addNotification(new PlayCardNotification(null , playCardMessage.getCard())); //TODO: get color + logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor() , playCardMessage.getCard())); + handlePowerCard(playCardMessage); } @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 187fb4e5..b4675bd9 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 @@ -3,8 +3,12 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; import pp.mdga.client.gameState.turnState.ChoosePieceState; +import pp.mdga.game.Piece; import pp.mdga.message.server.*; import pp.mdga.message.server.StartPieceMessage; +import pp.mdga.notification.MovePieceNotification; +import pp.mdga.notification.SelectableMoveNotification; +import pp.mdga.notification.WaitMoveNotification; import java.util.ArrayList; import java.util.stream.Collectors; @@ -31,16 +35,21 @@ public void exit() { @Override public void received(SelectPieceMessage msg) { parent.setState(parent.getSelectPiece()); - parent.getSelectPiece().setPossiblePieces(msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new))); + ArrayList pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)); + parent.getSelectPiece().setPossiblePieces(pieces); + logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove())); } @Override public void received(WaitPieceMessage msg){ + logic.addNotification(new WaitMoveNotification(msg.getPieceID())); parent.setState(parent.getWaitingPiece()); } @Override public void received(StartPieceMessage msg){ + Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()); + //TODO: logic.addNotification(null); parent.setState(parent.getStartPiece()); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java index 9b7e7513..209ba093 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java @@ -6,6 +6,9 @@ import pp.mdga.game.Piece; import pp.mdga.message.client.SelectedPiecesMessage; import pp.mdga.message.server.MoveMessage; +import pp.mdga.notification.HomeMoveNotification; +import pp.mdga.notification.MovePieceNotification; +import pp.mdga.notification.SelectableMoveNotification; import java.util.ArrayList; @@ -42,6 +45,12 @@ public void selectPiece(Piece piece){ @Override public void received(MoveMessage msg){ + Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); + if(msg.isHomeMove()){ + logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex())); + } else { + logic.addNotification(new MovePieceNotification(piece.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex())); + } parent.getParent().setState(parent.getParent().getMovePiece()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ChoosePowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ChoosePowerCardState.java index 3ebb3107..ae71e54f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ChoosePowerCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ChoosePowerCardState.java @@ -7,8 +7,10 @@ import pp.mdga.message.client.NoPowerCardMessage; import pp.mdga.message.client.SelectCardMessage; import pp.mdga.message.server.DiceNowMessage; +import pp.mdga.message.server.PlayCardMessage; import pp.mdga.message.server.PossibleCardMessage; import pp.mdga.message.server.PossiblePieceMessage; +import pp.mdga.notification.SelectableCardsNotification; import java.util.ArrayList; import java.util.stream.Collectors; @@ -36,6 +38,7 @@ public void exit() { @Override public void received(PossibleCardMessage msg){ possibleCards = (ArrayList) msg.getPossibleCards(); + logic.addNotification(new SelectableCardsNotification(possibleCards)); } @Override @@ -47,6 +50,15 @@ public void selectCard(BonusCard card){ } } + @Override + public void received(PlayCardMessage msg){ + if(msg.getCard().equals(BonusCard.TURBO)){ + logic.getGame().setDiceModifier(msg.getDiceModifier()); + } else { + LOGGER.log(System.Logger.Level.ERROR, "Received card that is not turbo"); + } + } + @Override public void received(DiceNowMessage msg){ parent.getParent().setState(parent.getParent().getRollDice()); @@ -55,12 +67,12 @@ public void received(DiceNowMessage msg){ @Override public void received(PossiblePieceMessage msg){ if (msg.getEnemyPossiblePieces().isEmpty()){ - parent.setState(parent.getShield()); parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new))); + parent.setState(parent.getShield()); } else { - parent.setState(parent.getSwap()); parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new))); parent.getSwap().setPossibleEnemyPieces(msg.getEnemyPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new))); + parent.setState(parent.getSwap()); } } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java index 870d6add..2ec13dde 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/ShieldState.java @@ -19,11 +19,13 @@ public class ShieldState extends PowerCardStates { public ShieldState(ClientState parent, ClientGameLogic logic) { super(parent, logic); this.parent = (PowerCardState) parent; + possiblePieces = new ArrayList<>(); } @Override public void enter() { - possiblePieces = new ArrayList<>(); + logic.addNotification(null); + //TODO: selectable piece notification } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java index 93914db8..0e0199e9 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/powerCardState/SwapState.java @@ -6,7 +6,9 @@ import pp.mdga.game.Piece; import pp.mdga.message.client.RequestPlayCardMessage; import pp.mdga.message.server.PlayCardMessage; +import pp.mdga.notification.SelectableSwapNotification; +import java.util.UUID; import java.util.ArrayList; public class SwapState extends PowerCardStates { @@ -21,12 +23,15 @@ public class SwapState extends PowerCardStates { public SwapState(ClientState parent, ClientGameLogic logic) { super(parent, logic); this.parent = (PowerCardState) parent; + possibleOwnPieces = new ArrayList<>(); + possibleEnemyPieces = new ArrayList<>(); } @Override public void enter() { - possibleOwnPieces = new ArrayList<>(); - possibleEnemyPieces = new ArrayList<>(); + ArrayList ownPieces = new ArrayList<>(possibleOwnPieces.stream().map(Piece::getUuid).toList()); + ArrayList enemyPieces = new ArrayList<>(possibleEnemyPieces.stream().map(Piece::getUuid).toList()); + logic.addNotification(new SelectableSwapNotification(ownPieces, enemyPieces)); } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/SelectPieceMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/SelectPieceMessage.java index d1ac6dc3..22c1514e 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/SelectPieceMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/SelectPieceMessage.java @@ -42,6 +42,24 @@ public List getPieces(){ return pieces; } + /** + * returns if a move is a home move for an index + * + * @return List of boolean values + */ + public List getIsHomeMove(){ + return isHomeMove; + } + + /** + * returns the target index of the pieces + * + * @return List of integers + */ + public List getTargetIndex(){ + return targetIndex; + } + /** * Accepts a visitor to process this message. * diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/WaitPieceMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/WaitPieceMessage.java index 42743ece..528ebbe2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/WaitPieceMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/WaitPieceMessage.java @@ -2,16 +2,39 @@ import com.jme3.network.serializing.Serializable; +import java.util.UUID; + /** * A message sent by the server to the active player to choose a piece from the waiting area. */ @Serializable public class WaitPieceMessage extends ServerMessage { + + private final UUID pieceID; + + /** + * Constructs a new WaitPiece instance. + */ + public WaitPieceMessage(UUID pieceID) { + super(); + this.pieceID = pieceID; + } + /** * Constructs a new WaitPiece instance. */ public WaitPieceMessage() { super(); + this.pieceID = null; + } + + /** + * Getter for the pieceID + * + * @return the pieceID + */ + public UUID getPieceID() { + return pieceID; } /** From 789868863f033fb5961962fbc0cd4e4786133bdd Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 12:06:06 +0100 Subject: [PATCH 07/10] added some more client game logic --- .../java/pp/mdga/client/CeremonyState.java | 11 +---- .../main/java/pp/mdga/client/ClientState.java | 29 +++++++++++ .../client/ceremonyState/PodiumState.java | 1 + .../client/ceremonyState/StatisticsState.java | 5 ++ .../pp/mdga/client/gameState/GameStates.java | 9 ++++ .../mdga/client/gameState/WaitingState.java | 49 +++++++------------ .../choosePieceState/SelectPieceState.java | 8 ++- .../src/main/java/pp/mdga/game/Statistic.java | 9 ++++ 8 files changed, 80 insertions(+), 41 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java index a34d765c..38541512 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java @@ -16,19 +16,10 @@ public CeremonyState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } - - private CeremonyNotification prepareNotification(){ - CeremonyNotification notification = new CeremonyNotification(); - - //TODO: creation of the notification - - return notification; - } - @Override public void enter() { currentState = podiumState; - logic.addNotification(prepareNotification()); + logic.addNotification(createCeremonyNotification()); } @Override 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 190e4c45..97d058a5 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 @@ -4,6 +4,7 @@ import pp.mdga.game.Color; import pp.mdga.game.Piece; import pp.mdga.message.server.*; +import pp.mdga.notification.CeremonyNotification; import java.lang.System.Logger.Level; @@ -230,4 +231,32 @@ public void selectStart(){ public void selectAnimationEnd(){ LOGGER.log(Level.DEBUG, "Animation end not allowed"); } + + public void selectNext(){ + LOGGER.log(Level.DEBUG, "Next not allowed"); + } + + protected CeremonyNotification createCeremonyNotification(){ + CeremonyNotification notification = new CeremonyNotification(); + for (var player : logic.getGame().getPlayers().entrySet()){ + notification.getColors().add(player.getValue().getColor()); + notification.getNames().add(player.getValue().getName()); + notification.getSixes().add(player.getValue().getPlayerStatistic().getDiced6()); + notification.getBonusNodes().add(player.getValue().getPlayerStatistic().getActivatedBonusNodes()); + notification.getPiecesLost().add(player.getValue().getPlayerStatistic().getPiecesBeingThrown()); + notification.getPiecesThrown().add(player.getValue().getPlayerStatistic().getPiecesThrown()); + notification.getNodesMoved().add(player.getValue().getPlayerStatistic().getTraveledNodes()); + notification.getBonusCardsPlayed().add(player.getValue().getPlayerStatistic().getCardsPlayed()); + } + + notification.getNames().add("GAME OVERALL"); + notification.getNodesMoved().add(logic.getGame().getGameStatistics().getTraveledNodes()); + notification.getSixes().add(logic.getGame().getGameStatistics().getDiced6()); + notification.getPiecesThrown().add(logic.getGame().getGameStatistics().getPiecesThrown()); + notification.getPiecesLost().add(logic.getGame().getGameStatistics().getPiecesBeingThrown()); + notification.getBonusNodes().add(logic.getGame().getGameStatistics().getActivatedBonusNodes()); + notification.getBonusCardsPlayed().add(logic.getGame().getGameStatistics().getCardsPlayed()); + + return notification; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java index 199fde11..4410d8c0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java @@ -23,6 +23,7 @@ public void exit() { } + @Override public void selectNext(){ parent.setState(parent.getStatisticsState()); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java index fdc5de34..89c5e8a1 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java @@ -17,4 +17,9 @@ public void enter() { public void exit() { } + + @Override + public void selectNext(){ + logic.setState(logic.getDialogs()); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java index 6be90533..5be2d171 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java @@ -9,6 +9,7 @@ import pp.mdga.notification.ShieldActiveNotification; import pp.mdga.notification.ShieldSuppressedNotification; import pp.mdga.notification.SwapPieceNotification; +import pp.mdga.notification.ThrowPieceNotification; public abstract class GameStates extends ClientState { public GameStates(ClientState parent, ClientGameLogic logic) { @@ -37,4 +38,12 @@ protected void handlePowerCard(PlayCardMessage msg){ logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).removeHandCard(msg.getCard()); logic.getGame().getDiscardPile().add(msg.getCard()); } + + protected void throwPiece(Piece piece){ + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); + logic.getGame().getBoard().getPlayerData().get(piece.getColor()).addWaitingPiece(piece); + logic.addNotification(new ThrowPieceNotification(piece.getUuid())); + logic.getGame().getPlayerByColor(piece.getColor()).getPlayerStatistic().increasePiecesBeingThrown(); + logic.getGame().getGameStatistics().increasePiecesBeingThrown(); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java index 8c43233e..6f3708ac 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java @@ -19,30 +19,6 @@ public WaitingState(ClientState parent, ClientGameLogic logic) { this.parent = (GameState) parent; } - private CeremonyNotification createCeremonyNotification(){ - CeremonyNotification notification = new CeremonyNotification(); - for (var player : logic.getGame().getPlayers().entrySet()){ - notification.getColors().add(player.getValue().getColor()); - notification.getNames().add(player.getValue().getName()); - notification.getSixes().add(player.getValue().getPlayerStatistic().getDiced6()); - notification.getBonusNodes().add(player.getValue().getPlayerStatistic().getActivatedBonusNodes()); - notification.getPiecesLost().add(player.getValue().getPlayerStatistic().getPiecesBeingThrown()); - notification.getPiecesThrown().add(player.getValue().getPlayerStatistic().getPiecesThrown()); - notification.getNodesMoved().add(player.getValue().getPlayerStatistic().getTraveledNodes()); - notification.getBonusCardsPlayed().add(player.getValue().getPlayerStatistic().getCardsPlayed()); - } - - notification.getNames().add("GAME OVERALL"); - notification.getNodesMoved().add(logic.getGame().getGameStatistics().getTraveledNodes()); - notification.getSixes().add(logic.getGame().getGameStatistics().getDiced6()); - notification.getPiecesThrown().add(logic.getGame().getGameStatistics().getPiecesThrown()); - notification.getPiecesLost().add(logic.getGame().getGameStatistics().getPiecesBeingThrown()); - notification.getBonusNodes().add(logic.getGame().getGameStatistics().getActivatedBonusNodes()); - notification.getBonusCardsPlayed().add(logic.getGame().getGameStatistics().getCardsPlayed()); - - return notification; - } - @Override public void enter() { @@ -55,7 +31,6 @@ public void exit() { @Override public void received(CeremonyMessage msg){ - logic.addNotification(createCeremonyNotification()); logic.setState(logic.getCeremony()); } @@ -69,6 +44,10 @@ public void received(DiceNowMessage msg){ public void received(DieMessage msg){ logic.getGame().setDiceEyes(msg.getDiceEye()); logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier())); + if(msg.getDiceEye() == 6){ + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6(); + logic.getGame().getGameStatistics().increaseDiced6(); + } parent.setState(parent.getAnimation()); } @@ -76,6 +55,8 @@ public void received(DieMessage msg){ public void received(PlayCardMessage msg){ logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); handlePowerCard(msg); + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed(); + logic.getGame().getGameStatistics().increaseCardsPlayed(); parent.setState(parent.getAnimation()); } @@ -89,15 +70,23 @@ public void received(ActivePlayerMessage msg){ @Override public void received(MoveMessage msg){ Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); - if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ - logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true)); - } else if (msg.isHomeMove()){ + if (msg.isHomeMove()){ logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant(); + logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove); } else { if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { - logic.addNotification(new ThrowPieceNotification(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant().getUuid())); + throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant()); + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown(); + logic.getGame().getGameStatistics().increasePiecesThrown(); + } + if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ + logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true)); + logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove); + } else { + logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove), msg.getTargetIndex())); + logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove); } - logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove), msg.getTargetIndex())); } parent.setState(parent.getAnimation()); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java index 209ba093..89519bdc 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java @@ -8,7 +8,6 @@ import pp.mdga.message.server.MoveMessage; import pp.mdga.notification.HomeMoveNotification; import pp.mdga.notification.MovePieceNotification; -import pp.mdga.notification.SelectableMoveNotification; import java.util.ArrayList; @@ -48,7 +47,14 @@ public void received(MoveMessage msg){ Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); if(msg.isHomeMove()){ logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex())); + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); + logic.getGame().getBoard().getPlayerData().get(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece); } else { + if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { + throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant()); + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown(); + logic.getGame().getGameStatistics().increasePiecesThrown(); + } logic.addNotification(new MovePieceNotification(piece.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex())); } parent.getParent().setState(parent.getParent().getMovePiece()); 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 dab633f4..2b5e31aa 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 @@ -163,6 +163,15 @@ public void increaseTraveledNodes() { traveledNodes++; } + /** + * This method increases the value of traveledNodes by the given amount. + * + * @param nodes the amount of nodes to increase the traveledNodes by. + */ + public void increaseTraveledNodes(int nodes) { + traveledNodes += nodes; + } + /** * This method increases the value of cardsPlayed by 1. */ From 00b3ef1d803d9b9a780087e3deae4a0cefc43efa Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 12:12:37 +0100 Subject: [PATCH 08/10] added selectNext in CLG --- .../model/src/main/java/pp/mdga/client/ClientGameLogic.java | 4 ++++ 1 file changed, 4 insertions(+) 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 e86e1bf6..8e88dda5 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 @@ -223,6 +223,10 @@ public void selectPiece(UUID pieceId){ state.selectPiece(getPiece(pieceId)); } + public void selectNext(){ + state.selectNext(); + } + public void selectCard(BonusCard card){ state.selectCard(card); } From 26d2d0587d871b02bb7bc0c47cbf4bff2961fbd7 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 12:36:44 +0100 Subject: [PATCH 09/10] added the remaining logic for GameState and its substatemachines --- .../main/java/pp/mdga/client/GameState.java | 82 ++++++++++++++++++- .../mdga/client/gameState/SpectatorState.java | 60 +++++++++++++- .../pp/mdga/client/gameState/TurnState.java | 79 +++++++++++++++--- .../gameState/turnState/ChoosePieceState.java | 32 ++++++++ .../gameState/turnState/PowerCardState.java | 36 ++++++++ 5 files changed, 274 insertions(+), 15 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java index 41e3f0f0..7f04f8a8 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/GameState.java @@ -1,10 +1,9 @@ package pp.mdga.client; import pp.mdga.client.gameState.*; -import pp.mdga.message.server.DieMessage; -import pp.mdga.message.server.PauseGameMessage; -import pp.mdga.message.server.RankingResponseMessage; -import pp.mdga.message.server.RankingRollAgainMessage; +import pp.mdga.game.BonusCard; +import pp.mdga.game.Piece; +import pp.mdga.message.server.*; import pp.mdga.notification.InterruptNotification; public class GameState extends ClientState { @@ -48,6 +47,16 @@ public void selectDice(){ state.selectDice(); } + @Override + public void selectPiece(Piece piece){ + state.selectPiece(piece); + } + + @Override + public void selectCard(BonusCard card){ + state.selectCard(card); + } + @Override public void received(PauseGameMessage msg){ logic.enterInterrupt(); @@ -69,6 +78,71 @@ public void received(RankingResponseMessage msg){ state.received(msg); } + @Override + public void received(SelectPieceMessage msg){ + state.received(msg); + } + + @Override + public void received(WaitPieceMessage msg){ + state.received(msg); + } + + @Override + public void received(StartPieceMessage msg){ + state.received(msg); + } + + @Override + public void received(NoTurnMessage msg){ + state.received(msg); + } + + @Override + public void received(MoveMessage msg){ + state.received(msg); + } + + @Override + public void received(CeremonyMessage msg){ + state.received(msg); + } + + @Override + public void received(EndOfTurnMessage msg){ + state.received(msg); + } + + @Override + public void received(SpectatorMessage msg){ + state.received(msg); + } + + @Override + public void received(DiceAgainMessage msg){ + state.received(msg); + } + + @Override + public void received(PossibleCardMessage msg){ + state.received(msg); + } + + @Override + public void received(PlayCardMessage msg){ + state.received(msg); + } + + @Override + public void received(DiceNowMessage msg){ + state.received(msg); + } + + @Override + public void received(ActivePlayerMessage msg){ + state.received(msg); + } + public GameStates getState(){ return state; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/SpectatorState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/SpectatorState.java index 001454bc..2e7673fa 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/SpectatorState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/SpectatorState.java @@ -2,11 +2,18 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; -import pp.mdga.message.server.CeremonyMessage; +import pp.mdga.client.GameState; +import pp.mdga.game.Piece; +import pp.mdga.message.server.*; +import pp.mdga.notification.*; public class SpectatorState extends GameStates { + + private final GameState parent; + public SpectatorState(ClientState parent, ClientGameLogic logic) { super(parent, logic); + this.parent = (GameState) parent; } @Override @@ -23,4 +30,55 @@ public void exit() { public void received(CeremonyMessage msg){ logic.setState(logic.getCeremony()); } + + @Override + public void received(DieMessage msg){ + logic.getGame().setDiceEyes(msg.getDiceEye()); + logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier())); + if(msg.getDiceEye() == 6){ + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6(); + logic.getGame().getGameStatistics().increaseDiced6(); + } + parent.setState(parent.getAnimation()); + } + + @Override + public void received(PlayCardMessage msg){ + logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); + handlePowerCard(msg); + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed(); + logic.getGame().getGameStatistics().increaseCardsPlayed(); + parent.setState(parent.getAnimation()); + } + + @Override + public void received(ActivePlayerMessage msg){ + logic.addNotification(new ActivePlayerNotification(msg.getColor())); + logic.getGame().setActiveColor(msg.getColor()); + parent.setState(parent.getAnimation()); + } + + @Override + public void received(MoveMessage msg){ + Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); + if (msg.isHomeMove()){ + logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant(); + logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove); + } else { + if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { + throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant()); + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown(); + logic.getGame().getGameStatistics().increasePiecesThrown(); + } + if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ + logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true)); + logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove); + } else { + logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove), msg.getTargetIndex())); + logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove); + } + } + parent.setState(parent.getAnimation()); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java index 055986cf..b59a35b8 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/TurnState.java @@ -9,10 +9,9 @@ import pp.mdga.client.gameState.turnState.PowerCardState; import pp.mdga.client.gameState.turnState.RollDiceState; import pp.mdga.client.gameState.turnState.TurnStates; -import pp.mdga.message.server.CeremonyMessage; -import pp.mdga.message.server.EndOfTurnMessage; -import pp.mdga.message.server.NoTurnMessage; -import pp.mdga.message.server.SpectatorMessage; +import pp.mdga.game.BonusCard; +import pp.mdga.game.Piece; +import pp.mdga.message.server.*; public class TurnState extends GameStates { @@ -47,23 +46,83 @@ public void setState(TurnStates state){ } @Override - public void received(NoTurnMessage msg){ - parent.setState(parent.getWaiting()); + public void selectPiece(Piece piece){ + state.selectPiece(piece); } @Override - public void received(EndOfTurnMessage msg){ - parent.setState(parent.getWaiting()); + public void selectCard(BonusCard card){ + state.selectCard(card); + } + + @Override + public void selectAnimationEnd(){ + state.selectAnimationEnd(); + } + + @Override + public void received(SelectPieceMessage msg){ + state.received(msg); + } + + @Override + public void received(WaitPieceMessage msg){ + state.received(msg); + } + + @Override + public void received(StartPieceMessage msg){ + state.received(msg); + } + + @Override + public void received(NoTurnMessage msg){ + state.received(msg); + } + + @Override + public void received(MoveMessage msg){ + state.received(msg); } @Override public void received(CeremonyMessage msg){ - logic.setState(logic.getCeremony()); + state.received(msg); + } + + @Override + public void received(EndOfTurnMessage msg){ + state.received(msg); } @Override public void received(SpectatorMessage msg){ - parent.setState(parent.getSpectator()); + state.received(msg); + } + + @Override + public void received(DiceAgainMessage msg){ + state.received(msg); + } + + @Override + public void received(PossibleCardMessage msg){ + state.received(msg); + } + + @Override + public void received(PlayCardMessage msg){ + state.received(msg); + } + + @Override + public void received(DiceNowMessage msg){ + state.received(msg); + } + + @Override + public void received(DieMessage msg){ + state.received(msg); } public ChoosePieceState getChoosePiece() { diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java index 6861399f..b1a0c7e3 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/ChoosePieceState.java @@ -4,6 +4,8 @@ import pp.mdga.client.ClientState; import pp.mdga.client.gameState.TurnState; import pp.mdga.client.gameState.turnState.choosePieceState.*; +import pp.mdga.game.Piece; +import pp.mdga.message.server.*; public class ChoosePieceState extends TurnStates { @@ -37,6 +39,36 @@ public void setState(ChoosePieceStates state){ currentState.enter(); } + @Override + public void selectPiece(Piece piece){ + currentState.selectPiece(piece); + } + + @Override + public void received(SelectPieceMessage msg){ + currentState.received(msg); + } + + @Override + public void received(WaitPieceMessage msg){ + currentState.received(msg); + } + + @Override + public void received(StartPieceMessage msg){ + currentState.received(msg); + } + + @Override + public void received(NoTurnMessage msg){ + currentState.received(msg); + } + + @Override + public void received(MoveMessage msg){ + currentState.received(msg); + } + public NoPieceState getNoPiece(){ return noPieceState; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java index 9ff3a521..fd80b68d 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/PowerCardState.java @@ -7,6 +7,12 @@ import pp.mdga.client.gameState.turnState.powerCardState.PowerCardStates; import pp.mdga.client.gameState.turnState.powerCardState.ShieldState; import pp.mdga.client.gameState.turnState.powerCardState.SwapState; +import pp.mdga.game.BonusCard; +import pp.mdga.game.Piece; +import pp.mdga.message.server.DiceNowMessage; +import pp.mdga.message.server.PlayCardMessage; +import pp.mdga.message.server.PossibleCardMessage; +import pp.mdga.message.server.PossiblePieceMessage; public class PowerCardState extends TurnStates { @@ -39,6 +45,36 @@ public void setState(PowerCardStates state) { this.state = state; } + @Override + public void received(PossibleCardMessage msg){ + state.received(msg); + } + + @Override + public void received(PlayCardMessage msg){ + state.received(msg); + } + + @Override + public void received(DiceNowMessage msg){ + state.received(msg); + } + + @Override + public void received(PossiblePieceMessage msg){ + state.received(msg); + } + + @Override + public void selectCard(BonusCard card) { + state.selectCard(card); + } + + @Override + public void selectPiece(Piece piece) { + state.selectPiece(piece); + } + public ChoosePowerCardState getChoosePowerCard() { return choosePowerCardState; } From e70331d85d2f55cd3244c856b930b58ac7bcab8c Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sun, 1 Dec 2024 13:56:31 +0100 Subject: [PATCH 10/10] changed parameter of DieMessage and included the force resumgame logic in intterrupt --- .../java/pp/mdga/client/ClientGameLogic.java | 4 +++ .../main/java/pp/mdga/client/ClientState.java | 4 +++ .../java/pp/mdga/client/InterruptState.java | 8 ++++++ .../pp/mdga/message/server/DieMessage.java | 26 ++----------------- 4 files changed, 18 insertions(+), 24 deletions(-) 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 8e88dda5..17f30412 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 @@ -267,6 +267,10 @@ public void selectStart(){ state.selectStart(); } + public void selectResume(){ + state.selectResume(); + } + public void setState(ClientState state){ this.state.exit(); state.enter(); 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 97d058a5..336912a9 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 @@ -236,6 +236,10 @@ public void selectNext(){ LOGGER.log(Level.DEBUG, "Next not allowed"); } + public void selectResume(){ + LOGGER.log(Level.DEBUG, "Resume not allowed"); + } + protected CeremonyNotification createCeremonyNotification(){ CeremonyNotification notification = new CeremonyNotification(); for (var player : logic.getGame().getPlayers().entrySet()){ 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 7ea0e21d..1537b748 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 @@ -1,5 +1,6 @@ package pp.mdga.client; +import pp.mdga.message.client.ForceContinueGameMessage; import pp.mdga.message.server.ResumeGameMessage; import pp.mdga.notification.ResumeNotification; @@ -29,6 +30,13 @@ public ClientState getPreviousState() { return previousState; } + @Override + public void selectResume(){ + if(logic.isHost()){ + logic.send(new ForceContinueGameMessage()); + } + } + public void received(ResumeGameMessage msg) { //TODO: logic.addNotification(new ResumeNotification()); logic.setState(previousState); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java index 11cf206e..abf018a9 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/DieMessage.java @@ -18,9 +18,8 @@ public class DieMessage extends ServerMessage { * Constructor for Dice * * @param diceEye the eye of the dice - * @param moveablePieces the pieces that can be moved */ - public DieMessage(int diceEye, List moveablePieces) { + public DieMessage(int diceEye) { super(); this.diceEye = diceEye; } @@ -28,31 +27,10 @@ public DieMessage(int diceEye, List moveablePieces) { /** * Default constructor for serialization purposes. */ - private DieMessage() { + public DieMessage() { diceEye = 0; } - /** - * Constructor for inactivePlayer - * - * @param diceEye the eye of the dice - * @return a new Dice object - */ - public static DieMessage inactivePlayer(int diceEye) { - return new DieMessage(diceEye, null); - } - - /** - * Constructor for activePlayer - * - * @param diceEye the eye of the dice - * @param moveablePieces the pieces that can be moved - * @return a new Dice object - */ - public static DieMessage activePlayer(int diceEye, List moveablePieces) { - return new DieMessage(diceEye, moveablePieces); - } - /** * Getter for the eye of the dice *