Update the board file
This commit is contained in:
parent
2dfd232a84
commit
deafffe450
|
|
@ -171,19 +171,31 @@ public class Board {
|
||||||
if(selectedX == x && selectedY == y) {
|
if(selectedX == x && selectedY == y) {
|
||||||
selectedPosition = null;
|
selectedPosition = null;
|
||||||
highlightedPositions.clear(); //Unhighlight
|
highlightedPositions.clear(); //Unhighlight
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
//To check if square valid
|
||||||
// If a piece is selected and the user clicks a new position
|
boolean valid = false;
|
||||||
else {
|
for (int[] pos : highlightedPositions) {
|
||||||
movePiece(selectedX,selectedY,x,y);
|
if (pos[0]==x&&pos[1]==y) {
|
||||||
// Update turn
|
valid = true;
|
||||||
this.turnNumber++;
|
break;
|
||||||
this.turnWhite=!this.turnWhite;
|
}
|
||||||
|
|
||||||
// Deselect the position after moving
|
|
||||||
this.selectedPosition = null;
|
|
||||||
highlightedPositions.clear();//Clear after move
|
|
||||||
}
|
}
|
||||||
|
// If a piece is selected and the user clicks a new position
|
||||||
|
if (valid) {
|
||||||
|
movePiece(selectedX, selectedY, x, y);
|
||||||
|
//update turn
|
||||||
|
this.turnNumber++;
|
||||||
|
this.turnWhite=!this.turnWhite;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Blocked! This is not a valid move.");
|
||||||
|
|
||||||
|
}
|
||||||
|
// Deselect the position after moving
|
||||||
|
this.selectedPosition = null;
|
||||||
|
highlightedPositions.clear();//Clear after move
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue