From 3066ecf2116e1fcf6d02454bded53abadf509f57 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Fri, 3 Dec 2021 15:22:00 +0100 Subject: [PATCH] Fix critical bug --- server/src/main/java/fr/lnl/game/server/games/Game.java | 6 +++++- .../fr/lnl/game/server/games/player/AbstractPlayer.java | 3 +++ server/src/test/java/fr/lnl/game/server/Mock.java | 3 --- 3 files changed, 8 insertions(+), 4 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 58b918f..1406c89 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 @@ -23,12 +23,16 @@ public class Game { private Action selectedAction = null; public Game(Grid grid, List players, ModelListener gameFinishEvent) throws IllegalArgumentException { - if(players.size() < 2 || players.size() > grid.getNumberNeutralBox()) + 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.players = players; this.currentPlayer = players.get(0); this.grid = grid; this.gameFinishEvent = gameFinishEvent; + this.grid.initPlacePlayers(); currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer)); } diff --git a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java index 7f85b36..41dcfdd 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java @@ -87,6 +87,9 @@ public abstract class AbstractPlayer implements Player { @Override public void setPosition(Point position){ + if(position == null){ + throw new IllegalArgumentException("Position is null"); + } this.position = position; } diff --git a/server/src/test/java/fr/lnl/game/server/Mock.java b/server/src/test/java/fr/lnl/game/server/Mock.java index a7f5526..98644cb 100644 --- a/server/src/test/java/fr/lnl/game/server/Mock.java +++ b/server/src/test/java/fr/lnl/game/server/Mock.java @@ -23,9 +23,6 @@ public class Mock { List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); this.grid = new Grid(16,16, players,0.80F, 0.95F); - placePlayersBRUT(); - placeEnergyBallBRUT(); - placeInternWallBRUT(); game = new Game(grid, players, new GameFinishEvent()); }