Fix player who stayed on the grid

This commit is contained in:
Katchan 2021-12-07 21:38:43 +01:00
parent 4958c7688e
commit a6b9b69d9b

View File

@ -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<CountdownBox> countdownBoxes = this.getGrid().getAllCountdownElements();
countdownBoxes.forEach(CountdownBox::update);
@ -84,6 +94,10 @@ public class Game {
return players.parallelStream().filter(Player::isAlive);
}
public Stream<Player> getPlayersNotAlive() {
return players.parallelStream().filter(not(Player::isAlive));
}
public boolean isOver() {
return getPlayersAlive().count() <= 1;
}