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 1272a6a..fdd9f35 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 @@ -29,7 +29,7 @@ public class Game { public Player getWinner() { // On part du principe que isOver est forcément appelé avant d'appeler getWinner - return players.parallelStream().filter(player -> !player.isAlive()).findFirst().orElseThrow(ArrayIndexOutOfBoundsException::new); + return players.parallelStream().filter(player -> !player.isAlive()).findFirst().orElse(null); } public Player getCurrentPlayer() { diff --git a/server/src/test/java/fr/lnl/game/server/GridTest.java b/server/src/test/java/fr/lnl/game/server/GridTest.java index 9519ca9..97665ba 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -82,7 +82,8 @@ public class GridTest { game.nextCurrentPlayer(); } System.out.println(game.getGrid().toString()); - System.out.println("Le joueur gagnant : " + game.getWinner().getId()); + Player winner = game.getWinner(); + System.out.println(winner != null ? ("Le joueur gagnant : " + winner.getId()) : ("Partie nulle, aucun gagnant")); } }