needPiecedeletion implemented, it suppress the piece but doesnt move the
moving piece to the desired place
This commit is contained in:
parent
63518d092e
commit
8f5a17fc1a
|
|
@ -125,13 +125,16 @@ public class Board {
|
|||
selectX = x; //set select x to x
|
||||
selectY = y; // same with y
|
||||
}
|
||||
} else { //if select x and y arent at their initial value (means that a piece is selected in the grid)
|
||||
}else { //if select x and y arent at their initial value (means that a piece is selected in the grid)
|
||||
|
||||
if(selectX == x && selectY == y) { //if cliking one more time on same pos, return to original var value (comeback to the beggining of loop)
|
||||
selectX = -1;
|
||||
|
||||
selectX = -1;
|
||||
selectY = -1;
|
||||
|
||||
} else {
|
||||
movePiece(selectX, selectY, x, y); //if not clicking in same position, calls move piece to change the piece coordinates
|
||||
|
||||
|
||||
movePiece(selectX, selectY, x, y); //if not clicking in same position, calls move piece to change the piece coordinates
|
||||
turnNb++; // Increment turn number and change turn color
|
||||
selectX = -1;
|
||||
selectY = -1;
|
||||
|
|
@ -148,24 +151,32 @@ public class Board {
|
|||
if(piece.getX() == selectX && piece.getY() == selectY) { // if the coordinates selected and the coordinate of a piece on the board matches, the loop will activate
|
||||
movingPiece = piece; //storing in memory the piece
|
||||
|
||||
for(Piece pieceInTheWay : pieces) { //loop to check if a piece is in the way
|
||||
|
||||
if(pieceInTheWay.getX() == toX && pieceInTheWay.getY() == toY) { //checking if a piece is at the arrival coordinates
|
||||
if (setSelectXY(toX, toY)){//checking if a piece is at the arrival coordinates
|
||||
|
||||
pieces.remove(pieceInTheWay); //if a piece is at arrival coord, remove the piece
|
||||
movingPiece.setX(toX); // change coordinates to the new coordinate
|
||||
movingPiece.setY(toY);
|
||||
break;
|
||||
needPieceDeletion(toX, toY); //if a piece is at arrival coord, remove the piece
|
||||
movingPiece.setX(toX); // change coordinates to the new coordinate
|
||||
movingPiece.setY(toY);
|
||||
break;
|
||||
|
||||
} else { //if not, just move piece to new coord
|
||||
}else { //if not, just move piece to new coord
|
||||
|
||||
movingPiece.setX(toX); // change coordinates to the new coordinate
|
||||
movingPiece.setY(toY);
|
||||
break;
|
||||
}
|
||||
movingPiece.setX(toX); // change coordinates to the new coordinate
|
||||
movingPiece.setY(toY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void needPieceDeletion(int x, int y) { //almost a copy of setSelectXY but removes the piece instead of returning a bool
|
||||
|
||||
for (Piece piece : pieces) { // iterate trough all pieces
|
||||
|
||||
if (piece.getX() == x && piece.getY() == y) {
|
||||
|
||||
pieces.remove(piece); //removing piece according to if statement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue