tostring essai d'amelioration

This commit is contained in:
hugomanipoud2 2025-05-21 16:38:16 +02:00
parent a3159cc55e
commit 94858166b9
2 changed files with 20 additions and 5 deletions

View File

@ -12,8 +12,15 @@ public class Main {
// testing :
Board testBoard = new Board(8, 8);
testBoard.populateBoard();
System.out.println(testBoard.toString());
System.out.println(testBoard.getPiece(1,1));
int turnNb = testBoard.getTurnNumber();
int zero = testBoard.getZero();
if (turnNb > zero) {
System.out.println(testBoard.toString());
zero++;
}
// launches graphical interface :
MyInterface mjf = new MyInterface();

View File

@ -11,6 +11,7 @@ public class Board {
private int selectX = -1;
private int selectY = -1;
private Move move;
private int zero = -1;
//initiation of the board, creating an 8 * 8 grid
public Board(int colNum, int lineNum) {
@ -32,6 +33,10 @@ public class Board {
public int getTurnNumber() {
return this.turnNb;
}
public int getZero() {
return this.zero;
}
public boolean isTurnWhite() {
if (turnNb % 2 == 0){
@ -93,8 +98,8 @@ public class Board {
public String toString() {
//initialize the str variable + black and white str
String boardState = "";
String bOrW = "" ;
String bOrW = "" ;
//initialize the str variable + black and white str
//for loop that iterates through all the pieces in the arraylist pieces, adding conditions and simplifying the state of the board
for(Piece piece : pieces) {
if(piece.isWhite() == true) {
@ -110,10 +115,13 @@ 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
//TODO
//maybe i should add a flag variable to display 5 or 6 coordinates on the same line if i have time instead of 1 coord per line
}
public ArrayList<Piece> getPieces() {