From aea8ac654d226f57fec0cc35be9f0f82fa68a48c Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Sat, 4 Dec 2021 15:36:47 +0100 Subject: [PATCH] Fix build function call --- .../src/main/java/fr/lnl/game/server/games/Game.java | 11 +++++------ .../games/grid/build/AbstractBuildStrategy.java | 3 +-- .../game/server/games/grid/build/BuildStrategy.java | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/fr/lnl/game/server/games/Game.java b/server/src/main/java/fr/lnl/game/server/games/Game.java index 22b389c..f96d84f 100644 --- a/server/src/main/java/fr/lnl/game/server/games/Game.java +++ b/server/src/main/java/fr/lnl/game/server/games/Game.java @@ -26,6 +26,11 @@ public class Game { public Game(BuildStrategy buildStrategy, List players, ModelListener gameFinishEvent) throws IllegalArgumentException { this.grid = buildStrategy.getGrid(); + if(players.size() < 2) + throw new IllegalArgumentException("The game need 2 or more player to start"); + if(players.size() > grid.getNumberNeutralBox()){ + throw new IllegalArgumentException("There are too many players for the number of box available"); + } this.buildStrategy = buildStrategy; this.players = players; this.currentPlayer = players.get(0); @@ -34,12 +39,6 @@ public class Game { } public void initGame(){ - buildStrategy.build(); - if(players.size() < 2) - throw new IllegalArgumentException("The game need 2 or more player to start"); - if(players.size() > grid.getNumberNeutralBox()){ - throw new IllegalArgumentException("There are too many players for the number of box available"); - } buildStrategy.initPlacePlayers(); currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer)); } diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java b/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java index 80b3d05..b2d2dc0 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java @@ -11,10 +11,9 @@ public abstract class AbstractBuildStrategy implements BuildStrategy{ this.GRID = grid; this.WALL_PROBABILITY = wallProbability; this.ENERGY_PROBABILITY = energyProbability; + build(); } - - @Override public void build() { initGrid(); initPlaceInternWall(WALL_PROBABILITY); diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java b/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java index 9d0b144..16f4e9c 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java @@ -4,7 +4,6 @@ import fr.lnl.game.server.games.grid.Grid; public interface BuildStrategy { - void build(); void initPlacePlayers(); Grid getGrid();