pieces can now only go to highlighted cases, im litteraly a genius
This commit is contained in:
parent
ab4e2b2d32
commit
981a4ece1a
|
|
@ -215,7 +215,8 @@ public class Board {
|
||||||
} else if (type == PieceType.Bishop) {
|
} else if (type == PieceType.Bishop) {
|
||||||
for(int i = 1; i < 8;i++) {
|
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) {
|
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;
|
isAPieceHere = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +224,8 @@ public class Board {
|
||||||
} else if (type == PieceType.Rook) {
|
} 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) {
|
if(selectX == x+i && selectY == y || selectX == x && selectY == y+i ||
|
||||||
|
selectX == x-i && selectY == y || selectX == x && selectY == y-i) {
|
||||||
isAPieceHere = true;
|
isAPieceHere = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -231,14 +233,20 @@ public class Board {
|
||||||
} else if (type == PieceType.Queen) {
|
} 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) {
|
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;
|
isAPieceHere = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (type == PieceType.Knight) {
|
} 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 ) {
|
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;
|
isAPieceHere = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +254,10 @@ public class Board {
|
||||||
} else if (type == PieceType.King){
|
} else if (type == PieceType.King){
|
||||||
for(int i = 1; i < 2;i++) {
|
for(int i = 1; i < 2;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) {
|
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;
|
isAPieceHere = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,20 @@ public class Move {
|
||||||
type = movingPiece.getType();
|
type = movingPiece.getType();
|
||||||
color = movingPiece.isWhite();
|
color = movingPiece.isWhite();
|
||||||
|
|
||||||
if (board.isAPieceThere(toX, toY)){//checking if a piece is at the arrival coordinates
|
if (board.isHighlighted(toX, toY)) {
|
||||||
needPieceDeletion(toX, toY); //if a piece is at arrival coord, remove the piece
|
|
||||||
|
if (board.isAPieceThere(toX, toY)){//checking if a piece is at the arrival coordinates
|
||||||
|
needPieceDeletion(toX, toY); //if a piece is at arrival coord, remove the piece
|
||||||
}
|
}
|
||||||
if(type == PieceType.Pawn && color == true && toY == 0) {
|
if(type == PieceType.Pawn && color == true && toY == 0) {
|
||||||
pawnPromotion(movingPiece);
|
pawnPromotion(movingPiece);
|
||||||
}
|
}
|
||||||
if(type == PieceType.Pawn && color == false && toY == 7) {
|
if(type == PieceType.Pawn && color == false && toY == 7) {
|
||||||
pawnPromotion(movingPiece);
|
pawnPromotion(movingPiece);
|
||||||
|
}
|
||||||
|
movingPiece.setX(toX); // change coordinates to the new coordinate
|
||||||
|
movingPiece.setY(toY);
|
||||||
}
|
}
|
||||||
movingPiece.setX(toX); // change coordinates to the new coordinate
|
|
||||||
movingPiece.setY(toY);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue