Fix critical bug

This commit is contained in:
Katchan 2021-12-03 15:22:00 +01:00
parent 7afd79b929
commit 3066ecf211
3 changed files with 8 additions and 4 deletions

View File

@ -23,12 +23,16 @@ public class Game {
private Action selectedAction = null; private Action selectedAction = null;
public Game(Grid grid, List<Player> players, ModelListener gameFinishEvent) throws IllegalArgumentException { public Game(Grid grid, List<Player> 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"); 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.players = players;
this.currentPlayer = players.get(0); this.currentPlayer = players.get(0);
this.grid = grid; this.grid = grid;
this.gameFinishEvent = gameFinishEvent; this.gameFinishEvent = gameFinishEvent;
this.grid.initPlacePlayers();
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer)); currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
} }

View File

@ -87,6 +87,9 @@ public abstract class AbstractPlayer implements Player {
@Override @Override
public void setPosition(Point position){ public void setPosition(Point position){
if(position == null){
throw new IllegalArgumentException("Position is null");
}
this.position = position; this.position = position;
} }

View File

@ -23,9 +23,6 @@ public class Mock {
List<Player> players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), List<Player> players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT),
new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT));
this.grid = new Grid(16,16, players,0.80F, 0.95F); this.grid = new Grid(16,16, players,0.80F, 0.95F);
placePlayersBRUT();
placeEnergyBallBRUT();
placeInternWallBRUT();
game = new Game(grid, players, new GameFinishEvent()); game = new Game(grid, players, new GameFinishEvent());
} }