diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 89f9e3b..8594e1d 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,7 +3,8 @@
-
+
+
@@ -14,31 +15,20 @@
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -47,8 +37,8 @@
-
-
+
+
@@ -56,64 +46,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -127,7 +62,9 @@
- Hp
+ couldn
+ could
+ runFromShips
@@ -137,27 +74,21 @@
-
-
-
-
-
-
-
+
+
+
+
+
-
-
@@ -174,15 +105,15 @@
+
+
-
-
-
-
+
+
@@ -230,7 +161,7 @@
- C:\Users\Harkamal Randhawa\AppData\Roaming\Subversion
+ $USER_HOME$/.subversion
125
@@ -241,43 +172,25 @@
1550454898506
-
-
-
-
-
- 1550458470138
+
+ 1550458807806
- 1550458470138
+ 1550458807807
-
- 1550540282400
-
-
-
- 1550540282400
-
-
- 1550540820542
-
-
-
- 1550540820542
-
-
+
-
+
-
+
-
+
@@ -286,17 +199,17 @@
-
+
-
+
-
-
+
+
@@ -316,23 +229,17 @@
-
-
-
-
+
+
-
-
-
-
-
-
+
+
-
-
+
+
@@ -341,77 +248,17 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/out/production/TaipanClone/ShipWarfare.class b/out/production/TaipanClone/ShipWarfare.class
new file mode 100644
index 0000000..61073a4
Binary files /dev/null and b/out/production/TaipanClone/ShipWarfare.class differ
diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java
index a1de955..4737578 100644
--- a/src/ShipWarfare.java
+++ b/src/ShipWarfare.java
@@ -1,44 +1,45 @@
-import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public class ShipWarfare {
- private int money = 100000000;
+ private int money = 0;
private int guns = 3;
private int hp = 100;
- private int numOfPeasantShips= 0;
+ private int numOfPeasantShips = 0;
-
- public void peasantFleetAttack() throws Exception{
+ public void peasantFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
setNumOfPeasantShips(numOfShips());
System.out.printf("By Golly! We have $%,d \nwe are being attacked by %d ships\n", getMoney(), getNumOfPeasantShips());
- System.out.println("What do you want to do? Press \"f\" to fight, and \"r\" to run ");
- while(true) {
- try {
- String response = userResponse.nextLine();
- if (response.equalsIgnoreCase("f")) {
- System.out.println("Ohh, fight ehh?");
- fightShips(getNumOfPeasantShips());
- }
- else if(response.equalsIgnoreCase("r")){
- System.out.println("Harkey G is dumb boiiiiiiiii");
+ System.out.println("What do you want to do? Enter \"f\" to fight, and \"r\" to run ");
+ while (true) {
+ String response = userResponse.nextLine();
+ if (response.equalsIgnoreCase("f")) {
+ System.out.println("Ohh, fight ehh?");
+ boolean winOrLose= destroyShipsOrEscape(getNumOfPeasantShips());
+ if(winOrLose==true){
+ break;
}
- } catch (InputMismatchException e) {
- String response;
- System.out.println("Sorry, that is not an acceptable input please try again");
- response = userResponse.nextLine();
- if (response.equalsIgnoreCase("f") || response.equalsIgnoreCase("r"))
+
+
+ } else if (response.equalsIgnoreCase("r")) {
+ runFromShips();
+ if(runFromShips()==true){
break;
+ }
+
}
+
}
+
}
+
public int getMoney() {
return money;
}
@@ -76,32 +77,26 @@ public class ShipWarfare {
TimeUnit.SECONDS.sleep(1);
}
- public void gameOver(){
+ public void gameOver() {
System.out.flush();
System.out.println("Game over");
}
- public int numOfShips(){
+ public int numOfShips() {
int numOfShipsAttacking = 0;
Random randomValue = new Random();
- if (getMoney() <= 100000){
+ if (getMoney() <= 100000) {
//Minimum one ship will attack, maximum 20
numOfShipsAttacking = randomValue.nextInt(20) + 1;
- }
-
- else if (getMoney() <= 200000){
+ } else if (getMoney() <= 200000) {
//Minimum 30 Ships will attack, maximum 70
numOfShipsAttacking = randomValue.nextInt(40) + 30;
- }
-
- else if (getMoney() <= 500000){
+ } else if (getMoney() <= 500000) {
//Minimum 50 ships will attack, maximum 140
numOfShipsAttacking = randomValue.nextInt(90) + 50;
- }
-
- else if (getMoney() > 1000000){
+ } else if (getMoney() > 1000000) {
//Minimum 100 ships will attack, maximum 300 ships
numOfShipsAttacking = randomValue.nextInt(3) + 100;
}
@@ -110,35 +105,46 @@ public class ShipWarfare {
}
+ public boolean runFromShips() {
+ Random randomValue = new Random();
+ int runSuccessChance = randomValue.nextInt(2) + 1;
+ if (runSuccessChance == 2) {
+ return true;
+ } else if (runSuccessChance == 1) {
+ System.out.println("Couldn't run away");
+ return false;
+ }
+ return false;
+ }
-
-
- public void fightShips(int typeOfShip) throws Exception {
-
+ public boolean destroyShipsOrEscape(int typeOfShip) throws Exception {
+ Scanner userInput = new Scanner(System.in);
Random randomValue = new Random();
int shipsRemaining = typeOfShip;
int exitValue=0;
- if(typeOfShip==getNumOfPeasantShips()) {
+ if (exitValue == 0) {
//Player volley
- while (exitValue==0){
+ while (exitValue == 0) {
for (int i = 0; i < shipsRemaining; i++) {
- for (int j = 0; j < getGuns(); j++) {
- int hitOrMiss = randomValue.nextInt(2) + 1;
- if (hitOrMiss == 2) {
- shipsRemaining--;
- if (shipsRemaining <= 0) {
- exitValue = 1;
- break;
+ if (exitValue == 0) {
+ for (int j = 0; j < getGuns(); j++) {
+ int hitOrMiss = randomValue.nextInt(2) + 1;
+ if (hitOrMiss == 2) {
+ shipsRemaining--;
+ if (shipsRemaining <= 0) {
+ exitValue = 1;
+ break;
+ }
+ System.out.println("Got eem");
+ delayForASecond();
+ } else {
+ System.out.println("ARRG! We missed captain");
+ delayForASecond();
}
- System.out.println("Got eem");
- delayForASecond();
- } else {
- System.out.println("ARRG! We missed captain");
- delayForASecond();
+
+
}
-
-
}
if (shipsRemaining <= 0) {
@@ -151,31 +157,55 @@ public class ShipWarfare {
delayForASecond();
//Computer volley
setHp(getHp() - randomValue.nextInt(10));
- if(getHp()<=0){
- exitValue=2;
+ if (getHp() <= 0) {
+ exitValue = 2;
break;
}
System.out.printf("EEK, we have %d health left\n", getHp());
delayForASecond();
+ System.out.println("Shall we continue the offensive? Enter \"f\" to fight, and \"r\" to run");
+
+ String response = userInput.nextLine();
+ if (response.equalsIgnoreCase("r")) {
+ runFromShips();
+ if (runFromShips() == false) {
+ exitValue = 6;
+ } else {
+ exitValue = 3;
+ break;
+ }
+ }
+
+
+ }
+ if (runFromShips() == true) {
+ break;
}
}
- if(exitValue==1) {
- System.out.printf("Got eem!\nIt appears we have defeated the enemy fleet and made it out at %d health\n", hp);
- }
- else if(exitValue==2){
+ if (exitValue == 1) {
+ System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d health\n", hp);
+ return true;
+ } else if (exitValue == 2) {
gameOver();
+ return true;
+ } else if (exitValue == 3) {
+ System.out.println("We made it");
+ return true;
}
+ return false;
+
}
//Type of ship implied to be Liu Yen fleet
- else{
+ else {
}
+ return false;
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
ShipWarfare littyObject = new ShipWarfare();
littyObject.peasantFleetAttack();
}