edited MoveMessage in WaitingState

This commit is contained in:
Cedric Beck
2024-12-08 12:38:59 +01:00
parent bc399b1bf9
commit ae436589a2
2 changed files with 17 additions and 7 deletions

View File

@@ -68,19 +68,28 @@ public void received(ActivePlayerMessage msg) {
@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);
this.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);
}
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.setState(parent.getAnimation());
}

View File

@@ -78,6 +78,7 @@ private StartNode createStartNode(int i) {
* @return the index of the piece
*/
public int getInfieldIndexOfPiece(Piece piece) {
System.out.println("Get uuid of: "+ piece.getUuid());
for (int i = 0; i < infield.length; i++) {
System.out.println(infield[i].getOccupant());
if(infield[i].isOccupied()) {