Mostly done ShiPWarfareText
This commit is contained in:
@@ -49,12 +49,14 @@ public class ShipWarfareText extends Player {
|
|||||||
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);
|
||||||
break;
|
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)));
|
setHP(getHP() - (1 + randomValue.nextInt(10)));
|
||||||
}
|
}
|
||||||
if (getHP() > 0) {
|
if (getHP() > 0) {
|
||||||
String response = displayQuery(userInput);
|
String userResponse = displayQuery(userInput);
|
||||||
if (response.equalsIgnoreCase("r")) {
|
if (userResponse.equalsIgnoreCase("r")) {
|
||||||
userAttacks=false;
|
userAttacks=false;
|
||||||
if (logic.runFromShips() == false) {
|
if (logic.runFromShips() == false) {
|
||||||
System.out.println("Couldn't run away");
|
System.out.println("Couldn't run away");
|
||||||
@@ -179,6 +181,9 @@ public class ShipWarfareText extends Player {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(userResponse.equalsIgnoreCase("f")){
|
||||||
|
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
exitValue = 2;
|
exitValue = 2;
|
||||||
break;
|
break;
|
||||||
@@ -199,11 +204,22 @@ public class ShipWarfareText extends Player {
|
|||||||
gameOver();
|
gameOver();
|
||||||
return true;
|
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;
|
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 {
|
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);
|
||||||
@@ -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());
|
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();
|
||||||
|
while(!(response.equalsIgnoreCase("f") || response.equalsIgnoreCase("r")))
|
||||||
|
System.out.println("Invalid response, try again");
|
||||||
|
response=userInput.nextLine();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user