Merge branch 'master' of https://gitarero.ecam.fr/aurele.wittke/OOP_1A5_Project
This commit is contained in:
commit
0cb6318a8a
|
|
@ -11,6 +11,10 @@ public class Board {
|
|||
private int x;
|
||||
private int y;
|
||||
private int turnNumber;
|
||||
private boolean lastTurnPawnTwo = false;//for en passant
|
||||
private int xTwo;
|
||||
private int yTwo;
|
||||
private boolean enPassant = false;
|
||||
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.colNum = colNum;
|
||||
|
|
@ -162,9 +166,25 @@ public class Board {
|
|||
}
|
||||
}
|
||||
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
|
||||
if (enPassant) {
|
||||
this.pieces.remove(whatPiece(xTwo,yTwo));
|
||||
enPassant = false;
|
||||
}
|
||||
|
||||
int indexPiece = this.whatPiece(this.x, this.y);
|
||||
|
||||
if (pieces.get(indexPiece).getType() == PieceType.Pawn && Math.abs(this.y-y)==2) {//save the number of the turn at which a pawn moved by two
|
||||
lastTurnPawnTwo = true;
|
||||
xTwo = x;
|
||||
yTwo = y;
|
||||
}
|
||||
else {
|
||||
lastTurnPawnTwo = false;
|
||||
}
|
||||
|
||||
pieces.get(indexPiece).setX(x);
|
||||
pieces.get(indexPiece).setY(y);
|
||||
|
||||
this.turnNumber +=1;
|
||||
}
|
||||
|
||||
|
|
@ -389,13 +409,24 @@ public class Board {
|
|||
boolean highlight = false;
|
||||
if (positionOccupied(this.x,this.y)) { //check if we have selected a position with a piece
|
||||
int indexPieceSelect = whatPiece(this.x,this.y);
|
||||
|
||||
if (pieces.get(indexPieceSelect).getType() == PieceType.Pawn) {//highlight for pawns
|
||||
|
||||
if (pieces.get(indexPieceSelect).isWhite()) {//white pawns
|
||||
|
||||
if (lastTurnPawnTwo) {//en passant
|
||||
if(yTwo == this.y && Math.abs(xTwo - this.x) == 1 && x == xTwo && y == this.y - 1) {
|
||||
highlight = true;
|
||||
enPassant = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(y == this.y-1) {
|
||||
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 and of another color
|
||||
highlight = true;
|
||||
}
|
||||
|
|
@ -407,9 +438,18 @@ public class Board {
|
|||
|
||||
if (pieces.get(indexPieceSelect).isWhite() == false) {//black pawns
|
||||
if(y == this.y+1) {
|
||||
|
||||
if (lastTurnPawnTwo) {//en passant
|
||||
if(yTwo == this.y && Math.abs(xTwo - this.x) == 1 && x == xTwo && y == this.y+1) {
|
||||
highlight = true;
|
||||
enPassant = true;
|
||||
}
|
||||
}
|
||||
|
||||
if((x == this.x) && (positionOccupied(x,y)==false)) {
|
||||
highlight = true;
|
||||
}
|
||||
|
||||
if((Math.abs(x-this.x) == 1) && (positionOccupied(x,y)) && pieces.get(whatPiece(x,y)).isWhite() != pieces.get(indexPieceSelect).isWhite()) {
|
||||
highlight = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue