Java Docs BOIZ for ShipWarafare

This commit is contained in:
KahootChampion
2019-02-25 19:33:48 -07:00
parent 4cc9ac5d26
commit 70b698c22e
2 changed files with 248 additions and 190 deletions

207
.idea/workspace.xml generated
View File

@@ -3,7 +3,7 @@
<component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/TaipanShop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TaipanShop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ShipWarfare.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfare.java" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -27,21 +27,21 @@
<select />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<leaf>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main.java">
<entry file="file://$PROJECT_DIR$/src/Start.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="95">
<caret line="5" column="41" selection-start-line="5" selection-start-column="41" selection-end-line="5" selection-end-column="41" />
<state relative-caret-position="240">
<caret line="16" column="19" lean-forward="true" selection-start-line="16" selection-end-line="17" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/loanShark.java">
<entry file="file://$PROJECT_DIR$/src/Warehouse.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="858">
<caret line="64" column="5" selection-start-line="64" selection-start-column="5" selection-end-line="64" selection-end-column="5" />
<state relative-caret-position="203">
<caret line="16" column="15" lean-forward="true" selection-start-line="16" selection-end-line="17" />
</state>
</provider>
</entry>
@@ -49,8 +49,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1102">
<caret line="58" column="5" selection-start-line="58" selection-start-column="5" selection-end-line="58" selection-end-column="5" />
<state relative-caret-position="724">
<caret line="53" column="7" lean-forward="true" selection-start-line="53" selection-start-column="7" selection-end-line="53" selection-end-column="7" />
<folding>
<element signature="e#1253#1254#0" expanded="true" />
<element signature="e#1286#1287#0" expanded="true" />
@@ -59,48 +59,11 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Warehouse.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="475">
<caret line="25" selection-start-line="25" selection-end-line="25" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="402">
<caret line="81" column="63" selection-start-line="81" selection-start-column="63" selection-end-line="81" selection-end-column="63" />
<folding>
<element signature="e#1266#1267#0" expanded="true" />
<element signature="e#1299#1300#0" expanded="true" />
<element signature="e#1594#1595#0" expanded="true" />
<element signature="e#1626#1627#0" expanded="true" />
<element signature="e#1868#1869#0" expanded="true" />
<element signature="e#1900#1901#0" expanded="true" />
<element signature="e#2066#2067#0" expanded="true" />
<element signature="e#2101#2102#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="535">
<caret line="108" column="65" selection-start-line="108" selection-start-column="65" selection-end-line="108" selection-end-column="65" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="114">
<caret line="6" column="38" selection-start-line="6" selection-start-column="38" selection-end-line="6" selection-end-column="38" />
<state relative-caret-position="75">
<caret line="5" column="38" selection-start-line="5" selection-start-column="38" selection-end-line="5" selection-end-column="38" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -108,24 +71,6 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Bank.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="535">
<caret line="68" column="6" selection-start-line="68" selection-start-column="6" selection-end-line="68" selection-end-column="6" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Start.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="174">
<caret line="63" column="35" selection-start-line="63" selection-start-column="35" selection-end-line="63" selection-end-column="35" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@@ -137,8 +82,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>setg</find>
<find>guns</find>
<find>duplic</find>
<find>chanceOfRun</find>
<find>chance</find>
@@ -167,6 +110,8 @@
<find>player.</find>
<find>System.out.println(&quot;\n*** PLACEHOLDER FOR LOAN SHARK ***\n&quot;);</find>
<find>cargoSpace</find>
<find>delayF</find>
<find>guns&gt;0</find>
</findStrings>
<replaceStrings>
<replace>player.getName()</replace>
@@ -183,9 +128,11 @@
<replace>%s</replace>
<replace>loan();</replace>
<replace>player.getCargoSpace()</replace>
<replace>delayForSeconds(1)</replace>
</replaceStrings>
</component>
<component name="Git.Settings">
<option name="UPDATE_TYPE" value="REBASE" />
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
@@ -197,10 +144,10 @@
<option value="$PROJECT_DIR$/src/Travel.java" />
<option value="$PROJECT_DIR$/src/loanShark.java" />
<option value="$PROJECT_DIR$/src/main.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
<option value="$PROJECT_DIR$/src/Start.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
</list>
</option>
</component>
@@ -215,6 +162,7 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@@ -231,7 +179,6 @@
<select />
</subPane>
</pane>
<pane id="Scope" />
<pane id="PackagesPane" />
</panes>
</component>
@@ -479,13 +426,13 @@
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="40547000" />
<option name="totallyTimeSpent" value="42987000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<frame x="0" y="23" width="1280" height="709" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.26865673" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.31987077" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
@@ -500,7 +447,7 @@
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" sideWeight="0.49946696" weight="0.32901135" />
<window_info active="true" anchor="bottom" id="Version Control" order="8" sideWeight="0.49946696" visible="true" weight="0.32901135" />
<window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Terminal" order="10" weight="0.32936078" />
<window_info anchor="bottom" id="Event Log" order="11" sideWeight="0.50159913" side_tool="true" visible="true" weight="0.32719395" />
@@ -520,6 +467,42 @@
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="Vcs.Log.History.Properties">
<option name="COLUMN_ORDER">
<list>
<option value="0" />
<option value="2" />
<option value="3" />
<option value="1" />
</list>
</option>
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="RECENTLY_FILTERED_USER_GROUPS">
<collection />
</option>
<option name="RECENTLY_FILTERED_BRANCH_GROUPS">
<collection />
</option>
<option name="COLUMN_ORDER">
<list>
<option value="0" />
<option value="1" />
<option value="2" />
<option value="3" />
</list>
</option>
</State>
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<ignored-roots>
<path value="$PROJECT_DIR$" />
@@ -550,26 +533,7 @@
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/Test.java" />
<entry file="file://$PROJECT_DIR$/src/Warehouse.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="475">
<caret line="25" selection-start-line="25" selection-end-line="25" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/Desktop/src/main.java">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="114">
<caret line="6" column="38" selection-start-line="6" selection-start-column="38" selection-end-line="6" selection-end-column="38" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/Desktop/src/main.java" />
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="535">
@@ -591,24 +555,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1102">
<caret line="58" column="5" selection-start-line="58" selection-start-column="5" selection-end-line="58" selection-end-column="5" />
<folding>
<element signature="e#1253#1254#0" expanded="true" />
<element signature="e#1286#1287#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Start.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="174">
<caret line="63" column="35" selection-start-line="63" selection-start-column="35" selection-end-line="63" selection-end-column="35" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Bank.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="535">
@@ -633,6 +579,41 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="724">
<caret line="53" column="7" lean-forward="true" selection-start-line="53" selection-start-column="7" selection-end-line="53" selection-end-column="7" />
<folding>
<element signature="e#1253#1254#0" expanded="true" />
<element signature="e#1286#1287#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Warehouse.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="203">
<caret line="16" column="15" lean-forward="true" selection-start-line="16" selection-end-line="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Start.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="240">
<caret line="16" column="19" lean-forward="true" selection-start-line="16" selection-end-line="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
<caret line="5" column="38" selection-start-line="5" selection-start-column="38" selection-end-line="5" selection-end-column="38" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>

