changed all messages to work with a UUID of a piece instead of a string identifier

This commit is contained in:
Fleischer Hanno
2024-12-01 15:45:30 +01:00
parent 7712ee2e7c
commit ed04bc1119
27 changed files with 113 additions and 112 deletions

View File

@@ -114,7 +114,7 @@ private void initializeSerializables() {
Serializer.registerClass(EndOfTurnMessage.class); Serializer.registerClass(EndOfTurnMessage.class);
Serializer.registerClass(LobbyAcceptMessage.class); Serializer.registerClass(LobbyAcceptMessage.class);
Serializer.registerClass(LobbyDenyMessage.class); Serializer.registerClass(LobbyDenyMessage.class);
Serializer.registerClass(LobbyPlayerJoinMessage.class); Serializer.registerClass(LobbyPlayerJoinedMessage.class);
Serializer.registerClass(LobbyPlayerLeaveMessage.class); Serializer.registerClass(LobbyPlayerLeaveMessage.class);
Serializer.registerClass(MoveMessage.class); Serializer.registerClass(MoveMessage.class);
Serializer.registerClass(NoTurnMessage.class); Serializer.registerClass(NoTurnMessage.class);

View File

@@ -125,7 +125,7 @@ public void received(LobbyDenyMessage msg) {
} }
@Override @Override
public void received(LobbyPlayerJoinMessage msg) { public void received(LobbyPlayerJoinedMessage msg) {
state.received(msg); state.received(msg);
} }

View File

@@ -86,7 +86,7 @@ public void received(LobbyDenyMessage msg) {
} }
@Override @Override
public void received(LobbyPlayerJoinMessage msg) { public void received(LobbyPlayerJoinedMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
} }

View File

@@ -5,7 +5,6 @@
import pp.mdga.client.dialogState.NetworkDialogState; import pp.mdga.client.dialogState.NetworkDialogState;
import pp.mdga.client.dialogState.StartDialogState; import pp.mdga.client.dialogState.StartDialogState;
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.game.Player;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
public class DialogsState extends ClientState { public class DialogsState extends ClientState {
@@ -112,7 +111,7 @@ public void selectHost(String name){
} }
@Override @Override
public void received(LobbyPlayerJoinMessage msg){ public void received(LobbyPlayerJoinedMessage msg){
currentState.received(msg); currentState.received(msg);
} }

View File

@@ -6,7 +6,7 @@
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.game.Player; import pp.mdga.game.Player;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.LobbyPlayerJoinMessage; import pp.mdga.message.server.LobbyPlayerJoinedMessage;
import pp.mdga.message.server.LobbyPlayerLeaveMessage; import pp.mdga.message.server.LobbyPlayerLeaveMessage;
import pp.mdga.message.server.ServerStartGameMessage; import pp.mdga.message.server.ServerStartGameMessage;
import pp.mdga.message.server.UpdateReadyMessage; import pp.mdga.message.server.UpdateReadyMessage;
@@ -74,8 +74,8 @@ public void received(ServerStartGameMessage msg){
} }
@Override @Override
public void received(LobbyPlayerJoinMessage msg){ public void received(LobbyPlayerJoinedMessage msg){
logic.getGame().getPlayers().put(msg.getId(), new Player(msg.getName())); logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
} }
@Override @Override

View File

