From 370b3ee041cc02c1d3ec4943c6f00514625ce7b7 Mon Sep 17 00:00:00 2001 From: KahootChampion Date: Sat, 9 Mar 2019 18:28:44 -0700 Subject: [PATCH] Made ShipWarfare easier to access by ShipWarfareGUI --- out/production/TaipanClone/ShipWarfare.class | Bin 4807 -> 8124 bytes src/ShipWarfare.java | 101 +++++++++++++------ 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/out/production/TaipanClone/ShipWarfare.class b/out/production/TaipanClone/ShipWarfare.class index 26c4c4cf4f1e7cd2bdc0cb9f3339088556823886..da08cf6213d842f125c937412fb28abad9f46416 100644 GIT binary patch literal 8124 zcmcIp3w%`NmH(eRGnvUSAt4YR2IU3`gds|C70XLOp3#I*f?%*}CYhVez+@)QgAlDQ z^$~e?Ypu3E>UOu=?QY*9X#eNlJCg~HtH1rZI_?8ae*5O(muG8T=0bH-o8~pfg5JCLC zPPY58qa5GEjX_l4rXVRd>#$R4w*+vjAK%x#gF*ZNx9QvMLEM2|y61;_m4*#Vb2Dwna+OS0KW*JjI9>0m6?-;(Q!t<5C`!M=Dp zlC@SxdM!b9^QOp_$m~QU*)zK>nE9%C*#=@1fv@A#F^^_ z-leH1*;F>ilh*27Z>N=B7wJscj8k2a#QI1&u5*{@&Bo#szoJ>S+7L;1N75E~k8;;Xe$zym38bQ@HD7M<^AzwYq~j=p%j6%mFY_* z^);jxTw9oqbrjEKh@GHnng|q|X+Z5$eYqwAk{kT~=Qkl`fpXt-P>=7i)@EM(`nhRgo_%IA2rb&T+I+35QlC zG?YfzYD{;$CzfqZGbCE9OeWH!KBMJry^62&HZ-YK$K}^XhFfLSVuY+nrQ58oR5D8E zdKkMj8OPRcH+aVmPaIb<%;@!WBpFThu8$;gcD&ef+x}Q$0li zv@O@wMUj`rBFQeEoD{V(*>q}PSm@UD@=RBxk89 z812d>m=4XUR8~;cWixH+KN!7O4=vf^$Q72k#23lLpL{sYGI+&fH*`vB(z7 zoL1i$HED5^$!K<3^o<#@fyRoOodafl)NHZR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pjxm7YpOv%!YfI3HK7=_Y)!y5N;3g z^ustp`lI}Z#{+nrvtxJ!Pp~*YiI;Jl-%L+o3QyxBmfyeN8TC3WR>Uuz*LawtLi-#(#CkpKVy 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);