Fix ArrayOutOfBoundException when we didn't have a winner
This commit is contained in:
parent
e2bd1a8bf6
commit
360a84c403
@ -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() {
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user