diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/xblast/server/Board.java | 8 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/GameState.java | 49 |
2 files changed, 53 insertions, 4 deletions
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 { | |||
142 | return this.blocksAt(c).head(); | 142 | return this.blocksAt(c).head(); |
143 | } | 143 | } |
144 | 144 | ||
145 | /** | ||
146 | * Return the blocks of the Board. | ||
147 | * | ||
148 | * @return a list of the Sequences of blocks of the board. | ||
149 | */ | ||
150 | public List<Sq<Block>> getBlocks() { | ||
151 | return blocks; | ||
152 | } | ||
145 | } | 153 | } |
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 { | |||
119 | * @return the next board | 119 | * @return the next board |
120 | */ | 120 | */ |
121 | private static Board nextBoard(Board board0, Set<Cell> consumedBonuses, Set<Cell> blastedCells1) { | 121 | private static Board nextBoard(Board board0, Set<Cell> consumedBonuses, Set<Cell> blastedCells1) { |
122 | return null; // TODO | 122 | List<Sq<Block>> blocks0 = board0.getBlocks(); |
123 | List<Sq<Block>> blocks1 = new ArrayList<>(); | ||
124 | |||
125 | int i = 0; | ||
126 | for (Sq<Block> blockSq : blocks0) { | ||
127 | int cellId = blocks0.get(i).hashCode(); | ||
128 | Block block = blockSq.head(); | ||
129 | if (((HashSet) consumedBonuses).contains(cellId) && block.isBonus()) { | ||
130 | blocks1.add(Sq.constant(Block.FREE)); | ||
131 | } else if (((HashSet) blastedCells1).contains(cellId) && (block == Block.DESTRUCTIBLE_WALL || block.isBonus())) { | ||
132 | if (block == Block.DESTRUCTIBLE_WALL) { | ||
133 | Block bonus = randomBonus(); | ||
134 | blocks1.add(Sq.repeat(Ticks.WALL_CRUMBLING_TICKS, Block.CRUMBLING_WALL).concat(Sq.constant(bonus))); | ||
135 | } else { | ||
136 | blocks1.add(Sq.repeat(Ticks.BONUS_DISAPPEARING_TICKS, block).concat(Sq.constant(Block.FREE))); | ||
137 | } | ||
138 | } else { | ||
139 | blocks1.add(blockSq.tail()); | ||
140 | } | ||
141 | i++; | ||
142 | } | ||
143 | |||
144 | return new Board(blocks1); | ||
123 | } | 145 | } |
124 | 146 | ||
125 | /** | 147 | /** |
@@ -140,7 +162,8 @@ public final class GameState { | |||
140 | Board board1, | 162 | Board board1, |
141 | Set<Cell> blastedCells1, | 163 | Set<Cell> blastedCells1, |
142 | Map<PlayerID, Optional<Direction>> speedChangeEvents) { | 164 | Map<PlayerID, Optional<Direction>> speedChangeEvents) { |
143 | return null; // TODO | 165 | //ToDo |
166 | return players0; | ||
144 | } | 167 | } |
145 | 168 | ||
146 | /** | 169 | /** |
@@ -150,7 +173,11 @@ public final class GameState { | |||
150 | * @return the next explosion state | 173 | * @return the next explosion state |
151 | */ | 174 | */ |
152 | private static List<Sq<Sq<Cell>>> nextExplosions(List<Sq<Sq<Cell>>> explosions0) { | 175 | private static List<Sq<Sq<Cell>>> nextExplosions(List<Sq<Sq<Cell>>> explosions0) { |
153 | return null; // TODO | 176 | List<Sq<Sq<Cell>>> explosions1 = new ArrayList<>(); |
177 | for (Sq<Sq<Cell>> explosion : explosions0) { | ||
178 | explosions1.add(explosion.tail()); | ||
179 | } | ||
180 | return explosions1; | ||
154 | } | 181 | } |
155 | 182 | ||
156 | /** | 183 | /** |
@@ -165,7 +192,21 @@ public final class GameState { | |||
165 | List<Player> players0, | 192 | List<Player> players0, |
166 | Set<PlayerID> bombDropEvents, | 193 | Set<PlayerID> bombDropEvents, |
167 | List<Bomb> bombs0) { | 194 | List<Bomb> bombs0) { |
168 | return null; // TODO | 195 | List<Bomb> bombs1 = new ArrayList<>(); |
196 | Set<Cell> containingBombCells = new HashSet<>(); | ||
197 | |||
198 | for (Bomb bomb : bombs0) { | ||
199 | containingBombCells.add(bomb.position()); | ||
200 | } | ||
201 | |||
202 | for (Player player : players0) { | ||
203 | if (bombDropEvents.contains(player.id()) && player.isAlive() && !containingBombCells.contains(player.position().containingCell())) { | ||
204 | Bomb newBomb = new Bomb(player.id(), player.position().containingCell(), Ticks.BOMB_FUSE_TICKS, player.bombRange()); | ||
205 | containingBombCells.add(newBomb.position()); | ||
206 | bombs1.add(newBomb); | ||
207 | } | ||
208 | } | ||
209 | return bombs1; | ||
169 | } | 210 | } |
170 | 211 | ||
171 | private final int ticks; | 212 | private final int ticks; |