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();