diff options
author | Pacien TRAN-GIRARD | 2016-04-07 16:14:59 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-04-07 16:15:21 +0200 |
commit | 552085b0fc886d93680bde42af14d1e161b33380 (patch) | |
tree | 8a3d31d9e196a545ac5aba9f3d8169c173e8f07b /src/ch/epfl | |
parent | 182b0806bfa7d13ff3e79a99b876122fe9cd1219 (diff) | |
download | xblast-552085b0fc886d93680bde42af14d1e161b33380.tar.gz |
Make nextBoard great again
Diffstat (limited to 'src/ch/epfl')
-rw-r--r-- | src/ch/epfl/xblast/server/Board.java | 9 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/GameState.java | 51 |
2 files changed, 29 insertions, 31 deletions
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index d7ca706..bff3ea8 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java | |||
@@ -143,13 +143,4 @@ public final class Board { | |||
143 | return this.blocksAt(c).head(); | 143 | return this.blocksAt(c).head(); |
144 | } | 144 | } |
145 | 145 | ||
146 | /** | ||
147 | * Return the blocks of the Board. | ||
148 | * | ||
149 | * @return a list of the Sequences of blocks of the board. | ||
150 | */ | ||
151 | public List<Sq<Block>> getBlocks() { | ||
152 | List<Sq<Block>> immutableBlocks = Collections.unmodifiableList(new ArrayList<>(blocks)); | ||
153 | return immutableBlocks; | ||
154 | } | ||
155 | } | 146 | } |
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 36709e9..10b648b 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java | |||
@@ -120,29 +120,36 @@ public final class GameState { | |||
120 | * @return the next board | 120 | * @return the next board |
121 | */ | 121 | */ |
122 | private static Board nextBoard(Board board0, Set<Cell> consumedBonuses, Set<Cell> blastedCells1) { | 122 | private static Board nextBoard(Board board0, Set<Cell> consumedBonuses, Set<Cell> blastedCells1) { |
123 | List<Sq<Block>> blocks0 = board0.getBlocks(); | 123 | return new Board(Cell.ROW_MAJOR_ORDER.stream() |
124 | List<Sq<Block>> blocks1 = new ArrayList<>(); | 124 | .map(c -> GameState.nextBlockSeq(c, board0.blocksAt(c), consumedBonuses, blastedCells1)) |
125 | 125 | .collect(Collectors.toList())); | |
126 | int i = 0; | 126 | } |
127 | for (Sq<Block> blockSq : blocks0) { | 127 | |
128 | int cellId = blocks0.get(i).hashCode(); | 128 | /** |
129 | Block block = blockSq.head(); | 129 | * Returns the next Block sequence for the given cell according to the current state and given events. |
130 | if (consumedBonuses.contains(cellId) && block.isBonus()) { | 130 | * |
131 | blocks1.add(Sq.constant(Block.FREE)); | 131 | * @param c the Cell |
132 | } else if (blastedCells1.contains(cellId) && (block == Block.DESTRUCTIBLE_WALL || block.isBonus())) { | 132 | * @param bs0 the previous Block sequence |
133 | if (block == Block.DESTRUCTIBLE_WALL) { | 133 | * @param consumedBonuses the bonus consumption event |
134 | Block bonus = randomBonus(); | 134 | * @param blastedCells1 the new Cell blast events |
135 | blocks1.add(Sq.repeat(Ticks.WALL_CRUMBLING_TICKS, Block.CRUMBLING_WALL).concat(Sq.constant(bonus))); | 135 | * @return the new Block sequence |
136 | } else { | 136 | */ |
137 | blocks1.add(Sq.repeat(Ticks.BONUS_DISAPPEARING_TICKS, block).concat(Sq.constant(Block.FREE))); | 137 | private static Sq<Block> nextBlockSeq(Cell c, Sq<Block> bs0, Set<Cell> consumedBonuses, Set<Cell> blastedCells1) { |
138 | } | 138 | Block b = bs0.head(); |
139 | } else { | 139 | |
140 | blocks1.add(blockSq.tail()); | 140 | if (consumedBonuses.contains(c) && b.isBonus()) |
141 | } | 141 | return Sq.constant(Block.FREE); |
142 | i++; | 142 | |
143 | } | 143 | if (blastedCells1.contains(c)) |
144 | if (b == Block.DESTRUCTIBLE_WALL) | ||
145 | return Sq.repeat(Ticks.WALL_CRUMBLING_TICKS, Block.CRUMBLING_WALL) | ||
146 | .concat(Sq.constant(GameState.randomBonus())); | ||
147 | |||
148 | else if (b.isBonus()) | ||
149 | return Sq.repeat(Ticks.BONUS_DISAPPEARING_TICKS, b) | ||
150 | .concat(Sq.constant(Block.FREE)); | ||
144 | 151 | ||
145 | return new Board(blocks1); | 152 | return bs0.tail(); |
146 | } | 153 | } |
147 | 154 | ||
148 | /** | 155 | /** |