Remove board dimensions and update load() method

This commit is contained in:
Dorian HAMDANI
2025-04-07 08:57:53 +02:00
parent 707ad73291
commit 40e61c452d

View File

@@ -13,10 +13,10 @@ public class GomokuGame {
private Player player1;
private Player player2;
private int boardWidth;
private int boardHeight;
private GomokuBoard board;
private GomokuRenderer renderer;
Color colorP1;
int currP;
int nbTokens1, nbTokens2;
@@ -25,15 +25,11 @@ public class GomokuGame {
// Test
GomokuGame g = new GomokuGame();
System.out.println(g.load(Path.of(".cache/test.dat")));
System.out.println(g.getBoard());
System.out.println(g.save(Path.of(".cache/save.dat")));
for (int i = 0; i < g.boardHeight; ++i) {
for (int j = 0; j < g.boardWidth; ++j) {
System.out.print(g.getBoard().get(i ,j));
}
System.out.println();
}
g.renderer = new ConsoleRenderer();
g.renderer.init(g);
g.renderer.update();
g.board.expandBoard(Cardinal.SE);
g.renderer.update();
}
public void newGame() {
@@ -61,11 +57,17 @@ public class GomokuGame {
try (BufferedWriter writer = Files.newBufferedWriter(filename)) {
// Write the first line
writer.write(String.format("%d %d %s %d %d %d%n",
this.boardWidth, this.boardHeight, colorP1, currP, nbTokens1, nbTokens2));
this.getBoard().getWidth(),
this.getBoard().getHeight(),
colorP1,
currP,
nbTokens1,
nbTokens2
));
// Write the board
for (int i = 0; i < boardHeight; ++i) {
for (int j = 0; j < boardWidth; ++j) {
for (int i = 0; i < this.getBoard().getHeight(); ++i) {
for (int j = 0; j < this.getBoard().getWidth(); ++j) {
char c;
switch (board.get(i, j).getState()) {
case BLACK: c = 'X'; break;
@@ -160,8 +162,6 @@ public class GomokuGame {
}
// Initialize the board with the read values
this.boardWidth = w;
this.boardHeight = h;
this.board = new GomokuBoard(w, h, colors);
return true;