added bishop to ishighlighted
This commit is contained in:
parent
28e5ec34af
commit
f8461a35f2
|
|
@ -185,7 +185,7 @@ public class Board {
|
|||
|
||||
public boolean isHighlighted(int x, int y) {
|
||||
|
||||
Piece myPiece = getPiece(x,y);
|
||||
Piece myPiece = getPiece(selectX,selectY);//get the piece at the selected x and y on the board
|
||||
boolean isAPieceHere = false ; // final return boolean value
|
||||
PieceType type = null; // type of piece variable that we will get trough a loop, this will determine the pattern of highlights on the board
|
||||
boolean color = false ; //color of the piece for pawns that can only go in -y for black and +Y for white
|
||||
|
|
@ -194,31 +194,40 @@ public class Board {
|
|||
type = myPiece.getType();
|
||||
color = myPiece.isWhite();
|
||||
}
|
||||
if(type == PieceType.Pawn && color == true) {
|
||||
for(int i = 1; i < 3;i++) {
|
||||
|
||||
// from here its spaghetti but its works ! i'll explain one, its the same logic for all of them
|
||||
if(type == PieceType.Pawn && color == true) { //check type of piece, here its pawn and they can only move forward so i check the type too
|
||||
for(int i = 1; i < 3;i++) { // this loop iterates from 1 to 3 as pawns for their first move can go forward 2 slots. removing 0 let the is selected function do its job
|
||||
|
||||
if(selectX == x && selectY == y+i) {
|
||||
isAPieceHere = true;
|
||||
break;
|
||||
}
|
||||
if(selectX == x && selectY == y+i) { // this loop iterates 2 times trough the for loop, giving multiples coordinates to highlight ( here : (x;y+1)&(x;y+1))
|
||||
isAPieceHere = true; //set the boolean var to true
|
||||
}
|
||||
}else if (type == PieceType.Pawn && color == false) {
|
||||
}
|
||||
} else if (type == PieceType.Pawn && color == false) {
|
||||
for(int i = 1; i < 3;i++) {
|
||||
|
||||
if(selectX == x && selectY == y-i) {
|
||||
isAPieceHere = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (type == PieceType.Bishop) {
|
||||
for(int i = 1; i < 6;i++) {
|
||||
|
||||
if(selectX == x+i && selectY == y+i || selectX == x-i && selectY == y-i || selectX == x-i && selectY == y+i || selectX == x+i && selectY == y-i) {
|
||||
isAPieceHere = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}else {
|
||||
for(int i = 1; i < 5;i++) {
|
||||
|
||||
if(selectX == x && selectY == y+i) {
|
||||
isAPieceHere = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return isAPieceHere;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue