From 75cc8b9be15b33935fa8965aed808836ef3b3e5a Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 3 Feb 2018 22:36:39 +0100 Subject: Add max bomb placement restriction Signed-off-by: pacien --- src/main/java/fr/umlv/java/wallj/block/RobotBlock.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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; */ public class RobotBlock extends Block { private static final float SPEED = 10f; // px/ms + private static final int MAX_BOMB_PLACEMENTS = 3; private Vec2 pos; private PathFinder pathFinder; private Deque path = new LinkedList<>(); + private int droppedBombCount = 0; RobotBlock(Vec2 pos) { super(BlockType.ROBOT); @@ -62,10 +64,17 @@ public class RobotBlock extends Block { return Events.findFirst(events, BombSetupOrder.class) .map(event -> isOnBomb(stage) ? Collections.singletonList(new BombTimerIncrEvent(getTile())) : - Collections.singletonList(new BlockCreateEvent(BlockType.BOMB, getTile()))) + dropBomb(event)) .orElse(Collections.emptyList()); } + private List dropBomb(BombSetupOrder order) { + if (droppedBombCount >= MAX_BOMB_PLACEMENTS) return Collections.emptyList(); + + droppedBombCount++; + return Collections.singletonList(new BlockCreateEvent(BlockType.BOMB, getTile())); + } + private void updatePath(Board board, TileVec2 target) { if (!board.inside(target) || !board.getBlockTypeAt(target).isTraversable()) return; if (pathFinder == null) pathFinder = new PathFinder(board); -- cgit v1.2.3