debugging turnNb, now works correctly

This commit is contained in:
hugomanipoud2 2025-05-22 17:05:45 +02:00
parent 36cdfd1230
commit 61f1b5e83a
2 changed files with 10 additions and 6 deletions

View File

@ -7,7 +7,7 @@ public class Board {
private int line; // constructors for column and line
public ArrayList<Piece> pieces; // list of all pieces on the board
private Piece newPiece; // to add a piece to the board
private int turnNb = 0;
public int turnNb = 0;
private int selectX = -1;
private int selectY = -1;
private Move move;
@ -31,7 +31,11 @@ public class Board {
}
public int getTurnNumber() {
return this.turnNb;
return turnNb;
}
public void setTurnNb(int turnNb) {
this.turnNb = turnNb;
}
public int getZero() {
@ -115,7 +119,6 @@ public class Board {
boardState += bOrW + "[" + type + "] (" + xCord + ";" + yCord + ")\n"; // str concatenation
bOrW = ""; //reinitialization of this local var bc white and black will pile up if not
zero++;
}
return boardState; //gives back the full string
@ -145,7 +148,6 @@ public class Board {
} else {
move.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;
}
@ -208,7 +210,7 @@ public class Board {
type = myPiece.getType();
color = myPiece.isWhite();
yCord = myPiece.getY();
yCord = myPiece.getY();
}

View File

@ -20,7 +20,8 @@ public class Move {
Piece movingPiece = null ; // initializing variable to work with and store it
PieceType type = null;
boolean color = true;
int turnNb = board.getTurnNumber(); // Increment turn number and change turn color; // Increment turn number and change turn color
for (Piece piece : pieces) { // iterate trough all pieces
if(piece.getX() == selectX && piece.getY() == selectY) { // if the coordinates selected and the coordinate of a piece on the board matches, the loop will activate
@ -41,6 +42,7 @@ public class Move {
}
movingPiece.setX(toX); // change coordinates to the new coordinate
movingPiece.setY(toY);
board.setTurnNb(turnNb + 1);
}
break;
}