From a6b9b69d9bfeed6a993381f67d88d5377fb331b9 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Tue, 7 Dec 2021 21:38:43 +0100 Subject: [PATCH] Fix player who stayed on the grid --- .../main/java/fr/lnl/game/server/games/Game.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 c7cd4f2..2b31935 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 @@ -12,8 +12,11 @@ import fr.lnl.game.server.listener.ModelListener; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import java.util.stream.Stream; +import static java.util.function.Predicate.not; + public class Game { private final GridFactoryBuilder buildStrategy; @@ -48,6 +51,7 @@ public class Game { selectedAction = currentPlayer.choseAction(); selectedAction.doAction(); countdownGridElementsUpdate(); + gridPlayersUpdate(); nextCurrentPlayer(); currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer)); if(isOver()) { @@ -55,6 +59,12 @@ public class Game { } } + private void gridPlayersUpdate(){ + for (Player player: getPlayersNotAlive().toList()) { + getGrid().getBoard().get(player.getPosition()).setA(null); + } + } + private void countdownGridElementsUpdate() { List countdownBoxes = this.getGrid().getAllCountdownElements(); countdownBoxes.forEach(CountdownBox::update); @@ -84,6 +94,10 @@ public class Game { return players.parallelStream().filter(Player::isAlive); } + public Stream getPlayersNotAlive() { + return players.parallelStream().filter(not(Player::isAlive)); + } + public boolean isOver() { return getPlayersAlive().count() <= 1; }