fixed the issue, setSelected had its if statement compparing selY with X

instead of Y, due to copy paste the line elsewhere and not verifying
This commit is contained in:
hugomanipoud2 2025-05-19 15:10:26 +02:00
parent 0a8cd17dc6
commit be812038d3
1 changed files with 10 additions and 10 deletions

View File

@ -120,19 +120,19 @@ public class Board {
}
public void userTouch(int x, int y) {
if(selectX == -1 && selectY == -1) {
if(setSelectXY(x,y) == true) {
selectX = x;
selectY = y;
if(selectX == -1 && selectY == -1) { // if initial position for select x and y
if(setSelectXY(x,y) == true) { // checks for pieces at the position x and y
selectX = x; //set select x to x
selectY = y; // same with y
}
} else {
if(selectX == x && selectY == y) {
} else { //if select x and y arent at their initial value (means that a piece is selected in the grid)
if(selectX == x && selectY == y) { //if cliking one more time on same pos, return to original var value (comeback to the beggining of loop)
selectX = -1;
selectY = -1;
} else {
movePiece(selectX, selectY, x, y);
// Increment turn number and change turn color
turnNb++;
movePiece(selectX, selectY, x, y); //if not clicking in same position, calls move piece to change the piece coordinates
turnNb++; // Increment turn number and change turn color
selectX = -1;
selectY = -1;
}
@ -153,7 +153,7 @@ public class Board {
public boolean setSelectXY(int x, int y) {
boolean isPieceHere = false; // setting bool var
for (Piece piece : pieces) { // iterate trough all pieces
if (piece.getX() == x && piece.getY() == x) {
if (piece.getX() == x && piece.getY() == y) {
isPieceHere = !isPieceHere; //chnaging the value to true if a piece is at the coordinates
}
}