From 56b2b46a1ab35f51b634e797ca2605d833d91b6b Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 14:01:48 +0100 Subject: [PATCH] Added loop in UseCommand.performCommand() which only ends when every enemy has been slain --- .../org/bitbiome/commands/UseCommand.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 1ec7bbf..bf09152 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -9,9 +9,11 @@ import org.bitbiome.entities.*; public class UseCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { - System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); - if(engine.getPlayer().getHp() <= 0) - System.exit(0); + do { + System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); + if(engine.getPlayer().getHp() <= 0) + System.exit(0); + } while(getNumOfEnemyMobs(engine) > 0); } private String getUseMessage(String msg, TravelEngine engine) { @@ -64,4 +66,16 @@ public class UseCommand implements CommandAPI { target.setFriendly(false); return "You used " + item.getName() + " on " + target.getName(); } + + private int getNumOfEnemyMobs(TravelEngine engine) { + Location loc = engine.getPlayer().getLocation(); + ArrayList mobs = loc.getMobList(); + int count = 0; + for(int i = 0; i