diff --git a/src/GomokuBoard.java b/src/GomokuBoard.java index 6f469be..f8d7ecd 100644 --- a/src/GomokuBoard.java +++ b/src/GomokuBoard.java @@ -129,6 +129,8 @@ public class GomokuBoard{ * @return GomokuCell in the position. */ public GomokuCell get(int x, int y){ + if (x < 0 || x >= this.boardWidth) return null; + if (y < 0 || y >= this.boardHeight) return null; int i = 0, j = 0; GomokuCell act = this.firstCell; while (i != x || j != y){ diff --git a/src/GomokuGame.java b/src/GomokuGame.java index 2078028..3c66c4a 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -31,14 +31,67 @@ public class GomokuGame { } public static void main(String[] args) { + + int sizeX = 0; + int sizeY = 0; + int nbToken = 0; + int nbJetonsAligne = 0; + boolean renderer = false; + + + for (int i = 0; i < args.length; i++) { + switch (args[i]) { + case "--save": + if (i + 1 < args.length) { + //load(g.load(Path.of(".cache/test.dat"))); + } + break; + + case "--size": + if (i + 2 < args.length) { + sizeX = Integer.parseInt(args[++i]); + sizeY = Integer.parseInt(args[++i]); + } + break; + + case "--nbToken": + if (i + 1 < args.length) { + nbToken = Integer.parseInt(args[++i]); + } + break; + + case "--nbTokenToWin": + if (i + 1 < args.length) { + nbJetonsAligne = Integer.parseInt(args[++i]); + } + break; + + case "--renderer": + if (i + 1 < args.length) { + String bool = args[++i]; + if(bool=="true"){ + renderer = true; + } + else { + renderer=false; + } + } + break; + + default: + System.out.println("Invalid option : " + args[i]); + break; + } + } + // Test - GomokuGame g = new GomokuGame(false); - System.out.println(g.load(Path.of(".cache/test.dat"))); + GomokuGame g = new GomokuGame(renderer);//metre true ou fals si in veut l'affichage ou non g.renderer = new ConsoleRenderer(); - g.renderer.init(g); g.renderer.update(); g.board.expandBoard(Cardinal.SE); g.renderer.update(); + + } /** @@ -166,13 +219,13 @@ public class GomokuGame { // Write the board for (int i = 0; i < this.getBoard().getHeight(); ++i) { for (int j = 0; j < this.getBoard().getWidth(); ++j) { - char c = ' '; + char c; switch (board.get(i, j).getState()) { case BLACK: c = 'X'; break; case WHITE: - + c = 'O'; break; case NIL: c = '.';