diff --git a/src/backend/Board.java b/src/backend/Board.java index 2317d52..29b71df 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -152,17 +152,19 @@ public class Board { this.y = -1; } 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 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); pieces.get(indexPiece).setX(x); pieces.get(indexPiece).setY(y); this.turnNumber +=1; } + // we now reset our parameters this.x=-1; this.y=-1; @@ -354,7 +356,7 @@ public class Board { if((x == this.x) && (positionOccupied(x,y)==false)) {//advance one case 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; } }