pieces can now only go to highlighted cases, im litteraly a genius

This commit is contained in:
hugomanipoud2 2025-05-21 11:12:40 +02:00
parent ab4e2b2d32
commit 981a4ece1a
2 changed files with 27 additions and 13 deletions

View File

@ -215,7 +215,8 @@ 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) {
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;
}
}
@ -223,7 +224,8 @@ public class Board {
} else if (type == PieceType.Rook) {
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;
}
}
@ -231,14 +233,20 @@ public class Board {
} else if (type == PieceType.Queen) {
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;
}
}
} 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;
}
@ -246,7 +254,10 @@ public class Board {
} else if (type == PieceType.King){
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;
}
}

View File

@ -28,17 +28,20 @@ public class Move {
type = movingPiece.getType();
color = movingPiece.isWhite();
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 (board.isHighlighted(toX, toY)) {
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) {
pawnPromotion(movingPiece);
if(type == PieceType.Pawn && color == true && toY == 0) {
pawnPromotion(movingPiece);
}
if(type == PieceType.Pawn && color == false && toY == 7) {
pawnPromotion(movingPiece);
if(type == PieceType.Pawn && color == false && toY == 7) {
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;
}
}