@@ -21,16 +21,16 @@ protected void handlePowerCard(PlayCardMessage msg){
if (msg.getCard().equals(BonusCard.TURBO)){ if (msg.getCard().equals(BonusCard.TURBO)){
logic.getGame().setDiceModifier(msg.getDiceModifier()); logic.getGame().setDiceModifier(msg.getDiceModifier());
} else if (msg.getCard().equals(BonusCard.SHIELD)){ } else if (msg.getCard().equals(BonusCard.SHIELD)){
if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier())) % 10 != 0) { if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier())) % 10 != 0) {
logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED); logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).getUuid()));
} else { } else {
logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.ACTIVE); logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).setShield(ShieldState.ACTIVE);
logic.addNotification(new ShieldActiveNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid())); logic.addNotification(new ShieldActiveNotification(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).getUuid()));
} }
} else { } else {
Piece ownPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()); Piece ownPiece = logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier());
Piece enemyPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifierEnemy()); Piece enemyPiece = logic.getGame().getPieceThroughUUID(msg.getPieceIdentifierEnemy());
int ownIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(ownPiece); int ownIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(ownPiece);
logic.addNotification(new SwapPieceNotification(ownPiece.getUuid(), enemyPiece.getUuid())); logic.addNotification(new SwapPieceNotification(ownPiece.getUuid(), enemyPiece.getUuid()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece);

View File

@@ -60,7 +60,7 @@ public void received(ActivePlayerMessage msg){
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg){
Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
if (msg.isHomeMove()){ if (msg.isHomeMove()){
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant(); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();

View File

@@ -66,7 +66,7 @@ public void received(ActivePlayerMessage msg){
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg){
Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
if (msg.isHomeMove()){ if (msg.isHomeMove()){
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant(); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();

View File

@@ -35,7 +35,7 @@ public void exit() {
@Override @Override
public void received(SelectPieceMessage msg) { public void received(SelectPieceMessage msg) {
parent.setState(parent.getSelectPiece()); parent.setState(parent.getSelectPiece());
ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)); ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new));
parent.getSelectPiece().setPossiblePieces(pieces); parent.getSelectPiece().setPossiblePieces(pieces);
logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove())); logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove()));
} }
@@ -48,7 +48,7 @@ public void received(WaitPieceMessage msg){
@Override @Override
public void received(StartPieceMessage msg){ public void received(StartPieceMessage msg){
Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()); Piece piece = logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier());
//TODO: logic.addNotification(null); //TODO: logic.addNotification(null);
parent.setState(parent.getStartPiece()); parent.setState(parent.getStartPiece());
} }

View File

@@ -38,13 +38,13 @@ public void setPossiblePieces(ArrayList<Piece> possiblePieces){
@Override @Override
public void selectPiece(Piece piece){ public void selectPiece(Piece piece){
if(possiblePieces.contains(piece)){ if(possiblePieces.contains(piece)){
logic.send(new SelectedPiecesMessage(piece.getIdentifier())); logic.send(new SelectedPiecesMessage(piece.getUuid()));
} }
} }
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg){
Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); Piece piece = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
if(msg.isHomeMove()){ if(msg.isHomeMove()){
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex())); logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();

View File

@@ -31,7 +31,7 @@ public void exit() {
@Override @Override
public void selectPiece(Piece piece){ public void selectPiece(Piece piece){
if(moveablePiece.equals(piece)){ if(moveablePiece.equals(piece)){
logic.send(new SelectedPiecesMessage(piece.getIdentifier())); logic.send(new SelectedPiecesMessage(piece.getUuid()));
} }
} }

View File

@@ -30,7 +30,7 @@ public void exit() {
@Override @Override
public void selectPiece(Piece piece){ public void selectPiece(Piece piece){
if(moveablePiece.equals(piece)){ if(moveablePiece.equals(piece)){
logic.send(new SelectedPiecesMessage(piece.getIdentifier())); logic.send(new SelectedPiecesMessage(piece.getUuid()));
} }
} }

View File

@@ -102,11 +102,11 @@ public void received(DiceNowMessage msg){
@Override @Override
public void received(PossiblePieceMessage msg){ public void received(PossiblePieceMessage msg){
if (msg.getEnemyPossiblePieces().isEmpty()){ if (msg.getEnemyPossiblePieces().isEmpty()){
parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new))); parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.setState(parent.getShield()); parent.setState(parent.getShield());
} else { } else {
parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new))); parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.getSwap().setPossibleEnemyPieces(msg.getEnemyPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new))); parent.getSwap().setPossibleEnemyPieces(msg.getEnemyPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.setState(parent.getSwap()); parent.setState(parent.getSwap());
} }
} }

View File

@@ -39,7 +39,7 @@ public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
public void selectPiece(Piece piece) { public void selectPiece(Piece piece) {
if (possiblePieces.contains(piece)) { if (possiblePieces.contains(piece)) {
logic.send(RequestPlayCardMessage.requestPlayShield(piece.getIdentifier())); logic.send(RequestPlayCardMessage.requestPlayShield(piece.getUuid()));
} else { } else {
LOGGER.log(Level.DEBUG, "Invalid piece selected"); LOGGER.log(Level.DEBUG, "Invalid piece selected");
} }

View File

@@ -56,7 +56,7 @@ public void selectPiece(Piece piece){
selectedEnemyPiece = piece; selectedEnemyPiece = piece;
} }
if (selectedOwnPiece != null && selectedEnemyPiece != null){ if (selectedOwnPiece != null && selectedEnemyPiece != null){
logic.send(RequestPlayCardMessage.requestPlaySwap(selectedOwnPiece.getIdentifier(), selectedEnemyPiece.getIdentifier())); logic.send(RequestPlayCardMessage.requestPlaySwap(selectedOwnPiece.getUuid(), selectedEnemyPiece.getUuid()));
} }
} }

