From 40e61c452d434cf305ef9dfe9312f304a123cfa9 Mon Sep 17 00:00:00 2001 From: Dorian HAMDANI Date: Mon, 7 Apr 2025 08:57:53 +0200 Subject: [PATCH] Remove board dimensions and update load() method --- src/GomokuGame.java | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/GomokuGame.java b/src/GomokuGame.java index 10eee43..91783bd 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -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;