Browse Source

refactoring: Pulled getting enemies from location into its own function

remotes/origin/fight-engine
fdai7430 2 years ago
parent
commit
7694c397b0
  1. 15
      src/main/java/org/bitbiome/commands/UseCommand.java

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

@ -11,12 +11,7 @@ ArrayList<Mob> enemies = new ArrayList<Mob>();
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) {
ArrayList<Mob> allMobs = engine.getPlayer().getLocation().getMobList();
for(int i = 0; i<allMobs.size(); i++) {
Mob mob = allMobs.get(i);
if(!mob.isFriendly())
enemies.add(mob);
}
getEnemies(engine.getPlayer().getLocation().getMobList());
do {
System.out.println(getUseMessage(message.split(" ", 2)[1], engine));
if(engine.getPlayer().getHp() <= 0)
@ -89,4 +84,12 @@ ArrayList<Mob> enemies = new ArrayList<Mob>();
target.setFriendly(false);
return "You used " + item.getName() + " on " + target.getName();
}
private void getEnemies(ArrayList<Mob> allMobs) {
for(int i = 0; i<allMobs.size(); i++) {
Mob mob = allMobs.get(i);
if(!mob.isFriendly())
enemies.add(mob);
}
}
}
Loading…
Cancel
Save