Fix selectPieceState and startPieceState logic
This commit is contained in:
@@ -48,21 +48,30 @@ public void selectPiece(Piece piece) {
|
|||||||
@Override
|
@Override
|
||||||
public void received(MoveMessage msg) {
|
public void received(MoveMessage msg) {
|
||||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
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()) {
|
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().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||||
} else {
|
} else {
|
||||||
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
int oldIndex = 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()].getOccupant();
|
||||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
|
//logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
|
||||||
if (occ != null){
|
if (occ != null) {
|
||||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
//TODO: MoveThrowNotification
|
||||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
|
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());
|
parent.getParent().setState(parent.getParent().getMovePiece());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public void received(MoveMessage msg){
|
|||||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||||
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||||
LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
|
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);
|
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
|
||||||
if (occ != null){
|
if (occ != null){
|
||||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||||
|
|||||||
Reference in New Issue
Block a user