Updated again

This commit is contained in:
Lymeng LY 2025-05-09 09:24:59 +02:00
parent 14f88abd3d
commit 82ec202ad3
1 changed files with 9 additions and 8 deletions

View File

@ -178,8 +178,8 @@ public class Board {
} }
//To check if square valid //To check if square valid
boolean valid = false; boolean valid = false;
for (int[] pos : highlightedPositions) { for (int[] pos : highlightedPositions) {
if (pos[0]==x&&pos[1]==y) { if (pos[0]==x&&pos[1]==y) {
valid = true; valid = true;
break; break;
@ -187,16 +187,16 @@ public class Board {
// If a piece is selected and the user clicks a new position // If a piece is selected and the user clicks a new position
else { else {
// Check if the move is valid by checking if it exists in highlightedPositions // Check if the move is valid by checking if it exists in highlightedPositions
boolean isValidMove = false; boolean isValidMove = false;
for (int[] pos : highlightedPositions) { for (int[] pos : highlightedPositions) {
if (pos[0] == x && pos[1] == y) { if (pos[0] == x && pos[1] == y) {
isValidMove = true; isValidMove = true;
break; break;
} }
} }
}
// Only move the piece if the destination is valid // Only move the piece if the destination is valid
if (isValidMove) { if (isValidMove) {
movePiece(selectedX, selectedY, x, y); movePiece(selectedX, selectedY, x, y);
@ -225,7 +225,8 @@ public class Board {
this.selectedPosition = null; this.selectedPosition = null;
highlightedPositions.clear();//Clear after move highlightedPositions.clear();//Clear after move
}
}
} }