Browse Source

Added loop in UseCommand.performCommand() which only ends when every enemy has been slain

remotes/origin/fight-engine
fdai7430 2 years ago
parent
commit
56b2b46a1a
  1. 20
      src/main/java/org/bitbiome/commands/UseCommand.java

20
src/main/java/org/bitbiome/commands/UseCommand.java

@ -9,9 +9,11 @@ import org.bitbiome.entities.*;
public class UseCommand implements CommandAPI { public class UseCommand implements CommandAPI {
@Override @Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { 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) { private String getUseMessage(String msg, TravelEngine engine) {
@ -64,4 +66,16 @@ public class UseCommand implements CommandAPI {
target.setFriendly(false); target.setFriendly(false);
return "You used " + item.getName() + " on " + target.getName(); return "You used " + item.getName() + " on " + target.getName();
} }
private int getNumOfEnemyMobs(TravelEngine engine) {
Location loc = engine.getPlayer().getLocation();
ArrayList<Mob> mobs = loc.getMobList();
int count = 0;
for(int i = 0; i<mobs.size(); i++) {
Mob mob = mobs.get(i);
if(!mob.isFriendly())
count++;
}
return count;
}
} }
Loading…
Cancel
Save