pawns now can go up 2 cases IFF they never moved
This commit is contained in:
parent
8bcd0e2b14
commit
59c9394a93
|
|
@ -189,37 +189,54 @@ public class Board {
|
|||
Piece myPiece = getPiece(selectX,selectY);//get the piece at the selected x and y on the board
|
||||
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
|
||||
int yCord = -1;
|
||||
|
||||
// Piece everyOtherPiece = getPiece(x,y); // everypiece on the board, maybe to use
|
||||
|
||||
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) {
|
||||
if(myPiece != 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();
|
||||
yCord = myPiece.getY();
|
||||
}
|
||||
|
||||
// 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) { // 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
|
||||
if(yCord == 6) { //this condition is specific to the pawn, pawns can move 2 cases for their first move, but once they moved once they can move only 1 case. as they cant go back, this simple condition allows for regulation of this rule
|
||||
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) { // this loop iterates 2 times trough the for loop, giving multiples coordinates to highlight ( here : (x;y+1)&(x;y+2))
|
||||
isAPieceHere = true; //set the boolean var to true
|
||||
}
|
||||
}
|
||||
|
||||
}else {
|
||||
for(int i = 1; i < 2;i++) {
|
||||
if(selectX == x && selectY == y+i) {
|
||||
isAPieceHere = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else if (type == PieceType.Pawn && color == false || colorOther == false ) {
|
||||
for(int i = 1; i < 3;i++) {
|
||||
} else if (type == PieceType.Pawn && color == false) {
|
||||
if(yCord == 1) {
|
||||
for(int i = 1; i < 3;i++) {
|
||||
|
||||
if(selectX == x && selectY == y-i) {
|
||||
isAPieceHere = true;
|
||||
if(selectX == x && selectY == y-i) {
|
||||
isAPieceHere = true;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for(int i = 1; i < 2;i++) {
|
||||
|
||||
if(selectX == x && selectY == y-i) {
|
||||
isAPieceHere = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue