aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-04-06 23:06:07 +0200
committerPacien TRAN-GIRARD2016-04-06 23:06:07 +0200
commita33c9df30d209e8ba24b51507ffdeab17008dbe8 (patch)
treeee0898e680a7f36518f3aa321c0681cc306a6db1 /src/ch
parentf8effdde28b9d92ce28b3ef5fbd3acf0644d2191 (diff)
downloadxblast-a33c9df30d209e8ba24b51507ffdeab17008dbe8.tar.gz
Make newlyDroppedBombs more readable
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/xblast/server/GameState.java25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java
index c58a911..3495af1 100644
--- a/src/ch/epfl/xblast/server/GameState.java
+++ b/src/ch/epfl/xblast/server/GameState.java
@@ -240,30 +240,27 @@ public final class GameState {
240 240
241 /** 241 /**
242 * Computes and returns the list of newly dropped bombs by players according to the given player states and events. 242 * Computes and returns the list of newly dropped bombs by players according to the given player states and events.
243 * Given bomb drop events must be conflict-free.
243 * 244 *
244 * @param players0 the previous player states 245 * @param players0 the previous player states
245 * @param bombDropEvents the bomb drop events 246 * @param bombDropEvents the bomb drop events
246 * @param bombs0 the previous bomb state 247 * @param bombs0 the previous bomb state
247 * @return the newly dropped bombs 248 * @return the newly dropped bombs
248 */ 249 */
249 private static List<Bomb> newlyDroppedBombs( 250 private static List<Bomb> newlyDroppedBombs(List<Player> players0, Set<PlayerID> bombDropEvents, List<Bomb> bombs0) {
250 List<Player> players0, 251 Set<Cell> bombedCells = GameState.bombedCells(bombs0).keySet();
251 Set<PlayerID> bombDropEvents, 252
252 List<Bomb> bombs0) {
253 List<Bomb> bombs1 = new ArrayList<>(); 253 List<Bomb> bombs1 = new ArrayList<>();
254 Set<Cell> containingBombCells = new HashSet<>();
255 254
256 for (Bomb bomb : bombs0) { 255 for (Player p : GameState.alivePlayers(players0)) {
257 containingBombCells.add(bomb.position()); 256 if (!bombDropEvents.contains(p.id())) continue;
258 } 257 if (bombedCells.contains(p.position().containingCell())) continue;
259 258
260 for (Player player : players0) { 259 Bomb b = new Bomb(p.id(), p.position().containingCell(), Ticks.BOMB_FUSE_TICKS, p.bombRange());
261 if (bombDropEvents.contains(player.id()) && player.isAlive() && !containingBombCells.contains(player.position().containingCell())) { 260 bombedCells.add(b.position());
262 Bomb newBomb = new Bomb(player.id(), player.position().containingCell(), Ticks.BOMB_FUSE_TICKS, player.bombRange()); 261 bombs1.add(b);
263 containingBombCells.add(newBomb.position());
264 bombs1.add(newBomb);
265 }
266 } 262 }
263
267 return bombs1; 264 return bombs1;
268 } 265 }
269 266