Browse Source

refactoring: Made a function which executes one cycle of combat

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

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

@ -16,6 +16,11 @@ private boolean combat = false;
getEnemies(player.getLocation().getMobList()); getEnemies(player.getLocation().getMobList());
System.out.println(use(scanner, engine)); System.out.println(use(scanner, engine));
while(enemies.size() > 0 && combat) { while(enemies.size() > 0 && combat) {
combat(player, scanner, engine);
}
}
public void combat(Player player, Scanner scanner, TravelEngine engine) {
if(player.getHp() <= 0) if(player.getHp() <= 0)
System.exit(0); System.exit(0);
for(int i = 0; i<enemies.size(); i++) { for(int i = 0; i<enemies.size(); i++) {
@ -30,7 +35,6 @@ private boolean combat = false;
} }
player.setHp(hp); player.setHp(hp);
} }
//TODO get input from player
COMBAT_LOOP:do { COMBAT_LOOP:do {
System.out.println("What do you want to do?"); System.out.println("What do you want to do?");
String input = scanner.nextLine(); String input = scanner.nextLine();
@ -45,14 +49,14 @@ private boolean combat = false;
} }
break; break;
case "help": case "help":
new HelpCommand().performCommand(scanner, isRunning, message, engine);
new HelpCommand().performCommand(scanner, true, "", engine);
break; break;
case "exit": case "exit":
case "quit": case "quit":
System.out.println("You cannot quit while in combat."); System.out.println("You cannot quit while in combat.");
break; break;
case "location": case "location":
new LocationCommand().performCommand(scanner, isRunning, message, engine);
new LocationCommand().performCommand(scanner, true, "", engine);
break; break;
case "travel": case "travel":
System.out.println("You cannot travel while in combat."); System.out.println("You cannot travel while in combat.");
@ -63,7 +67,6 @@ private boolean combat = false;
} }
} while(true); } while(true);
} }
}
public boolean runawaySucceeds(int chance) { public boolean runawaySucceeds(int chance) {
int random = (int)(Math.random()*100); int random = (int)(Math.random()*100);

Loading…
Cancel
Save