From e495f6e1bbc746d16fec24e21b6aef4c50ab6d39 Mon Sep 17 00:00:00 2001
From: KahootChampion
Date: Sun, 24 Feb 2019 21:33:20 -0700
Subject: [PATCH] Sneaky bug in shipWarfare regarding having 0 guns is now
fixed.
---
.idea/workspace.xml | 153 +++++++++++++++++--------------------------
src/ShipWarfare.java | 130 ++++++++++++++++++++----------------
2 files changed, 132 insertions(+), 151 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index cb51149..6a320d6 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,7 +3,7 @@
-
+
@@ -27,57 +27,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -85,15 +49,6 @@
-
-
-
-
-
-
-
-
-
@@ -105,7 +60,6 @@
- guns
duplic
chanceOfRun
chance
@@ -135,6 +89,7 @@
System.out.println("\n*** PLACEHOLDER FOR LOAN SHARK ***\n");
keep
showWa
+ player.get
player.getName()
@@ -160,15 +115,15 @@
@@ -183,7 +138,6 @@
-
@@ -201,12 +155,13 @@
+
-
+
@@ -302,6 +257,8 @@
+
+
1550458807806
@@ -443,17 +400,24 @@
1551065447444
-
+
+ 1551065880809
+
+
+
+ 1551065880809
+
+
-
+
-
+
@@ -462,7 +426,7 @@
-
+
@@ -471,7 +435,7 @@
-
+
@@ -509,7 +473,8 @@
-
+
+
@@ -536,27 +501,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -564,16 +508,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -581,13 +515,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java
index fc29444..79d3e03 100644
--- a/src/ShipWarfare.java
+++ b/src/ShipWarfare.java
@@ -15,12 +15,12 @@ public class ShipWarfare extends Player {
private int numOfLittyShips = 0;
private boolean userAttacks = true;
private int startingPeasantShips = 0;
- private int startingLittyShips =0;
+ private int startingLittyShips = 0;
private int howMuchRun = 0;
private String pirateName = "Liu Yen";
private Player player;
- public ShipWarfare(Player player){
+ public ShipWarfare(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
@@ -30,11 +30,11 @@ public class ShipWarfare extends Player {
this.player = playerDummy;
}
- public Player getPlayer(){
+ public Player getPlayer() {
Player playerDummy = new Player(player);
return playerDummy;
}
-
+
//This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
public void peasantFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
@@ -70,6 +70,7 @@ public class ShipWarfare extends Player {
}
+
//This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
public void littyFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
@@ -180,29 +181,33 @@ public class ShipWarfare extends Player {
//Player volley
while (exitValue == 0) {
- for (int j = 0; j < player.getGuns(); j++) {
- if (userAttacks == true) {
- int hitOrMiss = randomValue.nextInt(3) + 1;
- if (hitOrMiss == 1) {
- numOfLittyShips--;
- if (numOfLittyShips <= 0) {
- exitValue = 1;
- break;
+ if (player.getGuns() > 0) {
+ for (int j = 0; j < player.getGuns(); j++) {
+ if (userAttacks == true) {
+ int hitOrMiss = randomValue.nextInt(3) + 1;
+ if (hitOrMiss == 1) {
+ numOfLittyShips--;
+ if (numOfLittyShips <= 0) {
+ exitValue = 1;
+ break;
+ }
+ System.out.println("Got eem");
+ delayForASecond();
+ } else if (hitOrMiss == 2) {
+ System.out.printf("ARRG! We missed %s\n", getName());
+ delayForASecond();
+ } else {
+ System.out.println("Darn! Their fleet tanked our attack");
+ delayForASecond();
}
- System.out.println("Got eem");
- delayForASecond();
- } else if (hitOrMiss == 2) {
- System.out.printf("ARRG! We missed %s\n", getName());
- delayForASecond();
+
+
} else {
- System.out.println("Darn! Their fleet tanked our attack");
- delayForASecond();
+ continue;
}
-
-
- } else {
- continue;
}
+ } else {
+ System.out.println("Captain! We don't have any GUNS!!!!");
}
@@ -210,17 +215,19 @@ public class ShipWarfare extends Player {
exitValue = 1;
break;
}
- chanceOfEnemyRun = randomValue.nextInt(2) + 1;
- if (chanceOfEnemyRun == 2) {
- howMuchRun = randomValue.nextInt(10) + 1;
- if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
+ if (player.getGuns() > 0) {
+ if (chanceOfEnemyRun == 2) {
+ chanceOfEnemyRun = randomValue.nextInt(2) + 1;
+ howMuchRun = randomValue.nextInt(10) + 1;
+ if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
- setNumOfLittyShips(numOfLittyShips - howMuchRun);
- if (userAttacks == true) {
- System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, getName());
- } else {
- System.out.printf("Escaped %d of them!\n", howMuchRun);
+ setNumOfLittyShips(numOfLittyShips - howMuchRun);
+ if (userAttacks == true) {
+ System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, getName());
+ } else {
+ System.out.printf("Escaped %d of them!\n", howMuchRun);
+ }
}
}
}
@@ -292,44 +299,53 @@ public class ShipWarfare extends Player {
//Player volley
while (exitValue == 0) {
- for (int j = 0; j < player.getGuns(); j++) {
- if (userAttacks == true) {
- int hitOrMiss = randomValue.nextInt(2) + 1;
- if (hitOrMiss == 2) {
- numOfPeasantShips--;
- if (numOfPeasantShips <= 0) {
- exitValue = 1;
- break;
+ if (player.getGuns() > 0) {
+
+ for (int j = 0; j < player.getGuns(); j++) {
+ if (userAttacks == true) {
+ int hitOrMiss = randomValue.nextInt(2) + 1;
+ if (hitOrMiss == 2) {
+ numOfPeasantShips--;
+ if (numOfPeasantShips <= 0) {
+ exitValue = 1;
+ break;
+ }
+ System.out.println("Got eem");
+ delayForASecond();
+ } else {
+ System.out.printf("ARRG! We missed %s\n", getName());
+ delayForASecond();
}
- System.out.println("Got eem");
- delayForASecond();
+
+
} else {
- System.out.printf("ARRG! We missed %s\n", getName());
- delayForASecond();
+ continue;
}
-
-
- } else {
- continue;
}
}
+ else{
+ System.out.println("Captain! We don't have any GUNS!!!!");
+
+ }
if (numOfPeasantShips <= 0) {
exitValue = 1;
break;
}
- chanceOfEnemyRun = randomValue.nextInt(2) + 1;
- if (chanceOfEnemyRun == 2) {
- howMuchRun = randomValue.nextInt(15) + 1;
- if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
+ if (player.getGuns() > 0) {
+ chanceOfEnemyRun = randomValue.nextInt(2) + 1;
+ if (chanceOfEnemyRun == 2) {
+ howMuchRun = randomValue.nextInt(15) + 1;
+ if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
- setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
- if (userAttacks == true) {
- System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, getName());
- } else {
- System.out.printf("Escaped %d of them!\n", howMuchRun);
+ setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
+ if (userAttacks == true) {
+ System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, getName());
+ } else {
+ System.out.printf("Escaped %d of them!\n", howMuchRun);
+ }
}
}
}