added new notifications for client-view communication

This commit is contained in:
Cedric Beck
2024-11-29 15:23:34 +01:00
parent 7690340b8f
commit 67bb30d124
11 changed files with 218 additions and 152 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -1,8 +1,4 @@
package pp.mdga.notification;
public abstract class Notification {
public void accept(){
}
}

View File

@@ -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;
}
}

View File

@@ -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<UUID> 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<UUID> 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<UUID> getPiecesList() {
return piecesList;
}
}

View File

@@ -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<UUID> pieces;
/**
* List of integers representing the target nodes the pieces can move to.
*/
private final List<Integer> 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<Boolean> 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<UUID> pieces, List<Integer> moveIndexe, List<Boolean> 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<UUID> getPieces() {
return pieces;
}
/**
* Gets the list of target nodes for the moves.
*
* @return a list of integers representing the target nodes
*/
public List<Integer> 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<Boolean> getHomeMoves() {
return homeMoves;
}
}

View File

@@ -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<UUID> selectablePieces;
/**
* @param selectablePieces
*/
SelectablePiecesNotification(List<UUID> selectablePieces){
this.selectablePieces = selectablePieces;
}
/**
* @return List<UUID>
*/
public List<UUID> getSelectablePieces(){
return selectablePieces;
}
}

View File

@@ -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<UUID> ownPieces;
/**
* List of UUIDs representing the opponent's pieces available for selection.
*/
private final List<UUID> 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<UUID> ownPieces, List<UUID> 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<UUID> 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<UUID> getEnemyPieces() {
return enemyPieces;
}
}

View File

@@ -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;

View File

@@ -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;
}
}