diff --git a/src/Main.java b/src/Main.java index 847f065..df45504 100644 --- a/src/Main.java +++ b/src/Main.java @@ -5,6 +5,11 @@ import backend.PieceType; import windowInterface.MyInterface; +<<<<<<< HEAD +======= + + +>>>>>>> branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git public class Main { @@ -25,13 +30,11 @@ public class Main { MyInterface mjf = new MyInterface(); mjf.setVisible(true); - - //print the table for the memory } - } + } diff --git a/src/backend/Board.java b/src/backend/Board.java index 3f25832..3b228be 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -199,43 +199,46 @@ public class Board { } /* saving-loading feature :*/ + //this public method returns String[] + public String[] toFileRep() { //converts the game into a chain of characters : state of the game + ArrayList lines = new ArrayList<>();//creates a list arraylist to store each line of the save data as a string - public String[] toFileRep() { - ArrayList lines = new ArrayList<>(); + //number of tour + lines.add(String.valueOf(turnNumber));//It's converted to a string using String.valueOf - // Line 0 : number tour - lines.add(String.valueOf(turnNumber)); + //color of the player + lines.add(String.valueOf(isWhiteTurn));//same - // Line 1 : color of the player - lines.add(String.valueOf(isWhiteTurn)); - - // Line 2+: each piece - for (Piece piece : pieces) { + // piece type position and color + for (Piece piece : pieces) { //loop through all pieces of the game String line = piece.getType() + "," + piece.getX() + "," + piece.getY() + "," + piece.isWhite(); lines.add(line); } - return lines.toArray(new String[0]); + return lines.toArray(new String[0]); //Converts the ArrayList to a fixed-size String[] and returns it } - - public Board(String[] array) { - this.colNum = 8; + //constructor for the Board class. + public Board(String[] array) { //takes the previous string and reconstruct the game state from it + this.colNum = 8;//dimensions initialized this.lineNum = 8; - this.turnNumber = Integer.parseInt(array[0]); - this.isWhiteTurn = Boolean.parseBoolean(array[1]); + this.turnNumber = Integer.parseInt(array[0]);//array[0] is the turn number (converted from string to int), - this.pieces = new ArrayList<>(); + this.isWhiteTurn = Boolean.parseBoolean(array[1]);//array[1] is the current player’s turn (converted from string to boolean). + + this.pieces = new ArrayList<>();//initialize empty list to hold all pieces for (int i = 2; i < array.length; i++) { + String[] parts = array[i].split(","); + PieceType type = PieceType.valueOf(parts[0]); int x = Integer.parseInt(parts[1]); int y = Integer.parseInt(parts[2]); boolean isWhite = Boolean.parseBoolean(parts[3]); - pieces.add(new Piece(x, y, isWhite, type)); + pieces.add(new Piece(x, y, isWhite, type)); //Creates a new Piece with the extracted data and adds it to the pieces list. } } diff --git a/src/backend/Game.java b/src/backend/Game.java index 4c64f70..51d0356 100644 --- a/src/backend/Game.java +++ b/src/backend/Game.java @@ -23,6 +23,8 @@ public class Game extends Thread { aiPlayer = new AutoPlayer(); } + + public int getWidth() { return board.getWidth(); } @@ -85,6 +87,7 @@ public class Game extends Thread { public void setBoard(String[] array) { board = new Board(array); + } public Iterable getPieces() {