View File

@@ -134,16 +134,6 @@ public int getNumberOfActivePlayers() {
return activePlayers; return activePlayers;
} }
/**
* This method will be used to return a piece based on the identifier.
*
* @return the piece specified by the identifier
*/
public Piece getPieceThroughIdentifier(String identifier){
String[] parts = identifier.split("-");
return board.getPlayerData().get(Color.valueOf(parts[0])).getPieces()[Integer.parseInt(parts[1])];
}
/** /**
* This method will be used to return a piece based on the UUID. * This method will be used to return a piece based on the UUID.
* *

View File

@@ -9,7 +9,6 @@ public class Piece {
private ShieldState shield; private ShieldState shield;
private PieceState state; private PieceState state;
private final Color color; private final Color color;
private final int id;
private final UUID uuid = UUID.randomUUID(); private final UUID uuid = UUID.randomUUID();
/** /**
@@ -22,7 +21,6 @@ public Piece(Color color, PieceState state, int id) {
this.color = color; this.color = color;
this.state = state; this.state = state;
shield = ShieldState.NONE; shield = ShieldState.NONE;
this.id = id;
} }
/** /**
@@ -88,15 +86,6 @@ public Color getColor() {
return color; 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;
}
/** /**
* This method is used to get the color of the piece * This method is used to get the color of the piece
* *

View File

@@ -2,6 +2,8 @@
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import java.util.UUID;
/** /**
* A message sent by a client to request a move for a piece. * A message sent by a client to request a move for a piece.
*/ */
@@ -10,14 +12,14 @@ public class RequestMoveMessage extends ClientMessage {
/** /**
* The identifier for the piece. * The identifier for the piece.
*/ */
private final String pieceIdentifier; private final UUID pieceIdentifier;
/** /**
* Constructor for RequestMove * Constructor for RequestMove
* *
* @param pieceIdentifier the piece identifier * @param pieceIdentifier the piece identifier
*/ */
public RequestMoveMessage(String pieceIdentifier) { public RequestMoveMessage(UUID pieceIdentifier) {
this.pieceIdentifier = pieceIdentifier; this.pieceIdentifier = pieceIdentifier;
} }
@@ -33,7 +35,7 @@ private RequestMoveMessage() {
* *
* @return the piece identifier * @return the piece identifier
*/ */
public String getPieceIdentifier() { public UUID getPieceIdentifier() {
return pieceIdentifier; return pieceIdentifier;
} }

View File

@@ -3,6 +3,8 @@
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import java.util.UUID;
/** /**
* A message sent by a client to request playing a bonus card. * A message sent by a client to request playing a bonus card.
*/ */
@@ -16,9 +18,9 @@ public class RequestPlayCardMessage extends ClientMessage {
/** /**
* The identifier of the piece. * The identifier of the piece.
*/ */
private final String ownPieceIdentifier; private final UUID ownPieceIdentifier;
private final String enemyPieceIdentifier; private final UUID enemyPieceIdentifier;
/** /**
* Constructs a new RequestPlayCard instance. * Constructs a new RequestPlayCard instance.
@@ -26,7 +28,7 @@ public class RequestPlayCardMessage extends ClientMessage {
* @param card the bonus card to be played * @param card the bonus card to be played
* @param ownPieceIdentifier the identifier of the piece * @param ownPieceIdentifier the identifier of the piece
*/ */
public RequestPlayCardMessage(BonusCard card, String ownPieceIdentifier, String enemyPieceIdentifier) { public RequestPlayCardMessage(BonusCard card, UUID ownPieceIdentifier, UUID enemyPieceIdentifier) {
this.ownPieceIdentifier = ownPieceIdentifier; this.ownPieceIdentifier = ownPieceIdentifier;
this.card = card; this.card = card;
this.enemyPieceIdentifier = enemyPieceIdentifier; this.enemyPieceIdentifier = enemyPieceIdentifier;
@@ -48,11 +50,17 @@ private RequestPlayCardMessage() {
* @param enemyPieceIdentifier the identifier of the enemy piece * @param enemyPieceIdentifier the identifier of the enemy piece
* @return a new RequestPlayCard instance * @return a new RequestPlayCard instance
*/ */
public static RequestPlayCardMessage requestPlaySwap(String ownPieceIdentifier, String enemyPieceIdentifier){ public static RequestPlayCardMessage requestPlaySwap(UUID ownPieceIdentifier, UUID enemyPieceIdentifier){
return new RequestPlayCardMessage(BonusCard.SWAP, ownPieceIdentifier, enemyPieceIdentifier); return new RequestPlayCardMessage(BonusCard.SWAP, ownPieceIdentifier, enemyPieceIdentifier);
} }
public static RequestPlayCardMessage requestPlayShield(String ownPieceIdentifier){ /**
* Creates a new RequestPlayCard instance for a shield bonus card.
*
* @param ownPieceIdentifier the identifier of the piece
* @return a new RequestPlayCard instance
*/
public static RequestPlayCardMessage requestPlayShield(UUID ownPieceIdentifier){
return new RequestPlayCardMessage(BonusCard.SHIELD, ownPieceIdentifier, null); return new RequestPlayCardMessage(BonusCard.SHIELD, ownPieceIdentifier, null);
} }
@@ -70,7 +78,7 @@ public BonusCard getCard() {
* *
* @return the piece identifier * @return the piece identifier
*/ */
public String getOwnPieceIdentifier() { public UUID getOwnPieceIdentifier() {
return ownPieceIdentifier; return ownPieceIdentifier;
} }
@@ -79,7 +87,7 @@ public String getOwnPieceIdentifier() {
* *
* @return the enemy piece identifier * @return the enemy piece identifier
*/ */
public String getEnemyPieceIdentifier() { public UUID getEnemyPieceIdentifier() {
return enemyPieceIdentifier; return enemyPieceIdentifier;
} }

View File

@@ -2,6 +2,8 @@
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import java.util.UUID;
/** /**
* A message sent by a client to indicate that a piece has been selected for a bonus cards. * A message sent by a client to indicate that a piece has been selected for a bonus cards.
*/ */
@@ -10,14 +12,14 @@ public class SelectedPiecesMessage extends ClientMessage {
/** /**
* The piece identifier. * The piece identifier.
*/ */
private String pieceIdentifier; private final UUID pieceIdentifier;
/** /**
* Constructor for SelectedPieces * Constructor for SelectedPieces
* *
* @param pieceIdentifier the piece identifier * @param pieceIdentifier the piece identifier
*/ */
public SelectedPiecesMessage(String pieceIdentifier) { public SelectedPiecesMessage(UUID pieceIdentifier) {
this.pieceIdentifier = pieceIdentifier; this.pieceIdentifier = pieceIdentifier;
} }
@@ -33,7 +35,7 @@ private SelectedPiecesMessage() {
* *
* @return the piece identifier * @return the piece identifier
*/ */
public String getPieceIdentifier() { public UUID getPieceIdentifier() {
return pieceIdentifier; return pieceIdentifier;
} }

View File

@@ -4,6 +4,7 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* A message sent by the server to the active player containing a list of pieces that the player can move any piece of the list on the board. * A message sent by the server to the active player containing a list of pieces that the player can move any piece of the list on the board.
@@ -13,7 +14,7 @@ public class AnyPieceMessage extends ServerMessage {
/** /**
* The list of pieces * The list of pieces
*/ */
private final ArrayList<String> piece; private final ArrayList<UUID> piece;
/** /**
* Constructor for AnyPiece * Constructor for AnyPiece
@@ -28,7 +29,7 @@ public AnyPieceMessage() {
* *
* @param piece the piece to add * @param piece the piece to add
*/ */
public void addPiece(String piece) { public void addPiece(UUID piece) {
this.piece.add(piece); this.piece.add(piece);
} }
@@ -37,7 +38,7 @@ public void addPiece(String piece) {
* *
* @return the list of pieces * @return the list of pieces
*/ */
public List<String> getPiece() { public List<UUID> getPiece() {
return piece; return piece;
} }

View File

@@ -1,17 +1,18 @@
package pp.mdga.message.server; package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Player;
/** /**
* A message sent from the server to the client indicating that a player has joined the lobby. * A message sent from the server to the client indicating that a player has joined the lobby.
*/ */
@Serializable @Serializable
public class LobbyPlayerJoinMessage extends ServerMessage { public class LobbyPlayerJoinedMessage extends ServerMessage {
/** /**
* The name of the player joining the lobby. * The player joining the lobby.
*/ */
private final String name; private final Player player;
/** /**
* The ID of the new Player * The ID of the new Player
@@ -21,29 +22,30 @@ public class LobbyPlayerJoinMessage extends ServerMessage {
/** /**
* Constructs a new LobbyPlayerJoin instance with the specified player name. * Constructs a new LobbyPlayerJoin instance with the specified player name.
* *
* @param name the name of the player joining the lobby * @param player the player joining the lobby
* @param id the id of the player
*/ */
public LobbyPlayerJoinMessage(int id, String name) { public LobbyPlayerJoinedMessage(int id, Player player) {
super(); super();
this.name = name; this.player = player;
this.id = id; this.id = id;
} }
/** /**
* Default constructor for serialization purposes. * Default constructor for serialization purposes.
*/ */
private LobbyPlayerJoinMessage() { private LobbyPlayerJoinedMessage() {
name = null; player = null;
id = 0; id = 0;
} }
/** /**
* Returns the name of the player joining the lobby. * Returns the player joining the lobby.
* *
* @return the name of the player joining the lobby * @return the player joining the lobby
*/ */
public String getName() { public Player getPlayer() {
return name; return player;
} }
/** /**

View File

@@ -3,6 +3,8 @@
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import java.util.UUID;
/** /**
* A message sent by the server to the active player to play a card. * A message sent by the server to the active player to play a card.
*/ */
@@ -16,9 +18,9 @@ public class PlayCardMessage extends ServerMessage {
/** /**
* The identifier of the piece that should be moved. * The identifier of the piece that should be moved.
*/ */
private final String pieceIdentifier; private final UUID ownPieceID;
private final String pieceIdentifierEnemy; private final UUID enemyPieceID;
private final int diceModifier; private final int diceModifier;
@@ -26,13 +28,15 @@ public class PlayCardMessage extends ServerMessage {
* Constructs a new PlayCard message. * Constructs a new PlayCard message.
* *
* @param card the card that should be played * @param card the card that should be played
* @param pieceIdentifier the identifier of the piece that should be moved * @param ownPieceID the identifier of the piece that should be moved
* @param enemyPieceID the identifier of the enemy piece that should be moved
* @param diceModifier the new modifier of the dice
*/ */
public PlayCardMessage(BonusCard card, String pieceIdentifier, String pieceIdentifierEnemy, int diceModifier) { public PlayCardMessage(BonusCard card, UUID ownPieceID, UUID enemyPieceID, int diceModifier) {
super(); super();
this.card = card; this.card = card;
this.pieceIdentifier = pieceIdentifier; this.ownPieceID = ownPieceID;
this.pieceIdentifierEnemy = pieceIdentifierEnemy; this.enemyPieceID = enemyPieceID;
this.diceModifier = diceModifier; this.diceModifier = diceModifier;
} }
@@ -40,31 +44,31 @@ public PlayCardMessage(BonusCard card, String pieceIdentifier, String pieceIdent
* Default constructor for serialization purposes. * Default constructor for serialization purposes.
*/ */
private PlayCardMessage() { private PlayCardMessage() {
this.pieceIdentifierEnemy = null; ownPieceID = null;
card = null; card = null;
pieceIdentifier = null; enemyPieceID = null;
diceModifier = 1; diceModifier = 1;
} }
/** /**
* Creates a new PlayCard message for the given card and piece identifier. * 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 ownPieceID the identifier of the piece of the player that should be affected
* @param pieceIdentifierEnemy the identifier of the enemy piece that should be affected * @param enemyPieceID the identifier of the enemy piece that should be affected
* @return a new PlayCard message * @return a new PlayCard message
*/ */
public static PlayCardMessage swap(String pieceIdentifier, String pieceIdentifierEnemy) { public static PlayCardMessage swap(UUID ownPieceID, UUID enemyPieceID) {
return new PlayCardMessage(BonusCard.SWAP, pieceIdentifier, pieceIdentifierEnemy, 1); return new PlayCardMessage(BonusCard.SWAP, ownPieceID, enemyPieceID, 1);
} }
/** /**
* Creates a new PlayCard message for the given card and piece identifier. * 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 ownPieceID the identifier of the piece of the player that should be affected
* @return a new PlayCard message * @return a new PlayCard message
*/ */
public static PlayCardMessage shield(String pieceIdentifier) { public static PlayCardMessage shield(UUID ownPieceID) {
return new PlayCardMessage(BonusCard.SHIELD, pieceIdentifier, null, 1); return new PlayCardMessage(BonusCard.SHIELD, ownPieceID, null, 1);
} }
/** /**
@@ -91,8 +95,8 @@ public BonusCard getCard() {
* *
* @return the identifier of the piece that should be moved * @return the identifier of the piece that should be moved
*/ */
public String getPieceIdentifier() { public UUID getPieceIdentifier() {
return pieceIdentifier; return ownPieceID;
} }
/** /**
@@ -100,8 +104,8 @@ public String getPieceIdentifier() {
* *
* @return the identifier of the enemy piece that should be moved * @return the identifier of the enemy piece that should be moved
*/ */
public String getPieceIdentifierEnemy() { public UUID getPieceIdentifierEnemy() {
return pieceIdentifierEnemy; return enemyPieceID;
} }

View File

@@ -4,6 +4,7 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* A message sent by the server to the active player to give all possible pieces to choose from. * A message sent by the server to the active player to give all possible pieces to choose from.
@@ -13,12 +14,12 @@ public class PossiblePieceMessage extends ServerMessage {
/** /**
* The list of possible own pieces * The list of possible own pieces
*/ */
private final List<String> possibleOwnPieces; private final List<UUID> possibleOwnPieces;
/** /**
* The list of possible enemy pieces * The list of possible enemy pieces
*/ */
private final List<String> possibleEnemyPieces; private final List<UUID> possibleEnemyPieces;
/** /**
* Constructor for PossiblePiece * Constructor for PossiblePiece
@@ -36,7 +37,7 @@ public PossiblePieceMessage() {
* @param possibleEnemyPieces the list of possible enemy pieces * @param possibleEnemyPieces the list of possible enemy pieces
* @return the swapped possible pieces * @return the swapped possible pieces
*/ */
public static PossiblePieceMessage swapPossiblePieces(ArrayList<String> possibleOwnPieces, ArrayList<String> possibleEnemyPieces) { public static PossiblePieceMessage swapPossiblePieces(ArrayList<UUID> possibleOwnPieces, ArrayList<UUID> possibleEnemyPieces) {
PossiblePieceMessage possiblePieceMessage = new PossiblePieceMessage(); PossiblePieceMessage possiblePieceMessage = new PossiblePieceMessage();
possiblePieceMessage.possibleOwnPieces.addAll(possibleOwnPieces); possiblePieceMessage.possibleOwnPieces.addAll(possibleOwnPieces);
possiblePieceMessage.possibleEnemyPieces.addAll(possibleEnemyPieces); possiblePieceMessage.possibleEnemyPieces.addAll(possibleEnemyPieces);
@@ -49,7 +50,7 @@ public static PossiblePieceMessage swapPossiblePieces(ArrayList<String> possible
* @param possibleOwnPieces the list of possible own pieces * @param possibleOwnPieces the list of possible own pieces
* @return the possible pieces for the shield * @return the possible pieces for the shield
*/ */
public static PossiblePieceMessage shieldPossiblePieces(ArrayList<String> possibleOwnPieces){ public static PossiblePieceMessage shieldPossiblePieces(ArrayList<UUID> possibleOwnPieces){
PossiblePieceMessage possiblePieceMessage = new PossiblePieceMessage(); PossiblePieceMessage possiblePieceMessage = new PossiblePieceMessage();
possiblePieceMessage.possibleOwnPieces.addAll(possibleOwnPieces); possiblePieceMessage.possibleOwnPieces.addAll(possibleOwnPieces);
return possiblePieceMessage; return possiblePieceMessage;
@@ -60,7 +61,7 @@ public static PossiblePieceMessage shieldPossiblePieces(ArrayList<String> possib
* *
* @param piece the piece to add * @param piece the piece to add
*/ */
public void addOwnPossiblePiece(String piece) { public void addOwnPossiblePiece(UUID piece) {
this.possibleOwnPieces.add(piece); this.possibleOwnPieces.add(piece);
} }
@@ -69,21 +70,21 @@ public void addOwnPossiblePiece(String piece) {
* *
* @param piece the piece to add * @param piece the piece to add
*/ */
public void addEnemyPossiblePiece(String piece) { public void addEnemyPossiblePiece(UUID piece) {
this.possibleEnemyPieces.add(piece); this.possibleEnemyPieces.add(piece);
} }
/** Getter for the list of possible pieces /** Getter for the list of possible pieces
* @return the list of possible pieces * @return the list of possible pieces
*/ */
public List<String> getOwnPossiblePieces() { public List<UUID> getOwnPossiblePieces() {
return possibleOwnPieces; return possibleOwnPieces;
} }
/** Getter for the list of possible enemy pieces /** Getter for the list of possible enemy pieces
* @return the list of possible enemy pieces * @return the list of possible enemy pieces
*/ */
public List<String> getEnemyPossiblePieces() { public List<UUID> getEnemyPossiblePieces() {
return possibleEnemyPieces; return possibleEnemyPieces;
} }

View File

@@ -3,11 +3,12 @@
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import java.util.List; import java.util.List;
import java.util.UUID;
@Serializable @Serializable
public class SelectPieceMessage extends ServerMessage{ public class SelectPieceMessage extends ServerMessage{
private final List<String> pieces; private final List<UUID> pieces;
private final List<Boolean> isHomeMove; private final List<Boolean> isHomeMove;
private final List<Integer> targetIndex; private final List<Integer> targetIndex;
@@ -18,7 +19,7 @@ public class SelectPieceMessage extends ServerMessage{
* @param isHomeMove the List of booleans of isHomeMove of the pieces * @param isHomeMove the List of booleans of isHomeMove of the pieces
* @param targetIndex the List of indexes of target nodes of the pieces * @param targetIndex the List of indexes of target nodes of the pieces
*/ */
public SelectPieceMessage(List<String> pieces, List<Boolean> isHomeMove, List<Integer> targetIndex){ public SelectPieceMessage(List<UUID> pieces, List<Boolean> isHomeMove, List<Integer> targetIndex){
this.pieces = pieces; this.pieces = pieces;
this.isHomeMove = isHomeMove; this.isHomeMove = isHomeMove;
this.targetIndex = targetIndex; this.targetIndex = targetIndex;
@@ -38,7 +39,7 @@ public SelectPieceMessage(){
* *
* @return the pieces * @return the pieces
*/ */
public List<String> getPieces(){ public List<UUID> getPieces(){
return pieces; return pieces;
} }

View File

@@ -80,7 +80,7 @@ public interface ServerInterpreter {
* *
* @param msg the LobbyPlayerJoin message received * @param msg the LobbyPlayerJoin message received
*/ */
void received(LobbyPlayerJoinMessage msg); void received(LobbyPlayerJoinedMessage msg);
/** /**
* Handles a LobbyPlayerLeave message received from the server. * Handles a LobbyPlayerLeave message received from the server.

View File

@@ -2,6 +2,8 @@
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import java.util.UUID;
/** /**
* A message sent by the server to the active player that he has to move a start piece. * A message sent by the server to the active player that he has to move a start piece.
*/ */
@@ -10,7 +12,7 @@ public class StartPieceMessage extends ServerMessage {
/** /**
* The identifier for the piece. * The identifier for the piece.
*/ */
private final String pieceIdentifier; private final UUID pieceIdentifier;
/** /**
* The target index of the move; * The target index of the move;
@@ -23,7 +25,7 @@ public class StartPieceMessage extends ServerMessage {
* @param pieceIdentifier the identifier for the piece * @param pieceIdentifier the identifier for the piece
* @param targetIndex the index of the targetNode * @param targetIndex the index of the targetNode
*/ */
public StartPieceMessage(String pieceIdentifier, int targetIndex) { public StartPieceMessage(UUID pieceIdentifier, int targetIndex) {
super(); super();
this.pieceIdentifier = pieceIdentifier; this.pieceIdentifier = pieceIdentifier;
this.targetIndex = targetIndex; this.targetIndex = targetIndex;
@@ -34,7 +36,7 @@ public StartPieceMessage(String pieceIdentifier, int targetIndex) {
*/ */
private StartPieceMessage() { private StartPieceMessage() {
super(); super();
this.pieceIdentifier = ""; this.pieceIdentifier = null;
this.targetIndex = 0; this.targetIndex = 0;
} }
@@ -43,7 +45,7 @@ private StartPieceMessage() {
* *
* @return the piece identifier * @return the piece identifier
*/ */
public String getPieceIdentifier() { public UUID getPieceIdentifier() {
return pieceIdentifier; return pieceIdentifier;
} }