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!");
counter++;
if (logic.runFromShips(userAttacks) == false) {
if (logic.runFromShips() == false) {
report.setText(("Couldn't run away"));
try {
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
*/
public boolean runFromShips(boolean userAttacks) {
userAttacks = false;
public boolean runFromShips() {
Random randomValue = new Random();
int runSuccessChance = randomValue.nextInt(10) + 1;
if (runSuccessChance == 2) {

View File

@@ -43,10 +43,13 @@ public class ShipWarfareText extends Player {
} 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!");
if (destroyPeasantShipsOrEscape())
break;
}
} else {
System.out.println("Phew! Got away safely");
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)));
}
if (getHP() > 0) {
displayQuery(userInput);
String response ="";
String response = displayQuery(userInput);
if (response.equalsIgnoreCase("r")) {
if (logic.runFromShips(userAttacks) == false) {
userAttacks=false;
if (logic.runFromShips() == false) {
System.out.println("Couldn't run away");
} else {
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());
delayForSeconds(1);
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());
String response = userInput.nextLine();
return response;
}
public static void main(String[] args) throws Exception {