From fff5456b45bf0b8752ede97b95eb2d67f31c2de8 Mon Sep 17 00:00:00 2001
From: KahootChampion
Date: Sun, 7 Apr 2019 13:52:36 -0600
Subject: [PATCH] Mostly done ShiPWarfareText
---
src/ShipWarfareText.java | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/src/ShipWarfareText.java b/src/ShipWarfareText.java
index 242e7c0..7254870 100644
--- a/src/ShipWarfareText.java
+++ b/src/ShipWarfareText.java
@@ -43,18 +43,20 @@ public class ShipWarfareText extends Player {
} else if (response.equalsIgnoreCase("r")) {
- userAttacks=false;
+ userAttacks = false;
boolean runSuccess = logic.runFromShips();
- if(runSuccess==false) {
+ if (runSuccess == false) {
System.out.println("Couldn't run away!");
if (destroyPeasantShipsOrEscape())
break;
- }
- } else {
+ }else {
System.out.println("Phew! Got away safely");
delayForSeconds(2);
break;
}
+ }else{
+ System.out.println("Invalid response, please try again");
+ }
}
@@ -169,8 +171,8 @@ public class ShipWarfareText extends Player {
setHP(getHP() - (1 + randomValue.nextInt(10)));
}
if (getHP() > 0) {
- String response = displayQuery(userInput);
- if (response.equalsIgnoreCase("r")) {
+ String userResponse = displayQuery(userInput);
+ if (userResponse.equalsIgnoreCase("r")) {
userAttacks=false;
if (logic.runFromShips() == false) {
System.out.println("Couldn't run away");
@@ -179,6 +181,9 @@ public class ShipWarfareText extends Player {
break;
}
}
+ else if(userResponse.equalsIgnoreCase("f")){
+
+ }
} else {
exitValue = 2;
break;
@@ -199,11 +204,22 @@ public class ShipWarfareText extends Player {
gameOver();
return true;
}
+ else if (exitValue == 3) {
+ System.out.printf("We made it out at %d%% ship status!\n", getHP());
+ delayForSeconds(2);
+ return true;
+ }
return false;
}
+ /**
+ * Ask the user to input either "f" or "r"
+ * @param userInput scanner object which is used to ask for user input
+ * @return user input which is the users response
+ * @throws Exception in case the delay afects this piece of code
+ */
public String displayQuery(Scanner userInput) throws Exception {
System.out.printf("EEK, our current ship status is %d%% \n", getHP());
delayForSeconds(1);
@@ -214,6 +230,9 @@ public class ShipWarfareText extends Player {
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", getGuns());
String response = userInput.nextLine();
+ while(!(response.equalsIgnoreCase("f") || response.equalsIgnoreCase("r")))
+ System.out.println("Invalid response, try again");
+ response=userInput.nextLine();
return response;
}