View File

@@ -2,33 +2,47 @@ import java.util.Scanner;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public class ShipWarfare {
public class ShipWarfare extends Player {
private int numOfPeasantShips = 0;
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;
}
/**
* setter method for player
* @param player object of the class Player
*/
public void setPlayer(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public Player getPlayer(){
/**
* getter method for obtaining a player object.
* @return returns player object
*/
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
/**
* This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
* @throws Exception in case of errors due to the delay
*/
public void peasantFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
setNumOfPeasantShips(numOfShips());
@@ -41,6 +55,7 @@ public class ShipWarfare {
if (response.equalsIgnoreCase("f")) {
userAttacks = true;
System.out.println("Ohh, fight ehh?");
delayForSeconds(1);
boolean winOrLose = destroyPeasantShipsOrEscape();
if (winOrLose == true) {
break;
@@ -54,6 +69,7 @@ public class ShipWarfare {
break;
} else {
System.out.println("Phew! Got away safely");
delayForSeconds(2);
break;
}
@@ -63,7 +79,11 @@ public class ShipWarfare {
}
//This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
/**
* 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
*/
public void littyFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
setNumOfLittyShips(numOfShips());
@@ -83,10 +103,12 @@ public class ShipWarfare {
} else if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away!");
delayForSeconds(1);
if (destroyLittyShipsOrEscape())
break;
} else {
System.out.println("Phew! Got away safely");
delayForSeconds(2);
break;
}
@@ -97,34 +119,49 @@ public class ShipWarfare {
}
/**
* Asks user if they would like to fight or run against ships
*/
public void fightOrRunMessage() {
System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)", player.getGuns());
}
public int numOfPeasantShips() {
return numOfPeasantShips;
System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)\n", player.getGuns());
}
/**
* setter method that takes in an integer as an argument
* @param numOfLittyShips the number of ships to be used in the litty fleet attack
*/
public void setNumOfLittyShips(int numOfLittyShips) {
this.numOfLittyShips = numOfLittyShips;
startingLittyShips = numOfLittyShips;
}
/**
* setter method that takes in an integer as an argument
* @param numOfPeasantShips the number of ships to be used in the peasant fleet attack
*/
public void setNumOfPeasantShips(int numOfPeasantShips) {
this.numOfPeasantShips = numOfPeasantShips;
startingPeasantShips = numOfPeasantShips;
}
public void delayForASecond() throws Exception {
TimeUnit.SECONDS.sleep(1);
/**
* delays for a specific amount of seconds, takes an integer as an argument
* @param num the seconds to delay
* @throws Exception in case of errors due to the delay
*/
public void delayForSeconds(int num) throws Exception {
TimeUnit.SECONDS.sleep(num);
}
//The number of ships which attack is based on the amount of money one has on hand
/**
* The number of ships that attack is based on the amount of money one has on hand
* @return the number of ships which will attack
*/
public int numOfShips() {
int numOfShipsAttacking = 0;
@@ -148,7 +185,11 @@ public class ShipWarfare {
}
//One in two chance of running away
/**
* One in two chance of running away
* @return true if the user is allowed to run, false if not, the "default" is false
*/
public boolean runFromShips() {
userAttacks = false;
Random randomValue = new Random();
@@ -161,6 +202,11 @@ public class ShipWarfare {
return false;
}
/**
* The user faces off against the litty ships and either prevails, dies, or runs away
* @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the delay
*/
//The loot for defeating a litty fleet is much higher than that of a peasant one
public boolean destroyLittyShipsOrEscape() throws Exception {
int calculateLoot = 0;
@@ -173,29 +219,34 @@ public class ShipWarfare {
//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");
delayForSeconds(1);
} else if (hitOrMiss == 2) {
System.out.printf("ARRG! We missed %s\n", getName());
delayForSeconds(1);
} else {
System.out.println("Darn! Their fleet tanked our attack");
delayForSeconds(1);
}
System.out.println("Got eem");
delayForASecond();
} else if (hitOrMiss == 2) {
System.out.printf("ARRG! We missed %s\n", player.getName());
delayForASecond();
} else {
System.out.println("Darn! Their fleet tanked our attack");
delayForASecond();
continue;
}
} else {
continue;
}
} else {
System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName());
delayForSeconds(1);
}
@@ -203,24 +254,26 @@ public class ShipWarfare {
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, player.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);
}
}
}
}
System.out.printf("%d ships remaining\n", numOfLittyShips);
System.out.println("Oh no, they are taking the offensive!");
delayForASecond();
delayForSeconds(1);
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) {
@@ -234,7 +287,7 @@ public class ShipWarfare {
break;
}
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
delayForASecond();
delayForSeconds(1);
if (userAttacks == false) {
userAttacks = true;
}
@@ -245,8 +298,10 @@ public class ShipWarfare {
if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away");
delayForSeconds(1);
} else {
exitValue = 3;
System.out.println("Phew! Got away safely");
delayForSeconds(2);
break;
}
}
@@ -257,15 +312,18 @@ 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;
player.setMoney(player.getMoney() + calculateLoot);
System.out.printf("We got $%,d!\n", calculateLoot);
delayForSeconds(2);
return true;
} else if (exitValue == 2) {
player.gameOver();
gameOver();
return true;
} else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
delayForSeconds(2);
return true;
}
return false;
@@ -273,6 +331,11 @@ public class ShipWarfare {
}
/**
* The user faces off against the peasant ships and either prevails, dies, or runs away
* @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the delay
*/
public boolean destroyPeasantShipsOrEscape() throws Exception {
int calculateLoot = 0;
@@ -285,51 +348,62 @@ public class ShipWarfare {
//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");
delayForSeconds(1);
} else {
System.out.printf("ARRG! We missed %s\n", getName());
delayForSeconds(1);
}
System.out.println("Got eem");
delayForASecond();
} else {
System.out.printf("ARRG! We missed %s\n", player.getName());
delayForASecond();
continue;
}
} else {
continue;
}
}
else{
System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName());
delayForSeconds(1);
}
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, player.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);
}
}
}
}
System.out.printf("%d ships remaining\n", numOfPeasantShips);
delayForSeconds(1);
System.out.println("Oh no, they are taking the offensive!");
delayForASecond();
delayForSeconds(1);
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) {
@@ -343,7 +417,7 @@ public class ShipWarfare {
break;
}
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
delayForASecond();
delayForSeconds(1);
if (userAttacks == false) {
userAttacks = true;
}
@@ -366,15 +440,18 @@ 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;
player.setMoney(player.getMoney() + calculateLoot);
System.out.printf("We got $%,d!", calculateLoot);
delayForSeconds(2);
return true;
} else if (exitValue == 2) {
player.gameOver();
gameOver();
return true;
} else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
delayForSeconds(2);
return true;
}
return false;