From 0086abb2a71fe2adb17db747eeb6653c9faafe5e Mon Sep 17 00:00:00 2001
From: KahootChampion
Date: Thu, 11 Apr 2019 22:01:34 -0600
Subject: [PATCH] Fixed many issues with ShipWarfare text like the fact that
the game wouldnt end when all ships were defeated until all shots had been
fired
---
src/text/ShipWarfareText.java | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/text/ShipWarfareText.java b/src/text/ShipWarfareText.java
index 01b25cc..0e6fdd8 100644
--- a/src/text/ShipWarfareText.java
+++ b/src/text/ShipWarfareText.java
@@ -95,17 +95,19 @@ public class ShipWarfareText extends Player {
/**
* Ships either land a hit or do not
- * @param random random object is used
+ *
+ * @param random random object is used
* @param exitValue exit in order to know if user wins, loses, or flees
* @throws Exception in case error is caused due to the delay
+ * @return exitValue
*/
- public void attackOrNot(Random random, int exitValue) throws Exception {
+ public int attackOrNot(Random random, int exitValue) throws Exception {
if (userAttacks == true) {
int hitOrMiss = random.nextInt(2) + 1;
if (hitOrMiss == 2) {
logic.setNumOfShips(logic.getNumOfShips() - 1);
if (logic.getNumOfShips() <= 0) {
- exitValue = 1;
+ return exitValue = 1;
}
System.out.println("Got eem");
delayForSeconds(1);
@@ -116,12 +118,14 @@ public class ShipWarfareText extends Player {
}
+ exitValue=0;
+ return exitValue;
}
/**
* Ships either run away or we escape
*/
- public void shipsRunOrWeEscape(){
+ public void shipsRunOrWeEscape() {
if (howMuchRun != 0 && howMuchRun < logic.getNumOfShips()) {
logic.setNumOfShips(logic.getNumOfShips() - howMuchRun);
if (userAttacks == true) {
@@ -152,11 +156,13 @@ public class ShipWarfareText extends Player {
while (exitValue == 0) {
if (getGuns() > 0) {
for (int j = 0; j < getGuns(); j++) {
- attackOrNot(randomValue,exitValue);
+ attackOrNot(randomValue, exitValue);
+
}
if (exitValue == 1) {
break;
}
+
} else {
System.out.printf("%s! We don't have any GUNS!!!!\n", getName());
delayForSeconds(1);
@@ -253,4 +259,9 @@ public class ShipWarfareText extends Player {
return response;
}
+ public static void main(String[] args) throws Exception {
+ ShipWarfareText test = new ShipWarfareText(new Player());
+ test.peasantFleetAttack();
+ }
+
}
\ No newline at end of file