Skip to content

Commit

Permalink
the players who are the last ones standing are marked as winners
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Aug 23, 2015
1 parent b9b5944 commit 91f74ab
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.cardshifter.modapi.base.PlayerComponent;
import com.cardshifter.modapi.base.PlayerEliminatedEvent;

import java.util.List;
import java.util.stream.Collectors;

/**
* Adds functionality that ends the game when there's only one (or less) players remaining in the game
*
Expand Down Expand Up @@ -37,12 +40,13 @@ public void startGame(ECSGame game) {
}

private void onPlayerEliminated(PlayerEliminatedEvent event) {
long numAlive = event.getEntity().getGame()
List<PlayerComponent> alive = event.getEntity().getGame()
.getEntitiesWithComponent(PlayerComponent.class).stream()
.map(e -> e.getComponent(PlayerComponent.class))
.filter(pl -> !pl.isEliminated())
.count();
if (numAlive <= playersRemainingToEnd) {
.collect(Collectors.toList());
if (alive.size() <= playersRemainingToEnd) {
alive.forEach(PlayerComponent::winGame);
event.getEntity().getGame().endGame();
}
}
Expand Down

0 comments on commit 91f74ab

Please sign in to comment.