added static methods to construct a PlayCard message for each card type

This commit is contained in:
Hanno Fleischer
2024-11-25 13:42:00 +01:00
committed by Felix
parent eba681c350
commit dd7a27629b

View File

@@ -18,26 +18,60 @@ public class PlayCard extends ServerMessage {
*/
private final String pieceIdentifier;
private final String pieceIdentifierEnemy;
/**
* 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 PlayCard(BonusCard card, String pieceIdentifier) {
public PlayCard(BonusCard card, String pieceIdentifier, String pieceIdentifierEnemy) {
super();
this.card = card;
this.pieceIdentifier = pieceIdentifier;
this.pieceIdentifierEnemy = pieceIdentifierEnemy;
}
/**
* Default constructor for serialization purposes.
*/
private PlayCard() {
this.pieceIdentifierEnemy = null;
card = null;
pieceIdentifier = null;
}
/**
* Creates a new PlayCard message for the given card and piece identifier.
*
* @param pieceIdentifier the identifier of the piece of the player that should be affected
* @param pieceIdentifierEnemy the identifier of the enemy piece that should be affected
* @return a new PlayCard message
*/
public static PlayCard swap(String pieceIdentifier, String pieceIdentifierEnemy) {
return new PlayCard(BonusCard.SWAP, pieceIdentifier, pieceIdentifierEnemy);
}
/**
* Creates a new PlayCard message for the given card and piece identifier.
*
* @return a new PlayCard message
*/
public static PlayCard turbo() {
return new PlayCard(BonusCard.TURBO, null, null);
}
/**
* Creates a new PlayCard message for the given card and piece identifier.
*
* @param pieceIdentifier the identifier of the piece of the player that should be affected
* @return a new PlayCard message
*/
public static PlayCard shield(String pieceIdentifier) {
return new PlayCard(BonusCard.SHIELD, pieceIdentifier, null);
}
/**
* Returns the card that should be played.
*
@@ -56,6 +90,15 @@ public String getPieceIdentifier() {
return pieceIdentifier;
}
/**
* Returns the identifier of the enemy piece that should be moved.
*
* @return the identifier of the enemy piece that should be moved
*/
public String getPieceIdentifierEnemy() {
return pieceIdentifierEnemy;
}
/**
* Accepts a visitor to process this message.
*