From 6b144c1c438a5d184d5ccb7b6df3acf2f7161d74 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Thu, 24 Mar 2016 09:21:28 +0100 Subject: Implement next*() for the fifth week --- src/ch/epfl/xblast/server/Board.java | 8 ++++++ src/ch/epfl/xblast/server/GameState.java | 49 +++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) (limited to 'src/ch') diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index 18ee532..f2a3c89 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java @@ -142,4 +142,12 @@ public final class Board { return this.blocksAt(c).head(); } + /** + * Return the blocks of the Board. + * + * @return a list of the Sequences of blocks of the board. + */ + public List> getBlocks() { + return blocks; + } } diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 522a367..d34c2a4 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java @@ -119,7 +119,29 @@ public final class GameState { * @return the next board */ private static Board nextBoard(Board board0, Set consumedBonuses, Set blastedCells1) { - return null; // TODO + List> blocks0 = board0.getBlocks(); + List> blocks1 = new ArrayList<>(); + + int i = 0; + for (Sq blockSq : blocks0) { + int cellId = blocks0.get(i).hashCode(); + Block block = blockSq.head(); + if (((HashSet) consumedBonuses).contains(cellId) && block.isBonus()) { + blocks1.add(Sq.constant(Block.FREE)); + } else if (((HashSet) blastedCells1).contains(cellId) && (block == Block.DESTRUCTIBLE_WALL || block.isBonus())) { + if (block == Block.DESTRUCTIBLE_WALL) { + Block bonus = randomBonus(); + blocks1.add(Sq.repeat(Ticks.WALL_CRUMBLING_TICKS, Block.CRUMBLING_WALL).concat(Sq.constant(bonus))); + } else { + blocks1.add(Sq.repeat(Ticks.BONUS_DISAPPEARING_TICKS, block).concat(Sq.constant(Block.FREE))); + } + } else { + blocks1.add(blockSq.tail()); + } + i++; + } + + return new Board(blocks1); } /** @@ -140,7 +162,8 @@ public final class GameState { Board board1, Set blastedCells1, Map> speedChangeEvents) { - return null; // TODO + //ToDo + return players0; } /** @@ -150,7 +173,11 @@ public final class GameState { * @return the next explosion state */ private static List>> nextExplosions(List>> explosions0) { - return null; // TODO + List>> explosions1 = new ArrayList<>(); + for (Sq> explosion : explosions0) { + explosions1.add(explosion.tail()); + } + return explosions1; } /** @@ -165,7 +192,21 @@ public final class GameState { List players0, Set bombDropEvents, List bombs0) { - return null; // TODO + List bombs1 = new ArrayList<>(); + Set containingBombCells = new HashSet<>(); + + for (Bomb bomb : bombs0) { + containingBombCells.add(bomb.position()); + } + + for (Player player : players0) { + if (bombDropEvents.contains(player.id()) && player.isAlive() && !containingBombCells.contains(player.position().containingCell())) { + Bomb newBomb = new Bomb(player.id(), player.position().containingCell(), Ticks.BOMB_FUSE_TICKS, player.bombRange()); + containingBombCells.add(newBomb.position()); + bombs1.add(newBomb); + } + } + return bombs1; } private final int ticks; -- cgit v1.2.3