Updated again
This commit is contained in:
parent
14f88abd3d
commit
82ec202ad3
|
|
@ -178,8 +178,8 @@ public class Board {
|
|||
}
|
||||
|
||||
//To check if square valid
|
||||
boolean valid = false;
|
||||
for (int[] pos : highlightedPositions) {
|
||||
boolean valid = false;
|
||||
for (int[] pos : highlightedPositions) {
|
||||
if (pos[0]==x&&pos[1]==y) {
|
||||
valid = true;
|
||||
break;
|
||||
|
|
@ -187,16 +187,16 @@ public class Board {
|
|||
|
||||
|
||||
// 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
|
||||
boolean isValidMove = false;
|
||||
for (int[] pos : highlightedPositions) {
|
||||
if (pos[0] == x && pos[1] == y) {
|
||||
boolean isValidMove = false;
|
||||
for (int[] pos : highlightedPositions) {
|
||||
if (pos[0] == x && pos[1] == y) {
|
||||
isValidMove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Only move the piece if the destination is valid
|
||||
if (isValidMove) {
|
||||
movePiece(selectedX, selectedY, x, y);
|
||||
|
|
@ -225,7 +225,8 @@ public class Board {
|
|||
this.selectedPosition = null;
|
||||
highlightedPositions.clear();//Clear after move
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue