From 94858166b9b813bd818aaace05e31262f489c443 Mon Sep 17 00:00:00 2001 From: hugomanipoud2 Date: Wed, 21 May 2025 16:38:16 +0200 Subject: [PATCH] tostring essai d'amelioration --- OOP_3B5_Project/src/Main.java | 11 +++++++++-- OOP_3B5_Project/src/backend/Board.java | 14 +++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/OOP_3B5_Project/src/Main.java b/OOP_3B5_Project/src/Main.java index 44ac36e..2f4232b 100644 --- a/OOP_3B5_Project/src/Main.java +++ b/OOP_3B5_Project/src/Main.java @@ -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(); diff --git a/OOP_3B5_Project/src/backend/Board.java b/OOP_3B5_Project/src/backend/Board.java index 2e47993..f855b0b 100644 --- a/OOP_3B5_Project/src/backend/Board.java +++ b/OOP_3B5_Project/src/backend/Board.java @@ -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 getPieces() {