knew that with getPieces with x and y for input, it could light up some
cases with specific pieces, trying to implement that
This commit is contained in:
parent
981a4ece1a
commit
8bcd0e2b14
|
|
@ -187,13 +187,21 @@ public class Board {
|
|||
// 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
|
||||
boolean color = false ; //color of the piece for pawns that can only go in -y for black and +Y for white
|
||||
if(myPiece != null) {
|
||||
|
||||
Piece everyOtherPiece = getPiece(x,y);
|
||||
PieceType typeOther = null; // type of piece variable that we will get trough a loop, this will determine the pattern of highlights on the board
|
||||
boolean colorOther = false;
|
||||
|
||||
boolean isAPieceHere = false ; // final return boolean value
|
||||
|
||||
if(myPiece != null && everyOtherPiece != null) {
|
||||
|
||||
type = myPiece.getType();
|
||||
color = myPiece.isWhite();
|
||||
typeOther = everyOtherPiece.getType(); // type of piece variable that we will get trough a loop, this will determine the pattern of highlights on the board
|
||||
colorOther = everyOtherPiece.isWhite();
|
||||
}
|
||||
|
||||
// from here its spaghetti but its works ! i'll explain one, its the same logic for all of them
|
||||
|
|
@ -204,7 +212,7 @@ public class Board {
|
|||
isAPieceHere = true; //set the boolean var to true
|
||||
}
|
||||
}
|
||||
} else if (type == PieceType.Pawn && color == false) {
|
||||
} else if (type == PieceType.Pawn && color == false || colorOther == false ) {
|
||||
for(int i = 1; i < 3;i++) {
|
||||
|
||||
if(selectX == x && selectY == y-i) {
|
||||
|
|
@ -214,7 +222,7 @@ 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
|
||||
// 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue