Fix selectPieceState and startPieceState logic

This commit is contained in:
Felix Koppe
2024-12-08 12:45:08 +01:00
parent bc399b1bf9
commit 121f47d070
2 changed files with 18 additions and 9 deletions

View File

@@ -48,21 +48,30 @@ public void selectPiece(Piece piece) {
@Override
public void received(MoveMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
//logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
if (msg.isHomeMove()) {
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
} else {
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex()));
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
if (occ != null){
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
//logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
if (occ != null) {
//TODO: MoveThrowNotification
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
//set occ to waiting
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
}
parent.getParent().setState(parent.getParent().getMovePiece());
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), oldIndex, msg.getTargetIndex()));
//clear old node
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
//set new node
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
}
parent.getParent().setState(parent.getParent().getMovePiece());
}
}

View File

@@ -51,7 +51,7 @@ public void received(MoveMessage msg){
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex()));
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), i, msg.getTargetIndex()));
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
if (occ != null){
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);