diff --git a/out/production/TaipanClone/ShipWarfare.class b/out/production/TaipanClone/ShipWarfare.class index 26c4c4c..da08cf6 100644 Binary files a/out/production/TaipanClone/ShipWarfare.class and b/out/production/TaipanClone/ShipWarfare.class differ diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java index 4f412ab..f20861c 100644 --- a/src/ShipWarfare.java +++ b/src/ShipWarfare.java @@ -49,7 +49,7 @@ public class ShipWarfare { Scanner userResponse = new Scanner(System.in); setNumOfPeasantShips(numOfShips()); - System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfPeasantShips, player.getHP()); + System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), getNumOfPeasantShips(), player.getHP()); fightOrRunMessage(); while (true) { @@ -82,6 +82,38 @@ public class ShipWarfare { } + public int getNumOfPeasantShips() { + return numOfPeasantShips; + } + + public int getNumOfLittyShips() { + return numOfLittyShips; + } + + public boolean isUserAttacks() { + return userAttacks; + } + + public int getStartingPeasantShips() { + return startingPeasantShips; + } + + public int getStartingLittyShips() { + return startingLittyShips; + } + + public int getHowMuchRun() { + return howMuchRun; + } + + public String getPirateName() { + return pirateName; + } + + public void setUserAttacks(boolean userAttacks) { + this.userAttacks = userAttacks; + } + /** * This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits * @throws Exception in case of errors due to the delay @@ -89,12 +121,12 @@ public class ShipWarfare { public void littyFleetAttack() throws Exception { Scanner userResponse = new Scanner(System.in); setNumOfLittyShips(numOfShips()); - System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfLittyShips, pirateName, player.getHP()); + System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", player.getMoney(), getNumOfLittyShips(), getPirateName(), player.getHP()); fightOrRunMessage(); while (true) { String response = userResponse.nextLine(); if (response.equalsIgnoreCase("f")) { - userAttacks = true; + setUserAttacks(true); System.out.println("Ohh, fight ehh?"); boolean winOrLose = destroyLittyShipsOrEscape(); if (winOrLose == true) { @@ -193,7 +225,7 @@ public class ShipWarfare { */ public boolean runFromShips() { - userAttacks = false; + setUserAttacks(false); Random randomValue = new Random(); int runSuccessChance = randomValue.nextInt(2) + 1; if (runSuccessChance == 2) { @@ -204,6 +236,10 @@ public class ShipWarfare { return false; } + public void setHowMuchRun(int howMuchRun) { + this.howMuchRun = howMuchRun; + } + /** * The user faces off against the litty ships and either prevails, dies, or runs away * The loot for defeating a litty fleet is much higher than that of a peasant one @@ -223,11 +259,11 @@ public class ShipWarfare { while (exitValue == 0) { if (player.getGuns() > 0) { for (int j = 0; j < player.getGuns(); j++) { - if (userAttacks == true) { + if (isUserAttacks()==true) { int hitOrMiss = randomValue.nextInt(3) + 1; if (hitOrMiss == 1) { - numOfLittyShips--; - if (numOfLittyShips <= 0) { + setNumOfPeasantShips(getNumOfPeasantShips()-1); + if (getNumOfLittyShips() <= 0) { exitValue = 1; break; } @@ -252,28 +288,28 @@ public class ShipWarfare { } - if (numOfLittyShips <= 0) { + if (getNumOfLittyShips() <= 0) { exitValue = 1; break; } if (player.getGuns() > 0) { if (chanceOfEnemyRun == 2) { chanceOfEnemyRun = randomValue.nextInt(2) + 1; - howMuchRun = randomValue.nextInt(10) + 1; - if (howMuchRun != 0 && howMuchRun < numOfLittyShips) { + setHowMuchRun(randomValue.nextInt(10) + 1); + if (getHowMuchRun() != 0 && getHowMuchRun() < getNumOfLittyShips()) { - setNumOfLittyShips(numOfLittyShips - howMuchRun); - if (userAttacks == true) { - System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, player.getName()); + setNumOfLittyShips(getNumOfLittyShips() - getHowMuchRun()); + if (isUserAttacks()==true) { + System.out.printf("Cowards! %d ships ran away %s!\n", getHowMuchRun(), player.getName()); } else { - System.out.printf("Escaped %d of them!\n", howMuchRun); + System.out.printf("Escaped %d of them!\n", getHowMuchRun()); } } } } - System.out.printf("%d ships remaining\n", numOfLittyShips); + System.out.printf("%d ships remaining\n", getNumOfLittyShips()); System.out.println("Oh no, they are taking the offensive!"); delayForSeconds(1); //Computer volley @@ -290,8 +326,8 @@ public class ShipWarfare { } System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); delayForSeconds(1); - if (userAttacks == false) { - userAttacks = true; + if (isUserAttacks() == false) { + setUserAttacks(true); } System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns()); @@ -315,7 +351,7 @@ public class ShipWarfare { if (exitValue == 1) { System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP()); delayForSeconds(1); - calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300; + calculateLoot = (randomValue.nextInt(getStartingLittyShips()) + getStartingLittyShips()) * 300; player.setMoney(player.getMoney() + calculateLoot); System.out.printf("We got $%,d!\n", calculateLoot); delayForSeconds(2); @@ -340,6 +376,7 @@ public class ShipWarfare { * @throws Exception in case of errors due to the delay */ + public boolean destroyPeasantShipsOrEscape() throws Exception { int calculateLoot = 0; int chanceOfEnemyRun = 0; @@ -354,11 +391,11 @@ public class ShipWarfare { if (player.getGuns() > 0) { for (int j = 0; j < player.getGuns(); j++) { - if (userAttacks == true) { + if (isUserAttacks()==true) { int hitOrMiss = randomValue.nextInt(2) + 1; if (hitOrMiss == 2) { - numOfPeasantShips--; - if (numOfPeasantShips <= 0) { + setNumOfPeasantShips(getNumOfPeasantShips()-1); + if (getNumOfPeasantShips() <= 0) { exitValue = 1; break; } @@ -382,28 +419,28 @@ public class ShipWarfare { } - if (numOfPeasantShips <= 0) { + if (getNumOfPeasantShips() <= 0) { exitValue = 1; break; } if (player.getGuns() > 0) { chanceOfEnemyRun = randomValue.nextInt(2) + 1; if (chanceOfEnemyRun == 2) { - howMuchRun = randomValue.nextInt(15) + 1; - if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) { + setHowMuchRun(randomValue.nextInt(15) + 1); + if (getHowMuchRun() != 0 && getHowMuchRun() < getNumOfPeasantShips()) { - setNumOfPeasantShips(numOfPeasantShips - howMuchRun); - if (userAttacks == true) { - System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, player.getName()); + setNumOfPeasantShips(getNumOfPeasantShips() - getHowMuchRun()); + if ( isUserAttacks()==true) { + System.out.printf("Ahhh, %d ships ran away %s!\n", getHowMuchRun(), player.getName()); } else { - System.out.printf("Escaped %d of them!\n", howMuchRun); + System.out.printf("Escaped %d of them!\n", getHowMuchRun()); } } } } - System.out.printf("%d ships remaining\n", numOfPeasantShips); + System.out.printf("%d ships remaining\n", getNumOfPeasantShips()); delayForSeconds(1); System.out.println("Oh no, they are taking the offensive!"); delayForSeconds(1); @@ -421,8 +458,8 @@ public class ShipWarfare { } System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); delayForSeconds(1); - if (userAttacks == false) { - userAttacks = true; + if (isUserAttacks()==false) { + setUserAttacks(true); } System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns()); @@ -444,7 +481,7 @@ public class ShipWarfare { if (exitValue == 1) { System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP()); delayForSeconds(1); - calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100; + calculateLoot = (randomValue.nextInt(getStartingPeasantShips()) + getStartingPeasantShips()) * 100; player.setMoney(player.getMoney() + calculateLoot); System.out.printf("We got $%,d!", calculateLoot); delayForSeconds(2);