aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/RobotBlock.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java b/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java
index da7f3cf..e4e0aad 100644
--- a/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java
+++ b/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java
@@ -23,10 +23,12 @@ import java.util.List;
23 */ 23 */
24public class RobotBlock extends Block { 24public class RobotBlock extends Block {
25 private static final float SPEED = 10f; // px/ms 25 private static final float SPEED = 10f; // px/ms
26 private static final int MAX_BOMB_PLACEMENTS = 3;
26 27
27 private Vec2 pos; 28 private Vec2 pos;
28 private PathFinder pathFinder; 29 private PathFinder pathFinder;
29 private Deque<TileVec2> path = new LinkedList<>(); 30 private Deque<TileVec2> path = new LinkedList<>();
31 private int droppedBombCount = 0;
30 32
31 RobotBlock(Vec2 pos) { 33 RobotBlock(Vec2 pos) {
32 super(BlockType.ROBOT); 34 super(BlockType.ROBOT);
@@ -62,10 +64,17 @@ public class RobotBlock extends Block {
62 return Events.findFirst(events, BombSetupOrder.class) 64 return Events.findFirst(events, BombSetupOrder.class)
63 .map(event -> isOnBomb(stage) ? 65 .map(event -> isOnBomb(stage) ?
64 Collections.<Event>singletonList(new BombTimerIncrEvent(getTile())) : 66 Collections.<Event>singletonList(new BombTimerIncrEvent(getTile())) :
65 Collections.<Event>singletonList(new BlockCreateEvent(BlockType.BOMB, getTile()))) 67 dropBomb(event))
66 .orElse(Collections.emptyList()); 68 .orElse(Collections.emptyList());
67 } 69 }
68 70
71 private List<Event> dropBomb(BombSetupOrder order) {
72 if (droppedBombCount >= MAX_BOMB_PLACEMENTS) return Collections.emptyList();
73
74 droppedBombCount++;
75 return Collections.singletonList(new BlockCreateEvent(BlockType.BOMB, getTile()));
76 }
77
69 private void updatePath(Board board, TileVec2 target) { 78 private void updatePath(Board board, TileVec2 target) {
70 if (!board.inside(target) || !board.getBlockTypeAt(target).isTraversable()) return; 79 if (!board.inside(target) || !board.getBlockTypeAt(target).isTraversable()) return;
71 if (pathFinder == null) pathFinder = new PathFinder(board); 80 if (pathFinder == null) pathFinder = new PathFinder(board);