This commit is contained in:
edwin 2025-05-06 14:07:09 +02:00
commit 4000184705
1 changed files with 5 additions and 3 deletions

View File

@ -155,17 +155,19 @@ public class Board {
this.y = -1; this.y = -1;
} }
else { // we know we already have a piece so we move it to another position else { // we know we already have a piece so we move it to another position
if( this.positionOccupied(x, y) == true) { boolean highlights = isHighlighted(x,y);
if( this.positionOccupied(x, y) == true && highlights) {
if (pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite()) {//check if we do not move to a position occupied by a piece of the same color if (pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite()) {//check if we do not move to a position occupied by a piece of the same color
this.pieces.remove(whatPiece(x,y)); //if there is a piece at the position we want to move we remove it from the array list this.pieces.remove(whatPiece(x,y)); //if there is a piece at the position we want to move we remove it from the array list
} }
} }
if((this.positionOccupied(x, y) == false || pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite()) && (isHighlighted(x,y))) {//moves the piece only if the position selected is not occupied by a piece of the same color if(((this.positionOccupied(x, y) == false || pieces.get(whatPiece(x,y)).isWhite() != pieces.get(whatPiece(this.x,this.y)).isWhite())) && (highlights)) {//moves the piece only if the position selected is not occupied by a piece of the same color
int indexPiece = this.whatPiece(this.x, this.y); int indexPiece = this.whatPiece(this.x, this.y);
pieces.get(indexPiece).setX(x); pieces.get(indexPiece).setX(x);
pieces.get(indexPiece).setY(y); pieces.get(indexPiece).setY(y);
this.turnNumber +=1; this.turnNumber +=1;
} }
// we now reset our parameters // we now reset our parameters
this.x=-1; this.x=-1;
this.y=-1; this.y=-1;
@ -357,7 +359,7 @@ public class Board {
if((x == this.x) && (positionOccupied(x,y)==false)) {//advance one case if((x == this.x) && (positionOccupied(x,y)==false)) {//advance one case
highlight = true; highlight = true;
} }
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {//highlight the piece in diagonal, if existing if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {//highlight the piece in diagonal, if existing and of another color
highlight = true; highlight = true;
} }
} }