From 6a2c1f96c6f0bafd49dac048956d167c249c36b3 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:08:34 +0100 Subject: [PATCH] Added ability to run away in combat --- .../java/org/bitbiome/commands/UseCommand.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 2fcda38..4361b74 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -31,13 +31,19 @@ private boolean combat = false; player.setHp(hp); } //TODO get input from player - do { + COMBAT_LOOP:do { System.out.println("What do you want to do?"); String input = scanner.nextLine(); switch(input) { case "use": use(scanner, engine); break; + case "runaway": + if(runawaySucceeds()) { + combat = false; + break COMBAT_LOOP; + } + break; default: System.out.println("That is not a valid command."); break; @@ -46,6 +52,13 @@ private boolean combat = false; } } + public boolean runawaySucceeds() { + int chance = (int)(Math.random()*100); + if(chance < 50) + return true; + return false; + } + public void use(Scanner scanner, TravelEngine engine) { System.out.println("Which item would you like to use?"); String item = scanner.nextLine();