Fix ArrayOutOfBoundException when we didn't have a winner

This commit is contained in:
Quentin Legot 2021-11-18 11:06:13 +01:00
parent e2bd1a8bf6
commit 360a84c403
2 changed files with 3 additions and 2 deletions

View File

@ -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() {

View File

@ -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"));
}
}