From 67bb30d124b7529b387ad3834eebc80860878276 Mon Sep 17 00:00:00 2001 From: Cedric Beck Date: Fri, 29 Nov 2024 15:23:34 +0100 Subject: [PATCH] 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; + } +}