From 67bb30d124b7529b387ad3834eebc80860878276 Mon Sep 17 00:00:00 2001 From: Cedric Beck Date: Fri, 29 Nov 2024 15:23:34 +0100 Subject: [PATCH 1/8] added new notifications for client-view communication --- .../notification/AcquireCardNotification.java | 10 ++- .../notification/MovePieceNotification.java | 75 ++++++++++++++----- .../MoveThrowPieceNotification.java | 64 ---------------- .../pp/mdga/notification/Notification.java | 4 - .../notification/PieceInGameNotification.java | 37 --------- .../PlayerInGameNotification.java | 11 ++- .../SelectableMoveNotification.java | 66 ++++++++++++++++ .../SelectablePiecesNotification.java | 26 ------- .../SelectableSwapNotification.java | 49 ++++++++++++ .../notification/SwapPieceNotification.java | 2 +- .../notification/ThrowPieceNotification.java | 26 +++++++ 11 files changed, 218 insertions(+), 152 deletions(-) delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/notification/MoveThrowPieceNotification.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/notification/PieceInGameNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java delete mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectablePiecesNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp/mdga/notification/ThrowPieceNotification.java diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java index 6a214f90..5a4afff7 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/AcquireCardNotification.java @@ -1,5 +1,7 @@ package pp.mdga.notification; +import pp.mdga.game.BonusCard; + import java.util.UUID; /** @@ -8,12 +10,14 @@ public class AcquireCardNotification extends Notification{ private UUID cardId; + private BonusCard bonusCard; /** * Constructor. * @param cardId The id of the card that was acquired. */ - public AcquireCardNotification(UUID cardId) { + public AcquireCardNotification(BonusCard bonusCard, UUID cardId) { + this.bonusCard = bonusCard; this.cardId = cardId; } @@ -24,4 +28,8 @@ public AcquireCardNotification(UUID cardId) { public UUID getCardId() { return cardId; } + + public BonusCard getBonusCard() { + return bonusCard; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java index 7a5ed1d1..610a9182 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/MovePieceNotification.java @@ -2,37 +2,76 @@ import pp.mdga.game.Color; +import java.util.UUID; + /** * Notification that a piece has been moved. */ public class MovePieceNotification extends Notification { - private Color color; - private int nodeIndex; + /** + * The unique identifier of the piece being moved. + */ + private final UUID piece; /** - * Constructor. - * @param color the color of the piece that has been moved. - * @param nodeIndex the index of the node the piece has been moved to. + * The index of the node from which the piece started moving. + * Ignored if {@code moveStart} is {@code true}. */ - MovePieceNotification(Color color, int nodeIndex) { - this.color = color; - this.nodeIndex = nodeIndex; + private final int startIndex; + + /** + * The index of the node to which the piece is moving. + * If {@code moveStart} is {@code true}, this index represents the start node. + */ + private final int moveIndex; + + /** + * Flag indicating that the piece ({@code uuid}) is moving from waiting area to the startNode. + */ + private final boolean moveStart; + + /** + * Constructs a notification for a piece start movement. + * + * @param piece the unique identifier of the piece + * @param moveIndex the destination node index + * @param moveStart whether to ignore {@code startIndex} and use {@code moveIndex} as the start node + */ + public MovePieceNotification(UUID piece, int moveIndex, boolean moveStart) { + this.piece = piece; + this.startIndex = 0; + this.moveIndex = moveIndex; + this.moveStart = moveStart; } /** - * Get the color of the piece that has been moved. - * @return the color of the piece that has been moved. + * Constructs a notification for a piece infield move with {@code moveStart} set to {@code false}. + * + * @param piece the unique identifier of the piece + * @param startIndex the starting node index + * @param moveIndex the destination node index */ - public Color getColor() { - return color; + public MovePieceNotification(UUID piece, int startIndex, int moveIndex) { + this.piece = piece; + this.startIndex = startIndex; + this.moveIndex = moveIndex; + this.moveStart = false; } - /** - * Get the index of the node the piece has been moved to. - * @return the index of the node the piece has been moved to. - */ - public int getNodeIndex() { - return nodeIndex; + public int getMoveIndex() { + return moveIndex; + } + + public int getStartIndex() { + return startIndex; + } + + public UUID getPiece() { + return piece; + } + + public boolean isMoveStart() { + return moveStart; } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/MoveThrowPieceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/MoveThrowPieceNotification.java deleted file mode 100644 index d9da6d38..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/MoveThrowPieceNotification.java +++ /dev/null @@ -1,64 +0,0 @@ -package pp.mdga.notification; - -import pp.mdga.game.Color; - -import java.util.UUID; - -public class MoveThrowPieceNotification extends Notification{ - - private UUID pieceId1; - private UUID pieceId2; - private int nodeIndex; - private Color colorPiece2; - - /** - * This constructor is used to create a new MoveThrowPieceNotification - * - * @param pieceId1 the pieceId1 - * @param pieceId2 the pieceId2 - * @param nodeIndex the nodeIndex - * @param colorPiece2 the color - */ - public MoveThrowPieceNotification(UUID pieceId1, UUID pieceId2, int nodeIndex, Color colorPiece2) { - this.pieceId1 = pieceId1; - this.pieceId2 = pieceId2; - this.nodeIndex = nodeIndex; - this.colorPiece2 = colorPiece2; - } - - /** - * This method returns the pieceId1 - * - * @return the pieceId1 - */ - public UUID getPieceId1() { - return pieceId1; - } - - /** - * This method returns the pieceId2 - * - * @return the pieceId2 - */ - public UUID getPieceId2() { - return pieceId2; - } - - /** - * This method returns the nodeIndex - * - * @return the nodeIndex - */ - public int getNodeIndex() { - return nodeIndex; - } - - /** - * This method returns the color - * - * @return the color - */ - public Color getColor() { - return colorPiece2; - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java index 3302d8a3..3f8be5da 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/Notification.java @@ -1,8 +1,4 @@ package pp.mdga.notification; public abstract class Notification { - - public void accept(){ - - } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PieceInGameNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PieceInGameNotification.java deleted file mode 100644 index 7afce473..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PieceInGameNotification.java +++ /dev/null @@ -1,37 +0,0 @@ -package pp.mdga.notification; - -import pp.mdga.game.Color; - -import java.util.UUID; - -/** - * Notification that a piece is in the game - */ -public class PieceInGameNotification extends Notification{ - private Color color; - private UUID id; - - /** - * Constructor - * @param color the color of the piece - * @param id the id of the piece - */ - PieceInGameNotification(Color color, UUID id) { - this.color = color; - this.id = id; - } - - /** - * @return the color of the piece - */ - public Color getColor() { - return null; - } - - /** - * @return the id of the piece - */ - public UUID getId() { - return null; - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java index 1db710c9..57552a0c 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayerInGameNotification.java @@ -2,6 +2,9 @@ import pp.mdga.game.Color; +import java.util.List; +import java.util.UUID; + /** * Notification that a player is in the game. */ @@ -9,15 +12,17 @@ public class PlayerInGameNotification extends Notification { private Color color; private String name; + private List piecesList; /** * Constructor. * @param color the color of the player that is in the game. * @param name the name of the player that is in the game. */ - PlayerInGameNotification(Color color, String name) { + public PlayerInGameNotification(Color color, List piecesList, String name) { this.color = color; this.name = name; + this.piecesList = piecesList; } /** @@ -35,4 +40,8 @@ public Color getColor() { public String getName() { return name; } + + public List getPiecesList() { + return piecesList; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java new file mode 100644 index 00000000..cd7fe627 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableMoveNotification.java @@ -0,0 +1,66 @@ +package pp.mdga.notification; + +import java.util.List; +import java.util.UUID; + +/** + * Notification for selecting pieces and their possible moves. + */ +public class SelectableMoveNotification extends Notification{ + + /** + * List of UUIDs representing the pieces that can be moved based on the dice roll. + */ + private final List pieces; + + /** + * List of integers representing the target nodes the pieces can move to. + */ + private final List moveIndexe; + + /** + * List of booleans indicating whether the corresponding target nodes are in the home area. + * {@code true} if the target node is in the home area, {@code false} if in the infield. + */ + private final List homeMoves; + + /** + * Constructs a notification for selectable piece moves. + * + * @param pieces the list of pieces that can be moved + * @param moveIndexe the list of target nodes for the moves + * @param homeMoves the list indicating if the target nodes are in the home area + */ + public SelectableMoveNotification(List pieces, List moveIndexe, List homeMoves) { + this.pieces = pieces; + this.moveIndexe = moveIndexe; + this.homeMoves = homeMoves; + } + + /** + * Gets the list of pieces that can be moved. + * + * @return a list of UUIDs representing the movable pieces + */ + public List getPieces() { + return pieces; + } + + /** + * Gets the list of target nodes for the moves. + * + * @return a list of integers representing the target nodes + */ + public List getMoveIndexe() { + return moveIndexe; + } + + /** + * Gets the list indicating whether the target nodes are in the home area. + * + * @return a list of booleans, {@code true} if the target node is in the home area, {@code false} otherwise + */ + public List getHomeMoves() { + return homeMoves; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectablePiecesNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectablePiecesNotification.java deleted file mode 100644 index 7179a721..00000000 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectablePiecesNotification.java +++ /dev/null @@ -1,26 +0,0 @@ -package pp.mdga.notification; - -import java.util.List; -import java.util.UUID; - -/** - * Notification to inform the client about the selectable pieces. - */ -public class SelectablePiecesNotification extends Notification{ - - private List selectablePieces; - - /** - * @param selectablePieces - */ - SelectablePiecesNotification(List selectablePieces){ - this.selectablePieces = selectablePieces; - } - - /** - * @return List - */ - public List getSelectablePieces(){ - return selectablePieces; - } -} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java new file mode 100644 index 00000000..b7102bd7 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableSwapNotification.java @@ -0,0 +1,49 @@ +package pp.mdga.notification; + +import java.util.List; +import java.util.UUID; + +/** + * Notification for selecting pieces for swapcard. + */ +public class SelectableSwapNotification extends Notification{ + + /** + * List of UUIDs representing the player's own pieces available for selection. + */ + private final List ownPieces; + + /** + * List of UUIDs representing the opponent's pieces available for selection. + */ + private final List enemyPieces; + + /** + * Constructs a notification for selecting pieces for swapcard. + * + * @param ownPieces the list of the player's own pieces + * @param enemyPieces the list of the opponent's pieces + */ + public SelectableSwapNotification(List ownPieces, List enemyPieces) { + this.ownPieces = ownPieces; + this.enemyPieces = enemyPieces; + } + + /** + * Gets the list of the player's own pieces available for selection. + * + * @return a list of UUIDs representing the player's own pieces + */ + public List getOwnPieces() { + return ownPieces; + } + + /** + * Gets the list of the opponent's pieces available for selection. + * + * @return a list of UUIDs representing the opponent's pieces + */ + public List getEnemyPieces() { + return enemyPieces; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java index 2032f66a..c66597b0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SwapPieceNotification.java @@ -15,7 +15,7 @@ public class SwapPieceNotification extends Notification { * @param firstPiece the UUID of the first piece that has been swapped. * @param secondPiece the UUID of the second piece that has been swapped. */ - SwapPieceNotification(UUID firstPiece, UUID secondPiece) { + public SwapPieceNotification(UUID firstPiece, UUID secondPiece) { assert(!firstPiece.equals(secondPiece)); this.firstPiece = firstPiece; this.secondPiece = secondPiece; 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 new file mode 100644 index 00000000..ad81f2f8 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ThrowPieceNotification.java @@ -0,0 +1,26 @@ +package pp.mdga.notification; + +import pp.mdga.game.Color; + +import java.util.UUID; + +public class ThrowPieceNotification extends Notification{ + + private UUID pieceId; + + /** + * 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; + } + + public UUID getPieceId() { + return pieceId; + } +} From 4d6cd63a3defcf129203f311e77e03afa1d91529 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 11:24:46 +0100 Subject: [PATCH 2/8] made all notifications constructors public --- .../mdga/notification/ActivePlayerNotification.java | 2 +- .../pp/mdga/notification/CeremonyNotification.java | 2 +- .../pp/mdga/notification/DiceNowNotification.java | 2 +- .../pp/mdga/notification/DicingNotification.java | 2 +- .../pp/mdga/notification/DrawCardNotification.java | 2 +- .../java/pp/mdga/notification/GameNotification.java | 2 +- .../pp/mdga/notification/HomeMoveNotification.java | 2 +- .../pp/mdga/notification/InterruptNotification.java | 6 +++--- .../mdga/notification/LobbyDialogNotification.java | 2 +- .../pp/mdga/notification/PlayCardNotification.java | 2 +- .../pp/mdga/notification/ResumeNotification.java | 2 +- .../pp/mdga/notification/RollDiceNotification.java | 2 +- .../notification/SelectableCardsNotification.java | 2 +- .../mdga/notification/StartDialogNotification.java | 2 +- .../pp/mdga/notification/TskSelectNotification.java | 13 +------------ .../mdga/notification/TskUnselectNotification.java | 2 +- 16 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java index e557e8ce..4efdb343 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ActivePlayerNotification.java @@ -12,7 +12,7 @@ public class ActivePlayerNotification extends Notification { */ private Color color; - ActivePlayerNotification(Color color) { + public ActivePlayerNotification(Color color) { this.color = color; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java index 3f88eb8a..20a270dc 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/CeremonyNotification.java @@ -7,6 +7,6 @@ public class CeremonyNotification extends Notification{ /** * Constructor */ - CeremonyNotification() { + public CeremonyNotification() { } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java index fce8c9b1..68064cfe 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DiceNowNotification.java @@ -8,6 +8,6 @@ public class DiceNowNotification extends Notification { /** * Constructor. */ - DiceNowNotification() { + public DiceNowNotification() { } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java index 5c1c7ecf..4e9f3145 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DicingNotification.java @@ -13,7 +13,7 @@ public class DicingNotification extends Notification{ * Constructor. * @param color The color of the player that diced. */ - DicingNotification(Color color) { + public DicingNotification(Color color) { this.color = color; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java index 2de500c0..5114fd15 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/DrawCardNotification.java @@ -15,7 +15,7 @@ public class DrawCardNotification extends Notification { * @param color the color of the player who drew the card * @param card the card that was drawn */ - DrawCardNotification(Color color, BonusCard card) { + public DrawCardNotification(Color color, BonusCard card) { this.color = color; this.card = card; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java index 90c60694..d1864bbd 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/GameNotification.java @@ -7,6 +7,6 @@ public class GameNotification extends Notification{ /** * Constructor */ - GameNotification() { + public GameNotification() { } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java index 48cecc52..ffa7d2e1 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/HomeMoveNotification.java @@ -16,7 +16,7 @@ public class HomeMoveNotification extends Notification { * @param pieceId the piece id * @param homeIndex the home index */ - HomeMoveNotification(UUID pieceId, int homeIndex) { + public HomeMoveNotification(UUID pieceId, int homeIndex) { this.pieceId = pieceId; this.homeIndex = homeIndex; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java index e9a61de6..bb8fb784 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/InterruptNotification.java @@ -10,14 +10,14 @@ public class InterruptNotification extends Notification { private Color color; /** - * @param color the color of the player who drew the card + * @param color the color of the player who disconnected */ - InterruptNotification(Color color) { + public InterruptNotification(Color color) { this.color = color; } /** - * @return the color of the player who drew the card + * @return the color of the player who disconnected */ public Color getColor() { return color; diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java index 7c1a4adf..dcea5094 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/LobbyDialogNotification.java @@ -7,6 +7,6 @@ public class LobbyDialogNotification extends Notification{ /** * Constructor */ - LobbyDialogNotification() { + public LobbyDialogNotification() { } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java index d554a0e6..dd9cf9d4 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/PlayCardNotification.java @@ -16,7 +16,7 @@ public class PlayCardNotification extends Notification { * @param color the color of the player that played the card. * @param card the card that was played. */ - PlayCardNotification(Color color, BonusCard card) { + public PlayCardNotification(Color color, BonusCard card) { this.color = color; this.card = card; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java index 98533e06..5ef4bd34 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/ResumeNotification.java @@ -13,7 +13,7 @@ public class ResumeNotification extends Notification { * Constructor. * @param color the color of the player that is in the game. */ - ResumeNotification(Color color) { + public ResumeNotification(Color color) { this.color = color; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java index b6bd27c3..3f778d3f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/RollDiceNotification.java @@ -17,7 +17,7 @@ public class RollDiceNotification extends Notification{ * @param eyes the number of eyes that were rolled. * @param moveNumber the number of the move that was made. */ - RollDiceNotification(Color color, int eyes, int moveNumber) { + public RollDiceNotification(Color color, int eyes, int moveNumber) { this.color = color; this.eyes = eyes; this.moveNumber = moveNumber; diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java index 925bde75..308edce2 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/SelectableCardsNotification.java @@ -14,7 +14,7 @@ public class SelectableCardsNotification extends Notification { * Constructor. * @param cards The list of cards that the player can choose from. */ - SelectableCardsNotification(List cards) { + public SelectableCardsNotification(List cards) { this.cards = cards; } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java index f2458c14..3e72cc29 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/StartDialogNotification.java @@ -7,6 +7,6 @@ public class StartDialogNotification extends Notification{ /** * Constructor */ - StartDialogNotification() { + public StartDialogNotification() { } } 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 5b99f0e7..2d0f1c49 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 @@ -9,18 +9,15 @@ public class TskSelectNotification extends Notification{ private Color color; private String name; - private boolean self; /** * Constructor. * @param color the color of the player that is in the game. * @param name the name of the player that is in the game. - * @param self true if it was the local player selecting the tsk, false otherwise */ - TskSelectNotification(Color color, String name, boolean self) { + public TskSelectNotification(Color color, String name) { this.color = color; this.name = name; - this.self = self; } /** @@ -38,12 +35,4 @@ public Color getColor() { public String getName() { return name; } - - /** - * Tells if it was the local player selecting this tsk. - * @return ture if it was the local player selecting the tsk. - */ - public boolean isSelf() { - return self; - } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java b/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java index 0f96beb1..4a036d46 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/notification/TskUnselectNotification.java @@ -10,7 +10,7 @@ public class TskUnselectNotification extends Notification{ * Constructor * @param color */ - TskUnselectNotification(Color color){ + public TskUnselectNotification(Color color){ this.color = color; } From 0487ff0238ae93f1068c5a6c02ac69a5f946f0f2 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 13:02:23 +0100 Subject: [PATCH 3/8] modified messages to work with piece uuid instead of an identifier. --- .../mdga/client/gameState/WaitingState.java | 23 ++++++++++--- .../src/main/java/pp/mdga/game/Board.java | 2 +- .../pp/mdga/message/server/MoveMessage.java | 34 ++++++++++++++++++- .../message/server/SelectPieceMessage.java | 10 +++++- .../message/server/StartPieceMessage.java | 19 ++++++++++- 5 files changed, 79 insertions(+), 9 deletions(-) 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 4b6f3f87..a936fb79 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,9 +3,7 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; import pp.mdga.client.GameState; -import pp.mdga.message.server.CeremonyMessage; -import pp.mdga.message.server.DiceNowMessage; -import pp.mdga.message.server.EndOfTurnMessage; +import pp.mdga.message.server.*; public class WaitingState extends GameStates { @@ -37,7 +35,22 @@ public void received(DiceNowMessage msg){ } @Override - public void received(EndOfTurnMessage msg){ - parent.setState(parent.getWaiting()); + public void received(DieMessage msg){ + parent.setState(parent.getAnimation()); + } + + @Override + public void received(PlayCardMessage msg){ + parent.setState(parent.getAnimation()); + } + + @Override + public void received(ActivePlayerMessage msg){ + parent.setState(parent.getAnimation()); + } + + @Override + public void received(MoveMessage msg){ + parent.setState(parent.getAnimation()); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java index 82554248..26af00c7 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Board.java @@ -7,7 +7,7 @@ */ public class Board { private Map playerData; - private Node[] infield; + private final Node[] infield; /** * This constructor is used to create a new board diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/MoveMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/MoveMessage.java index 27dbe370..5c14f8a0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/MoveMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/MoveMessage.java @@ -12,14 +12,26 @@ public class MoveMessage extends ServerMessage { */ private final String pieceIdentifier; + /** + * The index of the target node; + */ + private final int targetIndex; + + /** + * True if the pieces move into the home. + */ + private final boolean isHomeMove; + /** * Constructs a new MoveMessage instance. * * @param identifier the identifier of the piece that should be moved */ - public MoveMessage(String identifier) { + public MoveMessage(String identifier, boolean isHomeMove, int targetIndex) { super(); this.pieceIdentifier = identifier; + this.isHomeMove = isHomeMove; + this.targetIndex = targetIndex; } /** @@ -27,6 +39,8 @@ public MoveMessage(String identifier) { */ private MoveMessage() { pieceIdentifier = null; + targetIndex = 0; + isHomeMove = false; } /** @@ -38,6 +52,24 @@ public String getIdentifier() { return pieceIdentifier; } + /** + * Returns the index of the target Node. + * + * @return the target index + */ + public int getTargetIndex(){ + return targetIndex; + } + + /** + * Returns a boolean based on if it is a home move or not. + * + * @return the boolean isHomeMove. + */ + public boolean isHomeMove(){ + return isHomeMove; + } + /** * Accepts a visitor to process this message. * 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 b1220d8d..d1ac6dc3 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 @@ -8,14 +8,20 @@ public class SelectPieceMessage extends ServerMessage{ private final List pieces; + private final List isHomeMove; + private final List targetIndex; /** * Constructs a new SelectPiece instance. * * @param pieces the pieces to be selected + * @param isHomeMove the List of booleans of isHomeMove of the pieces + * @param targetIndex the List of indexes of target nodes of the pieces */ - public SelectPieceMessage(List pieces){ + public SelectPieceMessage(List pieces, List isHomeMove, List targetIndex){ this.pieces = pieces; + this.isHomeMove = isHomeMove; + this.targetIndex = targetIndex; } /** @@ -23,6 +29,8 @@ public SelectPieceMessage(List pieces){ */ public SelectPieceMessage(){ pieces = null; + isHomeMove = null; + targetIndex = null; } /** diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/StartPieceMessage.java b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/StartPieceMessage.java index 51910961..9ac17778 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/message/server/StartPieceMessage.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/message/server/StartPieceMessage.java @@ -12,14 +12,21 @@ public class StartPieceMessage extends ServerMessage { */ private final String pieceIdentifier; + /** + * The target index of the move; + */ + private final int targetIndex; + /** * Constructs a new StartPiece instance with the specified piece identifier. * * @param pieceIdentifier the identifier for the piece + * @param targetIndex the index of the targetNode */ - public StartPieceMessage(String pieceIdentifier) { + public StartPieceMessage(String pieceIdentifier, int targetIndex) { super(); this.pieceIdentifier = pieceIdentifier; + this.targetIndex = targetIndex; } /** @@ -28,6 +35,7 @@ public StartPieceMessage(String pieceIdentifier) { private StartPieceMessage() { super(); this.pieceIdentifier = ""; + this.targetIndex = 0; } /** @@ -39,6 +47,15 @@ public String getPieceIdentifier() { return pieceIdentifier; } + /** + * Gets the index of the target node + * + * @return the index of the target node as int. + */ + public int getTargetIndex(){ + return targetIndex; + } + /** * Accepts a visitor to process this message. * From 0297193be1b5678f8d647920b5924ca6c173cd25 Mon Sep 17 00:00:00 2001 From: Fleischer Hanno Date: Sat, 30 Nov 2024 16:23:09 +0100 Subject: [PATCH 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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;