From 82ec202ad34794fc00b2fa18c1f858824efe320f Mon Sep 17 00:00:00 2001 From: "lymeng.ly" Date: Fri, 9 May 2025 09:24:59 +0200 Subject: [PATCH] Updated again --- src/backend/Board.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index b82a926..611bf53 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -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 - } + + } }