Fix player who stayed on the grid
This commit is contained in:
parent
4958c7688e
commit
a6b9b69d9b
@ -12,8 +12,11 @@ import fr.lnl.game.server.listener.ModelListener;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static java.util.function.Predicate.not;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
|
|
||||||
private final GridFactoryBuilder buildStrategy;
|
private final GridFactoryBuilder buildStrategy;
|
||||||
@ -48,6 +51,7 @@ public class Game {
|
|||||||
selectedAction = currentPlayer.choseAction();
|
selectedAction = currentPlayer.choseAction();
|
||||||
selectedAction.doAction();
|
selectedAction.doAction();
|
||||||
countdownGridElementsUpdate();
|
countdownGridElementsUpdate();
|
||||||
|
gridPlayersUpdate();
|
||||||
nextCurrentPlayer();
|
nextCurrentPlayer();
|
||||||
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
|
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
|
||||||
if(isOver()) {
|
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() {
|
private void countdownGridElementsUpdate() {
|
||||||
List<CountdownBox> countdownBoxes = this.getGrid().getAllCountdownElements();
|
List<CountdownBox> countdownBoxes = this.getGrid().getAllCountdownElements();
|
||||||
countdownBoxes.forEach(CountdownBox::update);
|
countdownBoxes.forEach(CountdownBox::update);
|
||||||
@ -84,6 +94,10 @@ public class Game {
|
|||||||
return players.parallelStream().filter(Player::isAlive);
|
return players.parallelStream().filter(Player::isAlive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream<Player> getPlayersNotAlive() {
|
||||||
|
return players.parallelStream().filter(not(Player::isAlive));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isOver() {
|
public boolean isOver() {
|
||||||
return getPlayersAlive().count() <= 1;
|
return getPlayersAlive().count() <= 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user