added message contents to the messages

addedn the conentents for all messages regarding the BPMN diagramm and own interpretation.
also created an identifier for pieces to be used for network communication between server and client so that they talk about the same piece.
This commit is contained in:
Fleischer Hanno
2024-11-23 12:26:20 +01:00
committed by Felix
parent 6dfb2980fa
commit e3d5d8e2e9
21 changed files with 398 additions and 4 deletions

View File

@@ -405,4 +405,17 @@ public void notifyObservers() {
observer.update();
}
}
/**
* This method returns the piece through its identifier.
*
* @param identifier the identifier of the piece
* @return the piece
*/
public Piece getPieceThroughIdentifier(String identifier) {
String[] parts = identifier.split("-");
Color color = Color.valueOf(parts[0]);
int index = Integer.parseInt(parts[1]);
return board.getPlayerData().get(color).getPieces()[index];
}
}

View File

@@ -7,6 +7,7 @@ public class Piece {
private ShieldState shield;
private PieceState state;
private final Color color;
private final int id;
/**
* This constructor is used to create a new Piece
@@ -14,10 +15,11 @@ public class Piece {
* @param color the color of the piece
* @param state the state of the piece
*/
public Piece(Color color, PieceState state) {
public Piece(Color color, PieceState state, int id) {
this.color = color;
this.state = state;
shield = ShieldState.NONE;
this.id = id;
}
/**
@@ -82,4 +84,13 @@ public boolean isSuppressed() {
public Color getColor() {
return color;
}
/**
* This method is used to get the color of the piece
*
* @return the color of the piece
*/
public String getIdentifier() {
return color.toString() + "-" + id;
}
}

View File

@@ -19,7 +19,7 @@ public PlayerData(Color color) {
waitingArea = new Piece[4];
for (int i = 0; i < 4; i++) {
homeNodes[i] = new HomeNode();
pieces[i] = new Piece(color, PieceState.WAITING);
pieces[i] = new Piece(color, PieceState.WAITING, i);
waitingArea[i] = pieces[i];
}
}

View File

@@ -1,9 +1,28 @@
package pp.mdga.message.client;
import pp.mdga.game.Color;
public class RequestMove extends ClientMessage {
private final String pieceIdentifier;
/** Constructor for RequestMove
* @param pieceIdentifier the piece identifier
*/
public RequestMove(String pieceIdentifier) {
this.pieceIdentifier = pieceIdentifier;
}
/** Getter for the piece identifier
* @return the piece identifier
*/
public String getPieceIdentifier() {
return pieceIdentifier;
}
@Override
public String toString() {
return "null";
return pieceIdentifier;
}
@Override

View File

@@ -1,9 +1,28 @@
package pp.mdga.message.client;
import pp.mdga.game.BonusCard;
public class RequestPlayCard extends ClientMessage {
private final BonusCard card;
private final String pieceIdentifier;
public RequestPlayCard(BonusCard card, String pieceIdentifier) {
this.pieceIdentifier = pieceIdentifier;
this.card = card;
}
public BonusCard getCard() {
return card;
}
public String getPieceIdentifier() {
return pieceIdentifier;
}
@Override
public String toString() {
return "null";
return card.toString();
}
@Override

View File

@@ -1,6 +1,19 @@
package pp.mdga.message.client;
import pp.mdga.game.BonusCard;
public class SelectCard extends ClientMessage {
private final BonusCard card;
public SelectCard(BonusCard card) {
this.card = card;
}
public BonusCard getCard() {
return card;
}
@Override
public String toString() {
return "null";

View File

@@ -1,6 +1,19 @@
package pp.mdga.message.client;
import pp.mdga.game.Color;
public class SelectTSK extends ClientMessage {
private final Color color;
public SelectTSK(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
@Override
public String toString() {
return "null";

View File

@@ -1,6 +1,25 @@
package pp.mdga.message.client;
import pp.mdga.game.Color;
public class SelectedPieces extends ClientMessage {
private String pieceIdentifier;
/** Constructor for SelectedPieces
* @param pieceIdentifier the piece identifier
*/
public SelectedPieces(String pieceIdentifier) {
this.pieceIdentifier = pieceIdentifier;
}
/** Getter for the piece identifier
* @return the piece identifier
*/
public String getPieceIdentifier() {
return pieceIdentifier;
}
@Override
public String toString() {
return "null";

View File

@@ -1,6 +1,25 @@
package pp.mdga.message.server;
import pp.mdga.game.Color;
public class ActivePlayer extends ServerMessage {
private Color color;
/** Constructor for ActivePlayer
* @param color the color of the active player
*/
public ActivePlayer(Color color) {
this.color = color;
}
/** Getter for the color of the active player
* @return the color of the active player
*/
public Color getColor() {
return color;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,31 @@
package pp.mdga.message.server;
import java.util.ArrayList;
public class AnyPiece extends ServerMessage {
private ArrayList<String> piece;
/** Constructor for AnyPiece
*/
public AnyPiece() {
piece = new ArrayList<>();
}
/** Add a piece to the list of pieces
* @param piece the piece to add
*/
public void addPiece(String piece) {
this.piece.add(piece);
}
/** Getter for the list of pieces
* @return the list of pieces
*/
public ArrayList<String> getPiece() {
return piece;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,52 @@
package pp.mdga.message.server;
import java.util.ArrayList;
public class Dice extends ServerMessage {
private final int diceEye;
private final ArrayList<String> moveablePieces;
/** Constructor for Dice
* @param diceEye the eye of the dice
* @param moveablePieces the pieces that can be moved
*/
public Dice(int diceEye, ArrayList<String> moveablePieces) {
this.diceEye = diceEye;
this.moveablePieces = moveablePieces;
}
/** Constructor for inactivePlayer
* @param diceEye the eye of the dice
* @return a new Dice object
*/
public static Dice inactivePlayer(int diceEye) {
return new Dice(diceEye, null);
}
/** Constructor for activePlayer
* @param diceEye the eye of the dice
* @param moveablePieces the pieces that can be moved
* @return a new Dice object
*/
public static Dice activePlayer(int diceEye, ArrayList<String> moveablePieces) {
return new Dice(diceEye, moveablePieces);
}
/** Getter for the eye of the dice
* @return the eye of the dice
*/
public int getDiceEye() {
return diceEye;
}
/** Getter for the pieces that can be moved
* @return the pieces that can be moved
*/
public ArrayList<String> getMoveablePieces() {
return moveablePieces;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,17 @@
package pp.mdga.message.server;
public class LobbyPlayerJoin extends ServerMessage {
private final String name;
public LobbyPlayerJoin(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,24 @@
package pp.mdga.message.server;
import pp.mdga.game.Color;
public class LobbyPlayerLeave extends ServerMessage {
private final String name;
private final Color color;
public LobbyPlayerLeave(String name, Color color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public Color getColor() {
return color;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,26 @@
package pp.mdga.message.server;
public class MoveMessage extends ServerMessage {
private final String pieceIdentifier;
/**
* @param identifier the identifier of the piece that should be moved
*/
public MoveMessage(String identifier) {
this.pieceIdentifier = identifier;
}
/**
* @return the identifier of the piece that should be moved
*/
public String getIdentifier() {
return pieceIdentifier;
}
/**
* @return the identifier of the piece that should be moved
*/
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,34 @@
package pp.mdga.message.server;
import pp.mdga.game.BonusCard;
public class PlayCard extends ServerMessage {
private final BonusCard card;
private final String pieceIdentifier;
/**
* @param card the card that should be played
* @param pieceIdentifier the identifier of the piece that should be moved
*/
public PlayCard(BonusCard card, String pieceIdentifier) {
this.card = card;
this.pieceIdentifier = pieceIdentifier;
}
/**
* @return the card that should be played
*/
public BonusCard getCard() {
return card;
}
/**
* @return the identifier of the piece that should be moved
*/
public String getPieceIdentifier() {
return pieceIdentifier;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,33 @@
package pp.mdga.message.server;
import pp.mdga.game.BonusCard;
import java.util.ArrayList;
public class PossibleCard extends ServerMessage {
private ArrayList<BonusCard> possibleCards;
/** Constructor for PossibleCard
*/
public PossibleCard() {
possibleCards = new ArrayList<>();
}
/** Add a possible card to the list of possible cards
* @param card the possible card to add
*/
public void addPossibleCard(BonusCard card) {
this.possibleCards.add(card);
}
/** Getter for the list of possible cards
* @return the list of possible cards
*/
public ArrayList<BonusCard> getPossibleCards() {
return possibleCards;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,40 @@
package pp.mdga.message.server;
import java.util.ArrayList;
public class PossiblePiece extends ServerMessage {
private final ArrayList<String> possibleOwnPieces;
private final ArrayList<String> possibleEnemyPieces;
/** Constructor for PossiblePiece
*/
public PossiblePiece() {
possibleOwnPieces = new ArrayList<>();
possibleEnemyPieces = new ArrayList<>();
}
/** Add a piece to the list of possible pieces
* @param piece the piece to add
*/
public void addOwnPossiblePiece(String piece) {
this.possibleOwnPieces.add(piece);
}
/** Add a piece to the list of possible enemy pieces
* @param piece the piece to add
*/
public void addEnemyPossiblePiece(String piece) {
this.possibleEnemyPieces.add(piece);
}
/** Getter for the list of possible pieces
* @return the list of possible pieces
*/
public ArrayList<String> getPossiblePieces() {
return possibleOwnPieces;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,18 @@
package pp.mdga.message.server;
import pp.mdga.game.Game;
public class ReconnectBriefing extends ServerMessage {
private final Game game;
public ReconnectBriefing(Game game) {
this.game = game;
}
public Game getGame() {
return game;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,17 @@
package pp.mdga.message.server;
public class StartPiece extends ServerMessage {
private final String pieceIdentifier;
public StartPiece(String pieceIdentifier) {
this.pieceIdentifier = pieceIdentifier;
}
public String getPieceIdentifier() {
return pieceIdentifier;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,24 @@
package pp.mdga.message.server;
import pp.mdga.game.Color;
public class UpdateReady extends ServerMessage {
private final Color color;
private final boolean ready;
public UpdateReady(Color color, boolean ready) {
this.color = color;
this.ready = ready;
}
public Color getColor() {
return color;
}
public boolean isReady() {
return ready;
}
@Override
public void accept(ServerInterpreter interpreter) {

View File

@@ -1,6 +1,24 @@
package pp.mdga.message.server;
import pp.mdga.game.Color;
public class UpdateTSK extends ServerMessage {
private final String name;
private final Color color;
public UpdateTSK(String name, Color color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public Color getColor() {
return color;
}
@Override
public void accept(ServerInterpreter interpreter) {