ShipWarfareText Complete Haris Muhammad
This commit is contained in:
@@ -46,13 +46,12 @@ public class ShipWarfareLogic extends Player {
|
|||||||
*/
|
*/
|
||||||
public boolean runFromShips() {
|
public boolean runFromShips() {
|
||||||
Random randomValue = new Random();
|
Random randomValue = new Random();
|
||||||
int runSuccessChance = randomValue.nextInt(10) + 1;
|
int runSuccessChance = randomValue.nextInt(5) + 1;
|
||||||
if (runSuccessChance == 2) {
|
if (runSuccessChance == 2) {
|
||||||
return true;
|
return true;
|
||||||
} else if (runSuccessChance == 1) {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +98,4 @@ public class ShipWarfareLogic extends Player {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ public class ShipWarfareText extends Player {
|
|||||||
|
|
||||||
private boolean userAttacks = true;
|
private boolean userAttacks = true;
|
||||||
private int howMuchRun = 0;
|
private int howMuchRun = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor that takes in a type player as a parameter
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
* @param player object of the class Player
|
* @param player object of the class Player
|
||||||
*/
|
*/
|
||||||
public ShipWarfareText(Player player) {
|
public ShipWarfareText(Player player) {
|
||||||
@@ -21,6 +23,7 @@ public class ShipWarfareText extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
|
* This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
|
||||||
|
*
|
||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
*/
|
*/
|
||||||
public void peasantFleetAttack() throws Exception {
|
public void peasantFleetAttack() throws Exception {
|
||||||
@@ -63,10 +66,6 @@ public class ShipWarfareText extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asks user if they would like to fight or run against ships
|
* Asks user if they would like to fight or run against ships
|
||||||
*/
|
*/
|
||||||
@@ -77,9 +76,9 @@ public class ShipWarfareText extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delays for a specific amount of seconds, takes an integer as an argument
|
* delays for a specific amount of seconds, takes an integer as an argument
|
||||||
|
*
|
||||||
* @param num the seconds to delay
|
* @param num the seconds to delay
|
||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
*/
|
*/
|
||||||
@@ -88,9 +87,9 @@ public class ShipWarfareText extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user faces off against the peasant ships and either prevails, dies, or runs away
|
* The user faces off against the peasant ships and either prevails, dies, or runs away
|
||||||
|
*
|
||||||
* @return true if the user wins, loses, or flees, it returns false otherwise
|
* @return true if the user wins, loses, or flees, it returns false otherwise
|
||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
*/
|
*/
|
||||||
@@ -129,8 +128,7 @@ public class ShipWarfareText extends Player {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
System.out.printf("%s! We don't have any GUNS!!!!\n", getName());
|
System.out.printf("%s! We don't have any GUNS!!!!\n", getName());
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
|
|
||||||
@@ -181,9 +179,7 @@ public class ShipWarfareText extends Player {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(userResponse.equalsIgnoreCase("f")){
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
exitValue = 2;
|
exitValue = 2;
|
||||||
break;
|
break;
|
||||||
@@ -203,8 +199,7 @@ public class ShipWarfareText extends Player {
|
|||||||
} else if (exitValue == 2) {
|
} else if (exitValue == 2) {
|
||||||
gameOver();
|
gameOver();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (exitValue == 3) {
|
||||||
else if (exitValue == 3) {
|
|
||||||
System.out.printf("We made it out at %d%% ship status!\n", getHP());
|
System.out.printf("We made it out at %d%% ship status!\n", getHP());
|
||||||
delayForSeconds(2);
|
delayForSeconds(2);
|
||||||
return true;
|
return true;
|
||||||
@@ -216,6 +211,7 @@ public class ShipWarfareText extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the user to input either "f" or "r"
|
* Ask the user to input either "f" or "r"
|
||||||
|
*
|
||||||
* @param userInput scanner object which is used to ask for user input
|
* @param userInput scanner object which is used to ask for user input
|
||||||
* @return user input which is the users response
|
* @return user input which is the users response
|
||||||
* @throws Exception in case the delay afects this piece of code
|
* @throws Exception in case the delay afects this piece of code
|
||||||
@@ -230,9 +226,10 @@ 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")))
|
while (!(response.equalsIgnoreCase("f") || response.equalsIgnoreCase("r"))) {
|
||||||
System.out.println("Invalid response, try again");
|
System.out.println("Invalid response, try again");
|
||||||
response = userInput.nextLine();
|
response = userInput.nextLine();
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user