Fixed various issues but mainly with SHipWarfareText firing even when "r" was inputed as the command to run

This commit is contained in:
KahootChampion
2019-04-07 13:15:26 -06:00
parent ea591057cd
commit 548448bda1
3 changed files with 17 additions and 14 deletions

View File

@@ -487,7 +487,7 @@ public class ShipWarfareGUI extends Player {
title.setText("Ayy captain we will try to run!"); title.setText("Ayy captain we will try to run!");
counter++; counter++;
if (logic.runFromShips(userAttacks) == false) { if (logic.runFromShips() == false) {
report.setText(("Couldn't run away")); report.setText(("Couldn't run away"));
try { try {
winOrLose = destroyShipsOrEscape(primaryStage); winOrLose = destroyShipsOrEscape(primaryStage);

View File

@@ -44,8 +44,7 @@ public class ShipWarfareLogic extends Player {
* *
* @return true if the user is allowed to run, false if not, the "default" is false * @return true if the user is allowed to run, false if not, the "default" is false
*/ */
public boolean runFromShips(boolean userAttacks) { public boolean runFromShips() {
userAttacks = false;
Random randomValue = new Random(); Random randomValue = new Random();
int runSuccessChance = randomValue.nextInt(10) + 1; int runSuccessChance = randomValue.nextInt(10) + 1;
if (runSuccessChance == 2) { if (runSuccessChance == 2) {

View File

@@ -43,10 +43,13 @@ public class ShipWarfareText extends Player {
} else if (response.equalsIgnoreCase("r")) { } else if (response.equalsIgnoreCase("r")) {
if (logic.runFromShips(userAttacks) == false) { userAttacks=false;
boolean runSuccess = logic.runFromShips();
if(runSuccess==false) {
System.out.println("Couldn't run away!"); System.out.println("Couldn't run away!");
if (destroyPeasantShipsOrEscape()) if (destroyPeasantShipsOrEscape())
break; break;
}
} else { } else {
System.out.println("Phew! Got away safely"); System.out.println("Phew! Got away safely");
delayForSeconds(2); delayForSeconds(2);
@@ -58,7 +61,7 @@ public class ShipWarfareText extends Player {
} }
}
@@ -166,10 +169,10 @@ public class ShipWarfareText extends Player {
setHP(getHP() - (1 + randomValue.nextInt(10))); setHP(getHP() - (1 + randomValue.nextInt(10)));
} }
if (getHP() > 0) { if (getHP() > 0) {
displayQuery(userInput); String response = displayQuery(userInput);
String response ="";
if (response.equalsIgnoreCase("r")) { if (response.equalsIgnoreCase("r")) {
if (logic.runFromShips(userAttacks) == false) { userAttacks=false;
if (logic.runFromShips() == false) {
System.out.println("Couldn't run away"); System.out.println("Couldn't run away");
} else { } else {
exitValue = 3; exitValue = 3;
@@ -201,7 +204,7 @@ public class ShipWarfareText extends Player {
} }
public void displayQuery(Scanner userInput) throws Exception { public String displayQuery(Scanner userInput) throws Exception {
System.out.printf("EEK, our current ship status is %d%% \n", getHP()); System.out.printf("EEK, our current ship status is %d%% \n", getHP());
delayForSeconds(1); delayForSeconds(1);
if (userAttacks == false) { if (userAttacks == false) {
@@ -211,6 +214,7 @@ 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()); 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(); String response = userInput.nextLine();
return response;
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {