added knight ishiglighted
This commit is contained in:
parent
66a94a17cf
commit
8d8f155fa0
|
|
@ -185,6 +185,8 @@ public class Board {
|
|||
|
||||
public boolean isHighlighted(int x, int y) {
|
||||
|
||||
// knowing that getPiece(x,y) get all hypothetical pieces, i could use it to show only allowed placements and stopping the spread of ishiglighted to impossible moves ?
|
||||
|
||||
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
|
||||
|
|
@ -213,27 +215,34 @@ public class Board {
|
|||
|
||||
} else if (type == PieceType.Bishop) {
|
||||
for(int i = 1; i < 8;i++) {
|
||||
|
||||
// the sign is an "or" condition, its needed to fullfill all the case possible, if not we are just heading to one direction
|
||||
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 if (type == PieceType.Rook) {
|
||||
for(int i = 1; i < 8;i++) {
|
||||
for(int i = 1; i < 8;i++) {
|
||||
|
||||
if(selectX == x+i && selectY == y || selectX == x && selectY == y+i || selectX == x-i && selectY == y || selectX == x && selectY == y-i) {
|
||||
isAPieceHere = true;
|
||||
if(selectX == x+i && selectY == y || selectX == x && selectY == y+i || selectX == x-i && selectY == y || selectX == x && selectY == y-i) {
|
||||
isAPieceHere = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (type == PieceType.Queen) {
|
||||
for(int i = 1; i < 8;i++) {
|
||||
for(int i = 1; i < 8;i++) {
|
||||
|
||||
if(selectX == x+i && selectY == y || selectX == x && selectY == y+i || selectX == x-i && selectY == y || selectX == x && selectY == y-i || 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;
|
||||
if(selectX == x+i && selectY == y || selectX == x && selectY == y+i || selectX == x-i && selectY == y || selectX == x && selectY == y-i || 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 if (type == PieceType.Knight) {
|
||||
|
||||
if(selectX == x+1 && selectY == y+2 || selectX == x-1 && selectY == y-2 ||selectX == x-1 && selectY == y+2 || selectX == x+1 && selectY == y-2 || selectX == x+2 && selectY == y+1 || selectX == x-2 && selectY == y-1 ||selectX == x-2 && selectY == y+1 || selectX == x+2 && selectY == y-1 ) {
|
||||
isAPieceHere = true;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
for(int i = 1; i < 5;i++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue