Please find error

This commit is contained in:
KahootChampion
2019-03-09 20:03:51 -07:00
parent f5845cb8df
commit 80102eabee
2 changed files with 501 additions and 180 deletions

230
.idea/workspace.xml generated
View File

@@ -3,13 +3,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment=""> <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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/TaipanClone/ShipWarfare.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/TaipanClone/ShipWarfare.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Player.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Player.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ShipWarfare.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfare.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ShipWarfareGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfareGUI.java" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
<ignored path="C:\Users\Harkamal Randhawa\IdeaProjects\TaipanClone\.idea\shelf/" /> <ignored path="C:\Users\Harkamal Randhawa\IdeaProjects\TaipanClone\.idea\shelf/" />
<ignored path="$PROJECT_DIR$/.idea/shelf/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -19,39 +16,12 @@
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="177">
<caret line="33" column="35" selection-start-line="33" selection-start-column="35" selection-end-line="33" selection-end-column="35" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-348"> <state relative-caret-position="5025">
<caret line="264" column="40" selection-start-line="264" selection-start-column="40" selection-end-line="264" selection-end-column="40" /> <caret line="353" column="100" selection-end-line="503" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2604#2605#0" expanded="true" />
<element signature="e#2644#2645#0" expanded="true" />
<element signature="e#2683#2684#0" expanded="true" />
<element signature="e#2721#2722#0" expanded="true" />
<element signature="e#2759#2760#0" expanded="true" />
<element signature="e#2793#2794#0" expanded="true" />
<element signature="e#2837#2838#0" expanded="true" />
<element signature="e#2880#2881#0" expanded="true" />
<element signature="e#2922#2923#0" expanded="true" />
<element signature="e#2963#2964#0" expanded="true" />
<element signature="e#2997#2998#0" expanded="true" />
<element signature="e#3030#3031#0" expanded="true" />
<element signature="e#3067#3068#0" expanded="true" />
<element signature="e#3100#3101#0" expanded="true" />
<element signature="e#3155#3156#0" expanded="true" />
<element signature="e#3201#3202#0" expanded="true" />
<element signature="e#7408#7409#0" expanded="true" />
<element signature="e#7452#7453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@@ -60,22 +30,35 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2672"> <state relative-caret-position="2580">
<caret line="241" column="31" selection-start-line="241" selection-start-column="31" selection-end-line="241" selection-end-column="31" /> <caret line="172" column="5" selection-start-line="172" selection-start-column="5" selection-end-line="172" selection-end-column="5" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#1150#1151#0" expanded="true" />
<element signature="e#1178#1179#0" expanded="true" /> <element signature="e#1178#1179#0" expanded="true" />
<element signature="e#5971#5972#0" expanded="true" />
<element signature="e#6019#6020#0" expanded="true" />
<element signature="e#6052#6053#0" expanded="true" />
<element signature="e#6093#6094#0" expanded="true" />
<element signature="e#6137#6138#0" expanded="true" />
<element signature="e#6175#6176#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" column="4" selection-end-line="55" />
</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="15">
<caret line="1" column="13" selection-start-line="1" selection-start-column="13" selection-end-line="1" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ShopGUI"> <entry file="file://$PROJECT_DIR$/src/ShopGUI">
<provider selected="true" editor-type-id="text-editor" /> <provider selected="true" editor-type-id="text-editor" />
@@ -84,8 +67,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Player.java"> <entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90"> <state relative-caret-position="135">
<caret line="6" column="29" lean-forward="true" selection-start-line="6" selection-start-column="29" selection-end-line="6" selection-end-column="29" /> <caret line="9" column="32" selection-start-line="9" selection-start-column="32" selection-end-line="9" selection-end-column="32" />
</state> </state>
</provider> </provider>
</entry> </entry>
@@ -101,8 +84,6 @@
</component> </component>
<component name="FindInProjectRecents"> <component name="FindInProjectRecents">
<findStrings> <findStrings>
<find>travel</find>
<find>notDone</find>
<find>GetGuns</find> <find>GetGuns</find>
<find>set</find> <find>set</find>
<find>TaipanShop</find> <find>TaipanShop</find>
@@ -131,6 +112,8 @@
<find>litty</find> <find>litty</find>
<find>userAttacks</find> <find>userAttacks</find>
<find>numOfLittyShips</find> <find>numOfLittyShips</find>
<find>delay</find>
<find>Hp</find>
</findStrings> </findStrings>
<replaceStrings> <replaceStrings>
<replace>HP</replace> <replace>HP</replace>
@@ -154,8 +137,8 @@
<option value="$PROJECT_DIR$/src/TaipanShop.java" /> <option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/main.java" /> <option value="$PROJECT_DIR$/src/main.java" />
<option value="$PROJECT_DIR$/src/Travel.java" /> <option value="$PROJECT_DIR$/src/Travel.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/ShipWarfareGUI.java" /> <option value="$PROJECT_DIR$/src/ShipWarfareGUI.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" /> <option value="$PROJECT_DIR$/src/ShipWarfare.java" />
</list> </list>
</option> </option>
@@ -172,6 +155,7 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" />
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
<expand> <expand>
@@ -189,14 +173,13 @@
</subPane> </subPane>
</pane> </pane>
<pane id="PackagesPane" /> <pane id="PackagesPane" />
<pane id="Scope" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="ChangesTree.GroupingKeys" value="" /> <property name="ChangesTree.GroupingKeys" value="" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1552181286375" /> <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1552182988336" />
<property name="extract.method.default.visibility" value="private" /> <property name="extract.method.default.visibility" value="private" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" />
<property name="project.structure.last.edited" value="Project" /> <property name="project.structure.last.edited" value="Project" />
@@ -216,7 +199,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager" selected="Application.ShipWarfareGUI"> <component name="RunManager" selected="Application.main">
<configuration name="Game" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Game" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Game" /> <option name="MAIN_CLASS_NAME" value="Game" />
<module name="TaipanClone" /> <module name="TaipanClone" />
@@ -261,8 +244,8 @@
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Application.ShipWarfareGUI" />
<item itemvalue="Application.main" /> <item itemvalue="Application.main" />
<item itemvalue="Application.ShipWarfareGUI" />
<item itemvalue="Application.TaipanShop" /> <item itemvalue="Application.TaipanShop" />
<item itemvalue="Application.Game" /> <item itemvalue="Application.Game" />
<item itemvalue="Application.ShipWarfare" /> <item itemvalue="Application.ShipWarfare" />
@@ -291,6 +274,11 @@
<workItem from="1550878072546" duration="2009000" /> <workItem from="1550878072546" duration="2009000" />
<workItem from="1551065104002" duration="1313000" /> <workItem from="1551065104002" duration="1313000" />
<workItem from="1551158469442" duration="4822000" /> <workItem from="1551158469442" duration="4822000" />
<workItem from="1552183127375" duration="5000" />
<workItem from="1552183173819" duration="43000" />
<workItem from="1552183247090" duration="42000" />
<workItem from="1552183350012" duration="132000" />
<workItem from="1552183501892" duration="5000" />
</task> </task>
<task id="LOCAL-00001" summary="This should fix the ShipWarfare file and bring it up to date with the rest of the file."> <task id="LOCAL-00001" summary="This should fix the ShipWarfare file and bring it up to date with the rest of the file.">
<created>1550458470138</created> <created>1550458470138</created>
@@ -397,17 +385,31 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1552181324520</updated> <updated>1552181324520</updated>
</task> </task>
<option name="localTasksCounter" value="16" /> <task id="LOCAL-00016" summary="Missed one statement that I needed to encapsulate">
<created>1552181613507</created>
<option name="number" value="00016" />
<option name="presentableId" value="LOCAL-00016" />
<option name="project" value="LOCAL" />
<updated>1552181613507</updated>
</task>
<task id="LOCAL-00017" summary="Messed up player by setting money to 1000">
<created>1552181667375</created>
<option name="number" value="00017" />
<option name="presentableId" value="LOCAL-00017" />
<option name="project" value="LOCAL" />
<updated>1552181667376</updated>
</task>
<option name="localTasksCounter" value="18" />
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="55571000" /> <option name="totallyTimeSpent" value="57306000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="48" y="23" width="1189" height="652" extended-state="0" /> <frame x="48" y="23" width="1189" height="652" extended-state="0" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" weight="0.9267655" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.21621622" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" /> <window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" /> <window_info id="Designer" order="3" />
@@ -520,7 +522,9 @@
<MESSAGE value="Notified of getting attacked" /> <MESSAGE value="Notified of getting attacked" />
<MESSAGE value="Added fight stuff" /> <MESSAGE value="Added fight stuff" />
<MESSAGE value="Made ShipWarfare easier to access by ShipWarfareGUI" /> <MESSAGE value="Made ShipWarfare easier to access by ShipWarfareGUI" />
<option name="LAST_COMMIT_MESSAGE" value="Made ShipWarfare easier to access by ShipWarfareGUI" /> <MESSAGE value="Missed one statement that I needed to encapsulate" />
<MESSAGE value="Messed up player by setting money to 1000" />
<option name="LAST_COMMIT_MESSAGE" value="Messed up player by setting money to 1000" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="uml://JAVA/ShipWarfare"> <entry file="uml://JAVA/ShipWarfare">
@@ -562,37 +566,9 @@
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/Game.java" /> <entry file="file://$PROJECT_DIR$/src/Game.java" />
<entry file="file://$PROJECT_DIR$/src/Warehouse.java"> <entry file="file://$PROJECT_DIR$/src/Warehouse.java" />
<provider selected="true" editor-type-id="text-editor"> <entry file="file://$PROJECT_DIR$/src/Bank.java" />
<state relative-caret-position="34"> <entry file="file://$PROJECT_DIR$/src/TaipanShop.java" />
<caret line="2" column="3" selection-start-line="2" selection-start-column="3" selection-end-line="2" selection-end-column="3" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Start.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="590">
<caret line="70" column="24" lean-forward="true" selection-start-line="70" selection-start-column="24" selection-end-line="70" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Bank.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-872">
<caret line="7" column="6" lean-forward="true" selection-start-line="7" selection-start-column="6" selection-end-line="7" selection-end-column="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="168">
<caret line="594" column="42" lean-forward="true" selection-start-line="594" selection-start-column="42" selection-end-line="594" selection-end-column="42" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Travel.java"> <entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="27"> <state relative-caret-position="27">
@@ -603,65 +579,49 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/Player.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90"> <state relative-caret-position="5025">
<caret line="6" column="29" lean-forward="true" selection-start-line="6" selection-start-column="29" selection-end-line="6" selection-end-column="29" /> <caret line="353" column="100" selection-end-line="503" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2580">
<caret line="172" column="5" selection-start-line="172" selection-start-column="5" selection-end-line="172" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1150#1151#0" expanded="true" />
<element signature="e#1178#1179#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/ShopGUI"> <entry file="file://$PROJECT_DIR$/src/ShopGUI">
<provider selected="true" editor-type-id="text-editor" /> <provider selected="true" editor-type-id="text-editor" />
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" column="32" selection-start-line="9" selection-start-column="32" selection-end-line="9" selection-end-column="32" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Start.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="1" column="13" selection-start-line="1" selection-start-column="13" selection-end-line="1" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.java"> <entry file="file://$PROJECT_DIR$/src/main.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="177"> <state relative-caret-position="135">
<caret line="33" column="35" selection-start-line="33" selection-start-column="35" selection-end-line="33" selection-end-column="35" /> <caret line="9" column="4" selection-end-line="55" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2672">
<caret line="241" column="31" selection-start-line="241" selection-start-column="31" selection-end-line="241" selection-end-column="31" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1178#1179#0" expanded="true" />
<element signature="e#5971#5972#0" expanded="true" />
<element signature="e#6019#6020#0" expanded="true" />
<element signature="e#6052#6053#0" expanded="true" />
<element signature="e#6093#6094#0" expanded="true" />
<element signature="e#6137#6138#0" expanded="true" />
<element signature="e#6175#6176#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-348">
<caret line="264" column="40" selection-start-line="264" selection-start-column="40" selection-end-line="264" selection-end-column="40" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#2604#2605#0" expanded="true" />
<element signature="e#2644#2645#0" expanded="true" />
<element signature="e#2683#2684#0" expanded="true" />
<element signature="e#2721#2722#0" expanded="true" />
<element signature="e#2759#2760#0" expanded="true" />
<element signature="e#2793#2794#0" expanded="true" />
<element signature="e#2837#2838#0" expanded="true" />
<element signature="e#2880#2881#0" expanded="true" />
<element signature="e#2922#2923#0" expanded="true" />
<element signature="e#2963#2964#0" expanded="true" />
<element signature="e#2997#2998#0" expanded="true" />
<element signature="e#3030#3031#0" expanded="true" />
<element signature="e#3067#3068#0" expanded="true" />
<element signature="e#3100#3101#0" expanded="true" />
<element signature="e#3155#3156#0" expanded="true" />
<element signature="e#3201#3202#0" expanded="true" />
<element signature="e#7408#7409#0" expanded="true" />
<element signature="e#7452#7453#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>

View File

@@ -20,10 +20,12 @@ import javafx.animation.AnimationTimer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static javafx.application.Application.launch; import static javafx.application.Application.launch;
@SuppressWarnings("Duplicates")
public class ShipWarfareGUI extends Application { public class ShipWarfareGUI extends Application {
@@ -43,39 +45,231 @@ public class ShipWarfareGUI extends Application {
launch(args); launch(args);
} }
private int numOfPeasantShips = 0;
private int numOfLittyShips = 0;
private boolean userAttacks = true;
private int startingPeasantShips = 0;
private int startingLittyShips = 0;
private int howMuchRun = 0;
private String pirateName = "Liu Yen";
private int counter = 0; /**
* Class Constructor that takes in a type player as a parameter
* @param player object of the class Player
*/
public ShipWarfareGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/* /**
public boolean destroyPeasantShipsOrEscape(){ * setter method for player
int calculateLoot = 0; * @param player object of the class Player
String userStrikes=""; */
public void setPlayer(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* 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
* @throws Exception in case of errors due to the delay
*/
public void peasantFleetAttack() throws Exception {
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());
fightOrRunMessage();
while (true) {
String response = userResponse.nextLine();
if (response.equalsIgnoreCase("f")) {
userAttacks = true;
System.out.println("Ohh, fight ehh?");
delayForSeconds(1);
boolean winOrLose = destroyPeasantShipsOrEscape();
if (winOrLose == true) {
break;
}
int exitValue = 0; } else if (response.equalsIgnoreCase("r")) {
int chanceOfEnemyRun = 0; if (runFromShips() == false) {
System.out.println("Couldn't run away!");
if (destroyPeasantShipsOrEscape())
break;
} else {
System.out.println("Phew! Got away safely");
break;
}
}
}
}
/**
* 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());
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());
fightOrRunMessage();
while (true) {
String response = userResponse.nextLine();
if (response.equalsIgnoreCase("f")) {
userAttacks = true;
System.out.println("Ohh, fight ehh?");
boolean winOrLose = destroyLittyShipsOrEscape();
if (winOrLose == true) {
break;
}
} else if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away!");
if (destroyLittyShipsOrEscape())
break;
} else {
System.out.println("Phew! Got away safely");
delayForSeconds(2);
break;
}
}
}
}
/**
* 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)\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;
}
/**
* 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;
Random randomValue = new Random(); Random randomValue = new Random();
if (player.getMoney() <= 100000) {
//Minimum one ship will attack, maximum 20
numOfShipsAttacking = randomValue.nextInt(20) + 1;
} else if (player.getMoney() <= 200000) {
//Minimum 30 Ships will attack, maximum 70
numOfShipsAttacking = randomValue.nextInt(40) + 30;
} else if (player.getMoney() <= 500000) {
//Minimum 50 ships will attack, maximum 140
numOfShipsAttacking = randomValue.nextInt(90) + 50;
} else if (player.getMoney() > 1000000) {
//Minimum 100 ships will attack, maximum 300 ships
numOfShipsAttacking = randomValue.nextInt(3) + 100;
}
return numOfShipsAttacking;
}
/**
* 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();
int runSuccessChance = randomValue.nextInt(2) + 1;
if (runSuccessChance == 2) {
return true;
} else if (runSuccessChance == 1) {
return false;
}
return false;
}
/**
* 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
* @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the
*
* */
public boolean destroyLittyShipsOrEscape() throws Exception {
int calculateLoot = 0;
int chanceOfEnemyRun = 0;
Scanner userInput = new Scanner(System.in);
Random randomValue = new Random();
int exitValue = 0;
//Player volley //Player volley
while (exitValue == 0) { while (exitValue == 0) {
if (player.getGuns() > 0) { if (player.getGuns() > 0) {
for (int j = 0; j < player.getGuns(); j++) { for (int j = 0; j < player.getGuns(); j++) {
if (shipWarfare.isUserAttacks() == true) { if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(2) + 1; int hitOrMiss = randomValue.nextInt(3) + 1;
if (hitOrMiss == 2) { if (hitOrMiss == 1) {
shipWarfare.setNumOfPeasantShips(shipWarfare.getNumOfPeasantShips()-1); numOfLittyShips--;
if (numOfLittyShips <= 0) {
if (shipWarfare.getNumOfPeasantShips() <= 0) {
exitValue = 1; exitValue = 1;
break; break;
} }
userStrikes+= "Got eem\n";
System.out.println("Got eem"); System.out.println("Got eem");
delayForSeconds(1); delayForSeconds(1);
} else { } else if (hitOrMiss == 2) {
System.out.printf("ARRG! We missed %s\n", player.getName()); System.out.printf("ARRG! We missed %s\n", player.getName());
delayForSeconds(1); delayForSeconds(1);
} else {
System.out.println("Darn! Their fleet tanked our attack");
delayForSeconds(1);
} }
@@ -83,38 +277,167 @@ public class ShipWarfareGUI extends Application {
continue; continue;
} }
} }
} else {
System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName());
delayForSeconds(1);
}
label0.setText(userStrikes);
if (numOfLittyShips <= 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) {
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);
}
}
}
}
System.out.printf("%d ships remaining\n", numOfLittyShips);
System.out.println("Oh no, they are taking the offensive!");
delayForSeconds(1);
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) {
player.setGuns(player.getGuns() - 1);
System.out.println("Dang it! They destroyed one of our guns");
} else {
player.setHP(player.getHP() - (1 + randomValue.nextInt(15)));
}
if (player.getHP() <= 0) {
exitValue = 2;
break;
}
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
delayForSeconds(1);
if (userAttacks == false) {
userAttacks = 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());
String response = userInput.nextLine();
if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away");
delayForSeconds(1);
} else {
System.out.println("Phew! Got away safely");
delayForSeconds(2);
break;
}
}
}
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();
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;
}
/**
* 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;
int chanceOfEnemyRun = 0;
int hitCounter=0;
int missCounter=0;
Scanner userInput = new Scanner(System.in);
Random randomValue = new Random();
int exitValue = 0;
//Player volley
while (exitValue == 0) {
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;
}
hitCounter++;
delayForSeconds(1);
} else {
missCounter++;
delayForSeconds(1);
}
} else {
continue;
}
}
label1.setText(String.format("Report:\nShips we hit: %d\nShots missed: %d", hitCounter,missCounter));
} }
else{ else{
System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName()); label1.setText("We don't have any guns!!!");
delayForSeconds(1); delayForSeconds(1);
} }
if (shipWarfare.getNumOfPeasantShips() <= 0) { if (numOfPeasantShips <= 0) {
exitValue = 1; exitValue = 1;
break; break;
} }
if (player.getGuns() > 0) { if (player.getGuns() > 0) {
chanceOfEnemyRun = randomValue.nextInt(2) + 1; chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) { if (chanceOfEnemyRun == 2) {
shipWarfare.setHowMuchRun(randomValue.nextInt(15) + 1); howMuchRun = randomValue.nextInt(15) + 1;
if (shipWarfare.getHowMuchRun() != 0 && shipWarfare.getHowMuchRun() < shipWarfare.getHowMuchRun()) { if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
shipWarfare.setNumOfPeasantShips(shipWarfare.getNumOfPeasantShips() - shipWarfare.getHowMuchRun()); setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
if (shipWarfare.isUserAttacks() == true) { if (userAttacks == true) {
System.out.printf("Ahhh, %d ships ran away %s!\n", shipWarfare.getHowMuchRun(), player.getName()); System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, player.getName());
} else { } else {
System.out.printf("Escaped %d of them!\n", shipWarfare.getHowMuchRun()); System.out.printf("Escaped %d of them!\n", howMuchRun);
} }
} }
} }
} }
System.out.printf("%d ships remaining\n", shipWarfare.getNumOfPeasantShips()); System.out.printf("%d ships remaining\n", numOfPeasantShips);
delayForSeconds(1); delayForSeconds(1);
System.out.println("Oh no, they are taking the offensive!"); System.out.println("Oh no, they are taking the offensive!");
delayForSeconds(1); delayForSeconds(1);
@@ -132,14 +455,15 @@ public class ShipWarfareGUI extends Application {
} }
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
delayForSeconds(1); delayForSeconds(1);
if (shipWarfare.isUserAttacks() == false) { if (userAttacks == false) {
shipWarfare.setUserAttacks() = true; userAttacks = 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()); 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());
String response = userInput.nextLine();
if (response.equalsIgnoreCase("r")) { if (response.equalsIgnoreCase("r")) {
if (shipWarfare.runFromShips() == false) { if (runFromShips() == false) {
System.out.println("Couldn't run away"); System.out.println("Couldn't run away");
} else { } else {
exitValue = 3; exitValue = 3;
@@ -154,7 +478,7 @@ public class ShipWarfareGUI extends Application {
if (exitValue == 1) { 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()); 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); delayForSeconds(1);
calculateLoot = (randomValue.nextInt(shipWarfare.getStartingPeasantShips()) + shipWarfare.getStartingPeasantShips()) * 100; calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
player.setMoney(player.getMoney() + calculateLoot); player.setMoney(player.getMoney() + calculateLoot);
System.out.printf("We got $%,d!", calculateLoot); System.out.printf("We got $%,d!", calculateLoot);
delayForSeconds(2); delayForSeconds(2);
@@ -171,10 +495,20 @@ public class ShipWarfareGUI extends Application {
} }
*/
//Main G
private int counter = 0;
/**
* 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) { public void delayForSeconds(int num) {
try { try {
TimeUnit.SECONDS.sleep(num); TimeUnit.SECONDS.sleep(num);
@@ -184,13 +518,7 @@ public class ShipWarfareGUI extends Application {
} }
public void setPlayer(Player player) {
this.player = new Player(player);
}
public Player getPlayer() {
return new Player(player);
}
public void setLabel1(String sysOut) { public void setLabel1(String sysOut) {
label1.setText(sysOut); label1.setText(sysOut);
@@ -266,11 +594,11 @@ public class ShipWarfareGUI extends Application {
vBox.getChildren().add(label); vBox.getChildren().add(label);
vBox0.getChildren().add(label0); vBox0.getChildren().add(label0);
vBox.getChildren().add(vBox0); vBox.getChildren().add(vBox0);
int calculateLoot = 0;
int chanceOfEnemyRun = 0;
ShipWarfareGUI ship = new ShipWarfareGUI(); //label1.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), shipWarfare.getNumOfPeasantShips(), player.getHP()));
label1.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), shipWarfare.getNumOfPeasantShips(), player.getHP()));
label.setText("What would you like to do?"); label.setText("What would you like to do?");
@@ -280,19 +608,51 @@ public class ShipWarfareGUI extends Application {
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
counter++; counter++;
if (counter == 1) { if (counter == 1) {
int calculateLoot = 0;
int chanceOfEnemyRun = 0;
label.setText("Ohh, Fight ehh?"); label.setText("Ohh, Fight ehh?");
int hitCounter=0;
int missCounter=0;
Random randomValue = new Random();
int exitValue = 0;
while (exitValue == 0) {
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;
}
hitCounter++;
delayForSeconds(1);
} else {
missCounter++;
delayForSeconds(1);
}
} else {
continue;
}
}
label1.setText(String.format("Report:\nShips we hit: %d\nShots missed: %d", hitCounter, missCounter));
} else {
label1.setText("We don't have any guns!!!");
delayForSeconds(1);
}
}
label0.setText("Got eem");
} }
if (counter == 2) { if (counter == 2) {
System.out.println("You pressed the button."); System.out.println("You pressed the button twice.");
button1.setVisible(false); button1.setVisible(false);
button2.setVisible(false); button2.setVisible(false);
button1.setDisable(true); button1.setDisable(true);
@@ -309,9 +669,10 @@ public class ShipWarfareGUI extends Application {
if (counter == 1) { if (counter == 1) {
label1.setText("Ohh, Run ehh?"); label1.setText("Ohh, Run ehh?");
} }
if (counter == 2) { if (counter == 2) {
System.out.println("You pressed the button."); System.out.println("You pressed the button twice.");
button1.setVisible(false); button1.setVisible(false);
button2.setVisible(false); button2.setVisible(false);
button1.setDisable(true); button1.setDisable(true);