Modifications about the memory, trying to solve the pbm : cant' play

after having load what was saved
This commit is contained in:
clara 2025-05-13 11:41:04 +02:00
parent 9002f635f0
commit be44e497c4
5 changed files with 46 additions and 28 deletions

View File

@ -1,3 +1,4 @@
eclipse.preferences.version=1
encoding//src/Main.java=UTF-8
encoding//src/backend/Board.java=UTF-8
encoding/<project>=windows-1252

View File

@ -5,6 +5,13 @@ import backend.PieceType;
import windowInterface.MyInterface;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.ArrayList;
public class Main {
@ -25,6 +32,14 @@ public class Main {
MyInterface mjf = new MyInterface();
mjf.setVisible(true);
//print the table for the memory
}
}
}

View File

@ -202,35 +202,33 @@ public class Board {
/* saving-loading feature :*/
public String[] toFileRep() {
ArrayList<String> lines = new ArrayList<>();
ArrayList<String> lines = new ArrayList<>();
// Line 0 : number tour
lines.add(String.valueOf(turnNumber));
// Line 1 : color of the player
lines.add(String.valueOf(isWhiteTurn));
lines.add(String.valueOf(turnNumber)); //nombre xe tours
lines.add(String.valueOf(isWhiteTurn)); //couleur du joueur
// Line 2+: each piece
for (Piece piece : pieces) {
String line = piece.getType() + "," + piece.getX() + "," + piece.getY() + "," + piece.isWhite();
lines.add(line);
}
for (Piece piece : pieces) { //ajoute la pièce à la mémoire
String line = piece.getType() + "," + piece.getX() + "," + piece.getY() + "," + piece.isWhite();
lines.add(line);
}
System.out.println("The modifications are: " + lines);
return lines.toArray(new String[0]);
}
return lines.toArray(new String[0]);
}
public Board(String[] array) {
this.colNum = 8;
this.lineNum = 8;
this.turnNumber = Integer.parseInt(array[0]);
this.isWhiteTurn = Boolean.parseBoolean(array[1]);
this.pieces = new ArrayList<>();
for (int i = 2; i < array.length; i++) {
String[] parts = array[i].split(",");
PieceType type = PieceType.valueOf(parts[0]);
@ -238,8 +236,8 @@ public class Board {
int y = Integer.parseInt(parts[2]);
boolean isWhite = Boolean.parseBoolean(parts[3]);
pieces.add(new Piece(x, y, isWhite, type));}
System.out.println("The modifications are: " + pieces);
pieces.add(new Piece(x, y, isWhite, type));
}
}
/* The following methods require more work ! */

View File

@ -38,4 +38,8 @@ public class Piece {
this.y = y;
}
public String toString() {
return (isWhite ? "White " : "Black ") + type + " at (" + x + "," + y + ")";
}
}

View File

@ -1,4 +1,4 @@
package backend;
/*package backend;
public class SpecialMoves {
private Piece piece;
@ -21,7 +21,7 @@ public class SpecialMoves {
int[][] offsets = {{1, 2}, {-1, 2}};
}*/
public boolean checkCoordinates(int x, int y, PieceType type, boolean isWhite) {
/* public boolean checkCoordinates(int x, int y, PieceType type, boolean isWhite) {
if (type == PieceType.Pawn || isWhite == true || y == 3) {
int[][] offsets = {{1, 0}, {-1, 0}};
@ -45,4 +45,4 @@ public class SpecialMoves {
}
}
}
}*/