144 Commits
1.3 ... 3.0

Author SHA1 Message Date
0f56a515c1 Fixed some of the code related with Liu Yuen and fixed some of the javadocing 2019-03-24 23:31:05 -06:00
Siddhant Dewani
4d8265ea79 added javadocs 2019-03-24 22:45:58 -06:00
Siddhant Dewani
0d548442d4 Merge remote-tracking branch 'origin/master' 2019-03-24 22:45:25 -06:00
f0b1d42892 Merge remote-tracking branch 'origin/master' 2019-03-24 22:32:49 -06:00
bf53113834 Made it so that the user doesn't get pushed into travel if they press enter while buying something 2019-03-24 22:21:15 -06:00
Siddhant Dewani
ffc2000c70 Added javadocs 2019-03-24 22:20:00 -06:00
Vikramb987
016b765e3a Update Player.java
completed javadocs
2019-03-24 22:10:30 -06:00
384a874e09 Merge remote-tracking branch 'origin/master' 2019-03-24 22:08:05 -06:00
d82ac891f1 Commented a bit of Random Event 2019-03-24 22:07:48 -06:00
KahootChampion
f379278dc8 Completed ShipWarfareGUI 2019-03-24 21:58:53 -06:00
KahootChampion
39b494ff88 ShipWarfare javaDocs completed 2019-03-24 21:48:44 -06:00
KahootChampion
799704ad5c Fixed the issue where the ship shot with no guns 2019-03-24 21:25:57 -06:00
KahootChampion
2fb5d2fb1a Merge remote-tracking branch 'origin/master' 2019-03-24 21:02:20 -06:00
KahootChampion
bf21232510 Small error in animation whcih shoots even if no guns must fix that 2019-03-24 21:02:13 -06:00
68431ccad8 Merge remote-tracking branch 'origin/master' 2019-03-24 20:15:28 -06:00
b889ccd2bd Finished Warehouse 2019-03-24 20:15:13 -06:00
KahootChampion
31c72b3a1c changed some stuff related to the fight button animation 2019-03-24 19:50:42 -06:00
566cc9dfb2 Warehouse and Travel events are still work in progress but added their code to the github repo 2019-03-24 19:11:54 -06:00
KahootChampion
68f2c345d9 Merge remote-tracking branch 'origin/master' 2019-03-24 19:08:11 -06:00
KahootChampion
f27ee3d1d5 Made fight button basically functional for AnimationTesting 2019-03-24 19:07:51 -06:00
9012da0b3d Merge remote-tracking branch 'origin/master' 2019-03-24 16:13:46 -06:00
b8ed9bdb87 Made warehouse reappear 2019-03-24 16:12:30 -06:00
KahootChampion
3b38c2475b Sep up the scene which will be used for animation 2019-03-23 22:12:51 -06:00
KahootChampion
ddc8cd4a06 Litty Animation Practice littier 2019-03-23 19:19:44 -06:00
KahootChampion
55b3dbe0b6 Added method for animation 2019-03-23 19:18:39 -06:00
519ddec330 Merge remote-tracking branch 'origin/master' 2019-03-23 19:04:53 -06:00
cf287833f6 Made animation testing same as everyother class, can run from other classes. 2019-03-23 19:04:37 -06:00
KahootChampion
d15e0fd7d7 Added gifs back 2019-03-23 18:57:47 -06:00
KahootChampion
7ec7f00983 Litty Animation Practice 2019-03-23 18:39:20 -06:00
0024e7a5ab Should completely get rid of error messages and print statements related to save state 2019-03-23 18:15:59 -06:00
30cd4805d9 Merge remote-tracking branch 'origin/master' 2019-03-23 18:13:26 -06:00
9d113a656f Finished game saves 2019-03-23 18:13:07 -06:00
3bdd7fb55b Fixed buttons being too large on Linux and Mac 2019-03-23 15:59:35 -06:00
e6e1f02ea9 File saving is work in progress
Added a css file for the game
Made it so that you can press enter to continue forwars
Made folder for both images and save files
2019-03-23 03:37:41 -06:00
0bedf3e182 Made it so you can go inbetween screens by pressing enter, allowing for you to speed through the game without pressing buttons. 2019-03-22 23:01:31 -06:00
55ff34ef9b Moved around a few of the images and changed the dimensions of the start screen 2019-03-22 21:05:31 -06:00
KahootChampion
60cb7b3069 Maybe this is whack idk 2019-03-21 12:45:39 -06:00
KahootChampion
7ed267a6a0 Ayy added all the gifs needed. 2019-03-20 17:21:51 -06:00
KahootChampion
55c603716c Made the fight gif runnable by everyone hopefully 2019-03-19 23:53:25 -06:00
KahootChampion
7b9796f92c Made the fight gif runnable by everyone hopefully 2019-03-19 23:49:36 -06:00
KahootChampion
a33273035a Added fight Button gif. Might not work on your computers yet though... I inputed my own local documents folder as the library temporarily. 2019-03-19 23:34:54 -06:00
Vikram
2bc96e5d07 made everything use inheritance instead of whatever we were doing before. 2019-03-19 17:14:42 -06:00
Vikram
0f9ef34f54 Merge remote-tracking branch 'origin/master' 2019-03-11 19:42:14 -06:00
36f72b22e4 Merge remote-tracking branch 'origin/master' 2019-03-11 19:40:25 -06:00
4efe650091 Fixed the problem where shipwarfare didn't run after Travel 2019-03-11 19:40:13 -06:00
Vikramb987
e341112aec Update TaipanShopGUI.java
javadocs update.
2019-03-11 19:38:02 -06:00
Vikram
db4a06e652 javadocs update. 2019-03-11 19:36:23 -06:00
Vikram
a56a6690ee Merge remote-tracking branch 'origin/master' 2019-03-11 19:17:31 -06:00
Vikram
c179ac17ae fixed one small issue. 2019-03-11 19:17:13 -06:00
29e0f3e683 Merge remote-tracking branch 'origin/master' 2019-03-11 19:07:26 -06:00
923ff50c87 Finished the fix for negative numbers and Strings messing up the travel textField 2019-03-11 19:07:11 -06:00
Vikram
15525d789e fixed one small issue. 2019-03-11 19:07:06 -06:00
Vikram
e0171bacfa finished javadocs 2019-03-11 19:00:26 -06:00
KahootChampion
8c776b769b wrote javadocs for authorname 2019-03-11 18:47:10 -06:00
428a7caf80 Fixed the problem where the player could recalculate price values by leaving and entering the travel screen. 2019-03-11 18:27:42 -06:00
Vikramb987
af81624e27 Update TaipanShopGUI.java
changed the javadoc slightly.
2019-03-11 17:21:15 -06:00
KahootChampion
762b399c4b Added JavaDocs for ShipWarfare 2019-03-11 15:33:08 -06:00
Nathan Lum
8402a2368c Added Javadoc comments 2019-03-11 15:28:11 -06:00
Nathan Lum
8c3098a498 Added Javadoc comments 2019-03-11 15:20:38 -06:00
Vikramb987
f1a43a279a Update TaipanShopGUI.java 2019-03-11 15:18:05 -06:00
Nathan Lum
140e8dc706 Added Javadoc comments 2019-03-11 15:17:42 -06:00
Nathan Lum
e21a7c9f54 Added Javadoc comments 2019-03-11 15:12:03 -06:00
Nathan Lum
023e77f034 Added Javadoc comments 2019-03-11 15:07:35 -06:00
Vikramb987
696af67665 Update TaipanShopGUI.java
comment
2019-03-11 14:07:12 -06:00
cf0fd1281f Update README.md 2019-03-11 13:56:54 -06:00
Vikramb987
4e4d30c222 Update TravelGUI.java
aesthetic changes
2019-03-11 12:41:32 -06:00
Vikramb987
d2e42048b2 Update TaipanShopGUI.java
aesthetic changes boi
2019-03-11 12:40:08 -06:00
KahootChampion
303be2eea6 Fixed output for start and TaipanShop GUI 2019-03-11 12:27:17 -06:00
Siddhant Dewani
963f16afca Fixed bank label 2019-03-11 11:49:50 -06:00
Siddhant Dewani
fd03a7c588 FIXED Loanshark and bank 2019-03-11 11:41:06 -06:00
Vikramb987
c912394dd9 Update TaipanShopGUI.java
fixed minor error
2019-03-11 09:09:53 -06:00
c0914d8e5e Renamed a few classes so that all of them are uppercase 2019-03-11 02:12:10 -06:00
11b16b4e40 Finished cleaning up the code. Ready for Demo 2 2019-03-11 02:05:26 -06:00
076ba12ef1 Update README.md 2019-03-10 23:54:43 -06:00
59de84a47d Made it GUI friendly 2019-03-10 23:52:35 -06:00
e1671d8d21 Merge remote-tracking branch 'origin/master' 2019-03-10 23:50:56 -06:00
e6a67ce1e4 Removed previous textbased game 2019-03-10 23:50:41 -06:00
Nathan Lum
1ac82edf1e Added Javadoc comments 2019-03-10 23:43:19 -06:00
Nathan Lum
1df0cbec36 Added Javadoc comments 2019-03-10 23:42:24 -06:00
KahootChampion
0af20d9f67 Changed one line of text in shipwarfare GUI 2019-03-10 23:42:46 -06:00
Vikramb987
5b8682a900 Update TaipanShopGUI.java
finished javadocs
2019-03-10 23:18:20 -06:00
a58d0fa184 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/WarehouseGUI.java
2019-03-10 23:05:39 -06:00
KahootChampion
4d09891665 Added to my javadocs a bit 2019-03-10 23:03:30 -06:00
91bb72351e Fixed the Game End screen into Taipan Shop 2019-03-10 23:00:25 -06:00
KahootChampion
ba16ea1809 Completed javadocs for shipwarfare GUI 2019-03-10 22:58:43 -06:00
Nathan Lum
9b9af573a8 Added Javadoc comments 2019-03-10 22:56:26 -06:00
KahootChampion
c6df980f8e Fixed ShipWarfare bug about one-shotting. 2019-03-10 22:43:46 -06:00
Vikram
666e409e74 Merge remote-tracking branch 'origin/master' 2019-03-10 22:42:55 -06:00
Vikram
89f9e47921 some changes... 2019-03-10 22:42:40 -06:00
414a9634b5 Merge remote-tracking branch 'origin/master' 2019-03-10 22:11:07 -06:00
f4fbc474e7 Finished the End Game Screen 2019-03-10 22:10:45 -06:00
Vikram
4c8b99d4bb Merge remote-tracking branch 'origin/master' 2019-03-10 21:50:27 -06:00
Vikram
ffb77b14a0 some changes... 2019-03-10 21:49:50 -06:00
Vikramb987
0c5317cf6f Update TaipanShopGUI.java
fixed to adapt to loanshark
2019-03-10 21:15:38 -06:00
Vikram
461171ff46 minor changes. Still in progress. 2019-03-10 21:12:44 -06:00
Vikramb987
13f30b681a Update TaipanShopGUI.java
made it so that certain buttons are invisible in certain locations.
2019-03-10 21:12:26 -06:00
Siddhant Dewani
1d5e5aa706 Fixed bank and loanshark 2019-03-10 21:11:49 -06:00
Vikramb987
01ee9b2600 Update TaipanShopGUI.java
fixed shop prices not changing
2019-03-10 20:49:45 -06:00
3aa6ad619d Merge remote-tracking branch 'origin/master' 2019-03-10 20:13:33 -06:00
0b8b8ed50c Fixed output for travel 2019-03-10 20:13:06 -06:00
KahootChampion
df372522e4 Probably should upload 2019-03-10 20:12:01 -06:00
KahootChampion
4fd40af606 Completed ShipWarfareGUI 2019-03-10 20:01:20 -06:00
KahootChampion
664d194d7b Completed SHipWarfareGUI 2019-03-10 20:00:36 -06:00
KahootChampion
2198fffbd5 A lot of errors but easily fixable SHipwarfareGUI 2019-03-10 19:41:43 -06:00
d395d91730 Made it so you're not locked out of Taipan shop for Bank and Loanshark 2019-03-10 18:54:03 -06:00
31e93f6997 Fixed BorderPane issue in Warehouse 2019-03-10 18:38:24 -06:00
0f2e8848ad Merged together Taipanshop with both Loanshark and Bank GUI 2019-03-10 18:36:54 -06:00
c3f7cc16d2 Merge remote-tracking branch 'origin/master' 2019-03-10 18:29:17 -06:00
9a15f6bc63 Merged TaipanShop and Warehouse. Just need to add functionality to warehouse. 2019-03-10 18:28:59 -06:00
Siddhant Dewani
680225550f Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with. 2019-03-10 18:23:48 -06:00
Siddhant Dewani
6778aa5737 Merge remote-tracking branch 'origin/master' 2019-03-10 18:07:34 -06:00
Siddhant Dewani
46624389f5 Finished LoanShark!! 2019-03-10 18:06:03 -06:00
a0e0ab517d Merged Travel and Ship warfare 2019-03-10 17:35:46 -06:00
Nathan Lum
5e33374e3c Add files via upload 2019-03-10 17:27:17 -06:00
325c4127dd Fix bunch of issues with Travel and Taipanshop, also merged Main, Shop, Travel and Start. Now attempting to merge in ship. 2019-03-10 16:06:48 -06:00
KahootChampion
fde76a5bfb Just checking 2019-03-10 15:45:31 -06:00
KahootChampion
888d8a1c92 Fined minor bugs in shipwarfareGUI including the "gun frustration" variable 2019-03-10 12:10:33 -06:00
KahootChampion
42c4534f52 Fixed probability of ships running away 2019-03-10 12:00:00 -06:00
KahootChampion
a07d633ff9 Basic functionality of buttons completed, think all I have to do now is to find a way to break the code when the user wins, loses or runs away. 2019-03-10 11:26:54 -06:00
KahootChampion
b4e0e18d20 Completely ruined shipWarfare with a previous edit, fixed it and added a better loot feature for peasant ships 2019-03-10 03:30:28 -06:00
KahootChampion
d558e7cf0c Fixed the loot system a bit 2019-03-10 01:44:02 -07:00
KahootChampion
36aa789590 Fixed numOfShips method for ShipWarfareGUI 2019-03-10 01:14:37 -07:00
KahootChampion
e5807a46af Shipwarfare fight button GUI almost complete 2019-03-10 00:39:59 -07:00
KahootChampion
5f6abbc817 ShipWarfare fight button coming along nicely 2019-03-09 23:52:51 -07:00
b376ad5284 Fixed loop problem ShipwarfareGUI 2019-03-09 23:36:58 -07:00
b945cafe98 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	.idea/workspace.xml
2019-03-09 23:27:03 -07:00
75673d40e1 Finished TravelGUI and StartGUI 2019-03-09 23:26:25 -07:00
KahootChampion
9feac6e90e Forces you to fight in ShipWarfareGUI unfortunately 2019-03-09 22:52:30 -07:00
KahootChampion
1bb00d0d01 Super broken but fight button is in progress for shipwarfare 2019-03-09 22:32:45 -07:00
KahootChampion
80102eabee Please find error 2019-03-09 20:03:51 -07:00
KahootChampion
f5845cb8df Messed up player by setting money to 1000 2019-03-09 18:34:27 -07:00
KahootChampion
5a7d1e7c34 Missed one statement that I needed to encapsulate 2019-03-09 18:33:33 -07:00
KahootChampion
370b3ee041 Made ShipWarfare easier to access by ShipWarfareGUI 2019-03-09 18:28:44 -07:00
Vikramb987
7314bc174f Update ShopGUI
Mostly done.
2019-03-09 16:51:26 -07:00
KahootChampion
5c78f561d8 Added fight stuff 2019-03-09 16:13:36 -07:00
KahootChampion
271a37877b Notified of getting attacked 2019-03-09 16:09:15 -07:00
KahootChampion
89188152e6 Added time stuff to Shipwarfare GUI 2019-03-09 15:00:00 -07:00
6b9e3dcc06 Added some logic to ShipWarfareGUI 2019-03-09 14:33:27 -07:00
14e5eb2d30 Added basic functionality with KahootChampion 2019-03-09 14:28:02 -07:00
bf2d1c3fb0 Basic layout for ShipwarefareGUI. 2019-03-09 14:14:03 -07:00
Vikramb987
b62274cda3 Update ShopGUI
another set of updates.
2019-03-09 12:04:18 -07:00
Vikramb987
72708e53f2 Update ShopGUI
small change.
2019-03-08 19:44:05 -07:00
Vikramb987
540605f0f1 Update ShopGUI
Updated. Still a w.i.p
2019-03-08 19:36:55 -07:00
Vikramb987
f6fa9dc646 Create ShopGUI
This file is the temporary placeholder for my shop GUI. Very much still in progress.
2019-03-07 20:57:36 -07:00
31 changed files with 4248 additions and 2330 deletions

2
.idea/misc.xml generated
View File

@@ -9,7 +9,7 @@
<component name="ProjectKey">
<option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_141" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_201" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SvnBranchConfigurationManager">

615
.idea/workspace.xml generated
View File

@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment="Fixed the commenting on a lot of the code. Also added some stuff to Travel, fixed some bugs.">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment="Made the fight gif runnable by everyone hopefully">
<change afterPath="$PROJECT_DIR$/src/ShipsRunning.gif" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Travel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Travel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ShipWarfareGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfareGUI.java" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<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="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -17,29 +17,11 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<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="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>
</file>
<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="184">
<caret line="42" column="62" selection-start-line="42" selection-start-column="62" selection-end-line="42" selection-end-column="62" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="27">
<caret line="125" column="63" selection-start-line="125" selection-start-column="63" selection-end-line="125" selection-end-column="63" />
<state relative-caret-position="99">
<caret line="466" column="51" lean-forward="true" selection-start-line="466" selection-start-column="51" selection-end-line="466" selection-end-column="51" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -48,52 +30,20 @@
</entry>
</file>
<file pinned="false" current-in-tab="false">
<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 file="file://$PROJECT_DIR$/src/ShipsRunning.gif">
<provider selected="true" editor-type-id="images" />
</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="-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 file="file://$PROJECT_DIR$/src/ShipsAttacking.gif">
<provider selected="true" editor-type-id="images" />
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<entry file="file://$PROJECT_DIR$/src/TravelGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-2606">
<caret line="24" column="5" lean-forward="true" selection-start-line="24" selection-start-column="5" selection-end-line="24" selection-end-column="5" />
</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="17">
<caret line="353" column="11" selection-start-line="353" selection-start-column="11" selection-end-line="353" selection-end-column="11" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</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="34">
<caret line="2" column="3" selection-start-line="2" selection-start-column="3" selection-end-line="2" selection-end-column="3" />
<state relative-caret-position="251">
<caret line="180" column="18" selection-start-line="180" selection-start-column="18" selection-end-line="182" selection-end-column="17" />
</state>
</provider>
</entry>
@@ -109,25 +59,51 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>Hp</find>
<find>travel</find>
<find>notDone</find>
<find>GetGuns</find>
<find>get</find>
<find>set</find>
<find>TaipanShop</find>
<find>shop()</find>
<find>shop</find>
<find>initialize</find>
<find>gif</find>
<find>shipsRemainingGIF</find>
<find>initial</find>
<find>initializeS</find>
<find>ship</find>
<find>imageView</find>
<find>20</find>
<find>shipsAttackingGif.set</find>
<find>continueto</find>
<find>setprefwidth</find>
<find>setvisible(false)</find>
<find>chooseF</find>
<find>setPadd</find>
<find>setvisible</find>
<find>vbox.se</find>
<find>attacking</find>
<find>would</find>
<find>choosefightorrun.set</find>
<find>setpre</find>
<find>run</find>
<find>setvisi</find>
<find>fightand</find>
<find>shipWarfa</find>
<find>imageview</find>
<find>image</find>
<find>shipsAttack</find>
<find>shipsAttackingOr</find>
<find>ships</find>
<find>shipw</find>
</findStrings>
<replaceStrings>
<replace>HP</replace>
<replace>p1.get</replace>
<replace>p1.set</replace>
<replace>shipWarfare.getHowMuchRun()</replace>
<replace>shipWarfare.isUserAttacks()</replace>
<replace>shipWarfare.getNumOfPeasantShips()</replace>
<replace>attackImage</replace>
<replace>shipsAttacking</replace>
<replace>shipsApproachingGIF</replace>
</replaceStrings>
</component>
<component name="Git.Settings">
<option name="UPDATE_CHANGES_POLICY" value="SHELVE" />
<option name="UPDATE_TYPE" value="MERGE" />
<option name="UPDATE_TYPE" value="REBASE" />
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
@@ -135,31 +111,31 @@
<list>
<option value="$PROJECT_DIR$/src/Core.java" />
<option value="$PROJECT_DIR$/src/Game.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/Start.java" />
<option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/main.java" />
<option value="$PROJECT_DIR$/src/Travel.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
<option value="$PROJECT_DIR$/src/TaipanShopGUI.java" />
<option value="$PROJECT_DIR$/src/StartGUI.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/TravelGUI.java" />
<option value="$PROJECT_DIR$/src/ShipWarfareGUI.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="167" />
<option name="y" value="-11" />
<option name="width" value="1696" />
<option name="height" value="1026" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
<component name="ProjectFrameBounds">
<option name="y" value="23" />
<option name="width" value="1189" />
<option name="height" value="652" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
@@ -176,20 +152,26 @@
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="ChangesTree.GroupingKeys" value="" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1551163322073" />
<property name="extract.method.default.visibility" value="private" />
<property name="last_opened_file_path" value="$USER_HOME$/Documents/GitHub/Cpsc233" />
<property name="project.structure.last.edited" value="Project" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1552534669451" />
<property name="extract.method.default.visibility" value="public" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" />
<property name="project.structure.last.edited" value="Modules" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
<property name="settings.editor.selected.configurable" value="editing.templates" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
@@ -202,7 +184,7 @@
</list>
</option>
</component>
<component name="RunManager" selected="Application.main">
<component name="RunManager" selected="Application.MainGUI">
<configuration name="Game" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Game" />
<module name="TaipanClone" />
@@ -210,8 +192,15 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ShipWarfare" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="ShipWarfare" />
<configuration name="MainGUI" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="MainGUI" />
<module name="TaipanClone" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ShipWarfareGUI" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="ShipWarfareGUI" />
<module name="TaipanClone" />
<method v="2">
<option name="Make" enabled="true" />
@@ -224,13 +213,6 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Travel" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Travel" />
<module name="TaipanClone" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="main" />
<module name="TaipanClone" />
@@ -239,19 +221,19 @@
</method>
</configuration>
<list>
<item itemvalue="Application.ShipWarfare" />
<item itemvalue="Application.TaipanShop" />
<item itemvalue="Application.Travel" />
<item itemvalue="Application.Game" />
<item itemvalue="Application.main" />
<item itemvalue="Application.ShipWarfareGUI" />
<item itemvalue="Application.MainGUI" />
</list>
<recent_temporary>
<list>
<item itemvalue="Application.MainGUI" />
<item itemvalue="Application.ShipWarfareGUI" />
<item itemvalue="Application.main" />
<item itemvalue="Application.TaipanShop" />
<item itemvalue="Application.Game" />
<item itemvalue="Application.ShipWarfare" />
<item itemvalue="Application.Travel" />
</list>
</recent_temporary>
</component>
@@ -277,6 +259,36 @@
<workItem from="1550878072546" duration="2009000" />
<workItem from="1551065104002" duration="1313000" />
<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" />
<workItem from="1552187010251" duration="1043000" />
<workItem from="1552195875453" duration="55000" />
<workItem from="1552195941602" duration="33000" />
<workItem from="1552195980542" duration="513000" />
<workItem from="1552197114688" duration="110000" />
<workItem from="1552198897279" duration="7000" />
<workItem from="1552199842131" duration="998000" />
<workItem from="1552201459117" duration="275000" />
<workItem from="1552203562938" duration="2174000" />
<workItem from="1552207404121" duration="54000" />
<workItem from="1552210170594" duration="72000" />
<workItem from="1552238757321" duration="742000" />
<workItem from="1552240770629" duration="40000" />
<workItem from="1552241394045" duration="178000" />
<workItem from="1552254283748" duration="9473000" />
<workItem from="1552277298937" duration="11151000" />
<workItem from="1552353291496" duration="1918000" />
<workItem from="1552359156805" duration="98000" />
<workItem from="1552533765176" duration="1016000" />
<workItem from="1552622234355" duration="130000" />
<workItem from="1553037480176" duration="499000" />
<workItem from="1553047073421" duration="2245000" />
<workItem from="1553050110780" duration="21000" />
<workItem from="1553051761247" duration="104000" />
<workItem from="1553051882218" duration="9623000" />
</task>
<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>
@@ -355,16 +367,241 @@
<option name="project" value="LOCAL" />
<updated>1551162699319</updated>
</task>
<option name="localTasksCounter" value="12" />
<task id="LOCAL-00012" summary="Added time stuff to Shipwarfare GUI">
<created>1552168801248</created>
<option name="number" value="00012" />
<option name="presentableId" value="LOCAL-00012" />
<option name="project" value="LOCAL" />
<updated>1552168801248</updated>
</task>
<task id="LOCAL-00013" summary="Notified of getting attacked">
<created>1552172956109</created>
<option name="number" value="00013" />
<option name="presentableId" value="LOCAL-00013" />
<option name="project" value="LOCAL" />
<updated>1552172956109</updated>
</task>
<task id="LOCAL-00014" summary="Added fight stuff">
<created>1552173216531</created>
<option name="number" value="00014" />
<option name="presentableId" value="LOCAL-00014" />
<option name="project" value="LOCAL" />
<updated>1552173216532</updated>
</task>
<task id="LOCAL-00015" summary="Made ShipWarfare easier to access by ShipWarfareGUI">
<created>1552181324520</created>
<option name="number" value="00015" />
<option name="presentableId" value="LOCAL-00015" />
<option name="project" value="LOCAL" />
<updated>1552181324520</updated>
</task>
<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>
<task id="LOCAL-00018" summary="Please find error">
<created>1552187032139</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1552187032139</updated>
</task>
<task id="LOCAL-00019" summary="Super broken but fight button is in progress for shipwarfare">
<created>1552195966566</created>
<option name="number" value="00019" />
<option name="presentableId" value="LOCAL-00019" />
<option name="project" value="LOCAL" />
<updated>1552195966566</updated>
</task>
<task id="LOCAL-00020" summary="Forces you to fight in ShipWarfareGUI unfortunately">
<created>1552197150577</created>
<option name="number" value="00020" />
<option name="presentableId" value="LOCAL-00020" />
<option name="project" value="LOCAL" />
<updated>1552197150577</updated>
</task>
<task id="LOCAL-00021" summary="ShipWarfare fight button coming along nicely">
<created>1552200771732</created>
<option name="number" value="00021" />
<option name="presentableId" value="LOCAL-00021" />
<option name="project" value="LOCAL" />
<updated>1552200771732</updated>
</task>
<task id="LOCAL-00022" summary="Shipwarfare fight button GUI almost complete">
<created>1552203599900</created>
<option name="number" value="00022" />
<option name="presentableId" value="LOCAL-00022" />
<option name="project" value="LOCAL" />
<updated>1552203599900</updated>
</task>
<task id="LOCAL-00023" summary="Fixed numOfShips method for ShipWarfareGUI">
<created>1552205678080</created>
<option name="number" value="00023" />
<option name="presentableId" value="LOCAL-00023" />
<option name="project" value="LOCAL" />
<updated>1552205678080</updated>
</task>
<task id="LOCAL-00024" summary="Fixed the loot system a bit">
<created>1552207442784</created>
<option name="number" value="00024" />
<option name="presentableId" value="LOCAL-00024" />
<option name="project" value="LOCAL" />
<updated>1552207442785</updated>
</task>
<task id="LOCAL-00025" summary="Completely ruined shipWarfare with a previous edit, fixed it and added a better loot feature for peasant ships">
<created>1552210228514</created>
<option name="number" value="00025" />
<option name="presentableId" value="LOCAL-00025" />
<option name="project" value="LOCAL" />
<updated>1552210228514</updated>
</task>
<task id="LOCAL-00026" summary="Basic functionality of buttons completed, think all I have to do now is to find a way to break the code when the user wins, loses or runs away.">
<created>1552238814974</created>
<option name="number" value="00026" />
<option name="presentableId" value="LOCAL-00026" />
<option name="project" value="LOCAL" />
<updated>1552238814974</updated>
</task>
<task id="LOCAL-00027" summary="Fixed probability of ships running away">
<created>1552240801199</created>
<option name="number" value="00027" />
<option name="presentableId" value="LOCAL-00027" />
<option name="project" value="LOCAL" />
<updated>1552240801199</updated>
</task>
<task id="LOCAL-00028" summary="Fined minor bugs in shipwarfareGUI including the &quot;gun frustration&quot; variable">
<created>1552241433802</created>
<option name="number" value="00028" />
<option name="presentableId" value="LOCAL-00028" />
<option name="project" value="LOCAL" />
<updated>1552241433802</updated>
</task>
<task id="LOCAL-00029" summary="Just checking">
<created>1552254331758</created>
<option name="number" value="00029" />
<option name="presentableId" value="LOCAL-00029" />
<option name="project" value="LOCAL" />
<updated>1552254331759</updated>
</task>
<task id="LOCAL-00030" summary="A lot of errors but easily fixable SHipwarfareGUI">
<created>1552268490741</created>
<option name="number" value="00030" />
<option name="presentableId" value="LOCAL-00030" />
<option name="project" value="LOCAL" />
<updated>1552268490741</updated>
</task>
<task id="LOCAL-00031" summary="Completed SHipWarfareGUI">
<created>1552269636545</created>
<option name="number" value="00031" />
<option name="presentableId" value="LOCAL-00031" />
<option name="project" value="LOCAL" />
<updated>1552269636545</updated>
</task>
<task id="LOCAL-00032" summary="Completed ShipWarfareGUI">
<created>1552269681200</created>
<option name="number" value="00032" />
<option name="presentableId" value="LOCAL-00032" />
<option name="project" value="LOCAL" />
<updated>1552269681200</updated>
</task>
<task id="LOCAL-00033" summary="Probably should upload">
<created>1552270321401</created>
<option name="number" value="00033" />
<option name="presentableId" value="LOCAL-00033" />
<option name="project" value="LOCAL" />
<updated>1552270321402</updated>
</task>
<task id="LOCAL-00034" summary="Fixed ShipWarfare bug about one-shotting.">
<created>1552279406065</created>
<option name="number" value="00034" />
<option name="presentableId" value="LOCAL-00034" />
<option name="project" value="LOCAL" />
<updated>1552279406066</updated>
</task>
<task id="LOCAL-00035" summary="Completed javadocs for shipwarfare GUI">
<created>1552280311398</created>
<option name="number" value="00035" />
<option name="presentableId" value="LOCAL-00035" />
<option name="project" value="LOCAL" />
<updated>1552280311399</updated>
</task>
<task id="LOCAL-00036" summary="Added to my javadocs a bit">
<created>1552280610787</created>
<option name="number" value="00036" />
<option name="presentableId" value="LOCAL-00036" />
<option name="project" value="LOCAL" />
<updated>1552280610787</updated>
</task>
<task id="LOCAL-00037" summary="Changed one line of text in shipwarfare GUI">
<created>1552282957716</created>
<option name="number" value="00037" />
<option name="presentableId" value="LOCAL-00037" />
<option name="project" value="LOCAL" />
<updated>1552282957716</updated>
</task>
<task id="LOCAL-00038" summary="Fixed output for start and TaipanShop GUI">
<created>1552328825548</created>
<option name="number" value="00038" />
<option name="presentableId" value="LOCAL-00038" />
<option name="project" value="LOCAL" />
<updated>1552328825548</updated>
</task>
<task id="LOCAL-00039" summary="Added JavaDocs for ShipWarfare">
<created>1552339973224</created>
<option name="number" value="00039" />
<option name="presentableId" value="LOCAL-00039" />
<option name="project" value="LOCAL" />
<updated>1552339973224</updated>
</task>
<task id="LOCAL-00040" summary="wrote javadocs for authorname">
<created>1552351619924</created>
<option name="number" value="00040" />
<option name="presentableId" value="LOCAL-00040" />
<option name="project" value="LOCAL" />
<updated>1552351619924</updated>
</task>
<task id="LOCAL-00041" summary="Added fight Button gif. Might not work on your computers yet though... I inputed my own local documents folder as the library temporarily.">
<created>1553060094595</created>
<option name="number" value="00041" />
<option name="presentableId" value="LOCAL-00041" />
<option name="project" value="LOCAL" />
<updated>1553060094595</updated>
</task>
<task id="LOCAL-00042" summary="Made the fight gif runnable by everyone hopefully">
<created>1553060976358</created>
<option name="number" value="00042" />
<option name="presentableId" value="LOCAL-00042" />
<option name="project" value="LOCAL" />
<updated>1553060976358</updated>
</task>
<task id="LOCAL-00043" summary="Made the fight gif runnable by everyone hopefully">
<created>1553061205759</created>
<option name="number" value="00043" />
<option name="presentableId" value="LOCAL-00043" />
<option name="project" value="LOCAL" />
<updated>1553061205759</updated>
</task>
<option name="localTasksCounter" value="44" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="42486000" />
<option name="totallyTimeSpent" value="99878000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1696" height="1026" extended-state="7" />
<frame x="0" y="23" width="1189" height="652" extended-state="0" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.21026894" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.32519618" />
<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" />
@@ -373,7 +610,7 @@
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32922733" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.3975364" />
<window_info anchor="bottom" id="Run" order="2" weight="0.9357143" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -383,8 +620,8 @@
<window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Terminal" order="10" weight="0.32922733" />
<window_info anchor="bottom" id="Event Log" order="11" sideWeight="0.50061125" side_tool="true" weight="0.32922733" />
<window_info anchor="bottom" id="Messages" order="12" sideWeight="0.49938875" weight="0.32922733" />
<window_info anchor="bottom" id="Duplicate detector" order="13" weight="0.32922733" />
<window_info anchor="bottom" id="Messages" order="12" sideWeight="0.49938875" weight="0.32857144" />
<window_info anchor="bottom" id="Duplicate detector" order="13" weight="0.32857144" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@@ -441,22 +678,52 @@
</list>
</option>
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="RECENT_FILTERS">
<map>
<entry key="Branch">
<value>
<list />
</value>
</entry>
<entry key="User">
<value>
<list />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<ignored-roots>
<path value="$PROJECT_DIR$" />
</ignored-roots>
<MESSAGE value="This should fix the project repository once and for all." />
<MESSAGE value="This should fix the ShipWarfare file and bring it up to date with the rest of the file." />
<MESSAGE value="Created Core class" />
<MESSAGE value="Fixed the setters to be greater than 0" />
<MESSAGE value="Created Player class" />
<MESSAGE value="Added some stuff for the Travel Class" />
<MESSAGE value="Added disasters as well as removing a bug from the flee method in Haris's code" />
<MESSAGE value="Fixed a bunch of stuff inside of Travel, but also discovered a MASSIVE problem with our code" />
<MESSAGE value="Fixed stupid problem where you can't access methods above yours" />
<MESSAGE value="Brought back Vikram's changes" />
<MESSAGE value="Fixed the commenting on a lot of the code. Also added some stuff to Travel, fixed some bugs." />
<option name="LAST_COMMIT_MESSAGE" value="Fixed the commenting on a lot of the code. Also added some stuff to Travel, fixed some bugs." />
<MESSAGE value="Super broken but fight button is in progress for shipwarfare" />
<MESSAGE value="Forces you to fight in ShipWarfareGUI unfortunately" />
<MESSAGE value="ShipWarfare fight button coming along nicely" />
<MESSAGE value="Shipwarfare fight button GUI almost complete" />
<MESSAGE value="Fixed numOfShips method for ShipWarfareGUI" />
<MESSAGE value="Fixed the loot system a bit" />
<MESSAGE value="Completely ruined shipWarfare with a previous edit, fixed it and added a better loot feature for peasant ships" />
<MESSAGE value="Basic functionality of buttons completed, think all I have to do now is to find a way to break the code when the user wins, loses or runs away." />
<MESSAGE value="Fixed probability of ships running away" />
<MESSAGE value="Fined minor bugs in shipwarfareGUI" />
<MESSAGE value="Fined minor bugs in shipwarfareGUI including the &quot;gun frustration&quot; variable" />
<MESSAGE value="Just checking" />
<MESSAGE value="A lot of errors but easily fixable SHipwarfareGUI" />
<MESSAGE value="Completed SHipWarfareGUI" />
<MESSAGE value="Completed ShipWarfareGUI" />
<MESSAGE value="Probably should upload" />
<MESSAGE value="Fixed ShipWarfare bug about one-shotting." />
<MESSAGE value="Completed javadocs for shipwarfare GUI" />
<MESSAGE value="Added to my javadocs a bit" />
<MESSAGE value="Changed one line of text in shipwarfare GUI" />
<MESSAGE value="Fixed output for start and TaipanShop GUI" />
<MESSAGE value="Added JavaDocs for ShipWarfare" />
<MESSAGE value="wrote javadocs for authorname" />
<MESSAGE value="Added fight Button gif. Might not work on your computers yet though... I inputed my own local documents folder as the library temporarily." />
<MESSAGE value="Made the fight gif runnable by everyone hopefully" />
<option name="LAST_COMMIT_MESSAGE" value="Made the fight gif runnable by everyone hopefully" />
</component>
<component name="editorHistoryManager">
<entry file="uml://JAVA/ShipWarfare">
@@ -498,65 +765,102 @@
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Game.java" />
<entry file="file://$PROJECT_DIR$/src/Warehouse.java">
<entry file="file://$PROJECT_DIR$/src/Warehouse.java" />
<entry file="file://$PROJECT_DIR$/src/Bank.java" />
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java" />
<entry file="file://$PROJECT_DIR$/src/Travel.java" />
<entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/javafx-src.zip!/com/sun/glass/ui/InvokeLaterDispatcher.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="3" selection-start-line="2" selection-start-column="3" selection-end-line="2" selection-end-column="3" />
<state relative-caret-position="140">
<caret line="110" column="19" selection-start-line="110" selection-start-column="19" selection-end-line="110" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Start.java">
<entry file="file://$PROJECT_DIR$/src/ShopGUI" />
<entry file="file://$PROJECT_DIR$/src/Start.java" />
<entry file="file://$PROJECT_DIR$/src/main.java" />
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java" />
<entry file="file://$PROJECT_DIR$/src/WarehouseGUI.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 relative-caret-position="-1968">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Bank.java">
<entry file="file://$PROJECT_DIR$/src/StartGUI.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 relative-caret-position="30">
<caret line="10" selection-start-line="10" selection-end-line="15" selection-end-column="2" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<entry file="file://$PROJECT_DIR$/src/GameEndGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="353" column="11" selection-start-line="353" selection-start-column="11" selection-end-line="353" selection-end-column="11" />
<state relative-caret-position="120">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/LoanSharkGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="12" column="13" selection-start-line="12" selection-start-column="13" selection-end-line="12" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/BankGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="240">
<caret line="26" column="51" lean-forward="true" selection-start-line="26" selection-start-column="51" selection-end-line="26" selection-end-column="51" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/MainGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="150">
<caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#551#552#0" expanded="true" />
<element signature="e#579#580#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Ships Approaching.gif" />
<entry file="file://$PROJECT_DIR$/src/TaipanShopGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4902">
<caret line="370" column="35" selection-start-line="370" selection-start-column="35" selection-end-line="370" selection-end-column="35" />
<folding>
<element signature="n#!!doc" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-2606">
<caret line="24" column="5" lean-forward="true" selection-start-line="24" selection-start-column="5" selection-end-line="24" selection-end-column="5" />
<state relative-caret-position="300">
<caret line="20" column="25" lean-forward="true" selection-start-line="20" selection-start-column="25" selection-end-line="20" selection-end-column="25" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<entry file="file://$PROJECT_DIR$/src/ShipsAttacking.gif">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipsRunning.gif">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/src/TravelGUI.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 relative-caret-position="251">
<caret line="180" column="18" selection-start-line="180" selection-start-column="18" selection-end-line="182" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.java">
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="184">
<caret line="42" column="62" selection-start-line="42" selection-start-column="62" selection-end-line="42" selection-end-column="62" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="27">
<caret line="125" column="63" selection-start-line="125" selection-start-column="63" selection-end-line="125" selection-end-column="63" />
<state relative-caret-position="99">
<caret line="466" column="51" lean-forward="true" selection-start-line="466" selection-start-column="51" selection-end-line="466" selection-end-column="51" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -603,7 +907,7 @@
</state>
<state key="JdkListConfigurable.UI">
<settings>
<last-edited>1.8</last-edited>
<last-edited>1.8.0_201</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
@@ -620,7 +924,6 @@
<option name="proportions">
<list>
<option value="0.2" />
<option value="0.6" />
</list>
</option>
</splitter-proportions>

View File

@@ -2,12 +2,10 @@
Computer Science 233 project, Winter 2019
How to run:
If you are using intellij, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder in intellij. Also set up the SDK. Then, run main.java.
If you are using intellij, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder in intellij. Also set up the SDK. Then, run MainGUI.java.
If you are using the command line, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder. Open your terminal and change its directory to the "src" folder within "TaipanClone-master" folder. Then, type in "javac *.java", this compiles all the necessary files. Now, run main.java using "java main".
If you are using the command line, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder. Open your terminal and change its directory to the "src" folder within "TaipanClone-master" folder. Then, type in "javac *.java", this compiles all the necessary files. Now, run MainGUI.java using "java MainGUI".
Additional information:
For input, the program usually takes the first letter of whichever option you need to select. Example:
What would you like to buy? Valid inputs are "O" (for Opium), "S" (for Silk), "A" (for Arms), "G" (for General cargo).
You lose if your HP reaches 0. You can win if you "retire" in Hong Kong while having a net worth of over $1 million.

View File

@@ -9,4 +9,3 @@
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -1,102 +0,0 @@
import java.util.Scanner;
public class Bank{
private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
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;
}
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public Bank(Player player){
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* This method is used to withdraw or deposit money into the bank account
* by prompting the user if they would like to withdraw or deposit. Followed
* by prompting them to enter an amount to transfer. This method also uses the
* player class to see if the transfer can be made,and if it can it changes the
* values accordingly
*/
public void bank(){
Scanner input = new Scanner(System.in);
boolean notDone = true;
int check = 0;
while(notDone){
//Prompt the user if they want to withdraw or deposit
System.out.println("Would you like to Withdraw or Deposit?");
String response = input.nextLine();
//If user chose withdraw then subtract the amount from bank account and add it to cash
if(response.equalsIgnoreCase("W")){
boolean notDone2 = true;
while(notDone2){
System.out.println("How much do you wish to Withdraw?");
int withdraw = input.nextInt();
//Prompt the user for the amount and check if the bank has sufficient funds
if(withdraw <= player.getBank()){
player.setMoney(withdraw + player.getMoney());
player.setBank(player.getBank()-withdraw);
notDone2 = false;
check = 1;
}
}
}
//If the user chooses to deposit the continue to this code
else if(response.equalsIgnoreCase("D")){
boolean notDone2 = true;
while(notDone2){
//Prompt the user for the amount they would like to deposit and ensure suffiecent funds
System.out.println("How much do you wish to Deposit?");
int deposit = input.nextInt();
if(deposit <= player.getMoney()){
player.setBank(deposit + player.getBank());
player.setMoney(player.getMoney()-deposit);
notDone2 = false;
check = 1;
}
}
}
if(check == 1){
boolean notDone3 = true;
// Asks user if they would like to continue in bank or not
while(notDone3){
System.out.println("Would you like to continue? Y/N");
response = input.nextLine();
response = input.nextLine();
if(response.equalsIgnoreCase("Y")){
notDone3 = false;
}else if(response.equalsIgnoreCase("N")){
notDone = false;
notDone3 = false;
}
}
}
}
}
}

187
src/BankGUI.java Normal file
View File

@@ -0,0 +1,187 @@
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class BankGUI extends Player{
/**
* 2019-03-10
* Authors: Siddhant Dewani
* BankGUI allows the user to store cash and gain interest off of the cash
*/
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public BankGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* Initializes the GUI for the Bank in our game.
*
* @param primaryStage
* @return
*/
public Stage initializeBank(Stage primaryStage) {
primaryStage.setTitle("Bank");
/**
* Creating all the layouts, labels, buttons, and a textfield.
*
*/
BorderPane brdr1 = new BorderPane();
HBox hbx1 = new HBox(30);
HBox hbx2 = new HBox(30);
VBox vbx1 = new VBox(30);
Label l1 = new Label("Player: " + getName());
Label l2 = new Label("Current Balance: " + getBank());
Label l3 = new Label("Enter Amount: ");
Label l4 = new Label("Current cash: " + getMoney());
Label l5 = new Label(" ");
Button b1 = new Button("Withdraw");
Button b2 = new Button("Deposit");
Button b3 = new Button("Go back");
TextField txtField1 = new TextField();
/**
* Adds the buttons so that they are at the bottom of the screen.
*
*/
hbx1.setAlignment(Pos.CENTER);
hbx1.getChildren().add(b1);
hbx1.getChildren().add(b2);
hbx1.getChildren().add(b3);
hbx1.setPadding(new Insets(0,0,20,0));
brdr1.setBottom(hbx1);
/**
* Adds the text field to the center of the screen.
*
*/
hbx2.setAlignment(Pos.CENTER);
hbx2.getChildren().add(l3);
hbx2.getChildren().add(txtField1);
brdr1.setCenter(hbx2);
/**
* Adds the labels to the top of the screen.
*
*/
vbx1.setAlignment(Pos.CENTER);
vbx1.getChildren().add(l1);
vbx1.getChildren().add(l2);
vbx1.getChildren().add(l4);
vbx1.getChildren().add(l5);
vbx1.setPadding(new Insets(20,0,0,0));
brdr1.setTop(vbx1);
/**
* Adds function to button 1 which, when clicked, withdraws money from your bank to your person but, will not let you overdraw.
*
*/
b1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
int withdraw = Integer.parseInt(txtField1.getText());
if(withdraw < 0){
l5.setText("Come on " + getName() + " are you trying to fool me??? \n No negative Numbers Please");
}
else if (withdraw <= getBank()) {
setMoney(withdraw + getMoney());
setBank(getBank() - withdraw);
}
else {
l5.setText("Sorry you cannot withdraw that much");
}
l2.setText("Current Balance: " + getBank());
l4.setText("Current cash: " + getMoney());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
}
}
}
);
/**
* Adds function to button 2 which, when clicked, deposits money into your bank but, will not let you overdraw.
*
*/
// Set the event handler when the withdraw button is clicked
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
int deposit = Integer.parseInt(txtField1.getText());
if(deposit < 0){
l5.setText("Nice Try!!! No negative Numbers Please");
}
else if (deposit <= getMoney()) {
setBank(deposit + getBank());
setMoney(getMoney() - deposit);
} else {
l5.setText("Sorry you cannot deposit that much.$");
}
l2.setText("Current Balance: " + getBank());
l4.setText("Current cash: " + getMoney());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
}
}
}
);
/**
* Adds function to button 3 which, when clicked, brings you back to the Shop GUI.
*
*/
b3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
}
);
/**
* Sets the window size to a width of 600 and height of 480 and displays the screen.
*
*/
Scene scene = new Scene(brdr1, 600, 480);
scene.getStylesheets().add("styleguide.css");
primaryStage.setScene(scene);
return primaryStage;
}
/**
* sets scene and runs stage
*
* @param primaryStage the stage in which the scene may be run and switched to
*/
public void start(Stage primaryStage) {
BankGUI bank = new BankGUI(getPlayer());
bank.initializeBank(primaryStage);
primaryStage.show();
}
}

47
src/FileSaving.java Normal file
View File

@@ -0,0 +1,47 @@
import java.io.*;
/**
* 2019-03-10 (Edited on 2019-03-19)
* Authors:
* FileSaving Class allows the user to save the current status of the game and to continue from where they left off.
*/
public class FileSaving extends Player implements Serializable {
/**
*loads the file of type player which contains all the player instances
* @return player
*/
public Player loadFile() {
try {
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
ObjectInputStream inObject = new ObjectInputStream(in);
Player player = (Player) inObject.readObject();
in.close();
inObject.close();
return player;
}
catch (Exception e) {
return null;
}
}
public boolean saveFile(Player player){
try{
FileOutputStream out = new FileOutputStream(new File("src/saves/playerSave.txt"));
ObjectOutputStream outObject = new ObjectOutputStream(out);
outObject.writeObject(player);
out.close();
outObject.close();
//returns true if program can save file
return true;
}
catch (Exception e) {
return false;
}
}
}

120
src/GameEndGUI.java Normal file
View File

@@ -0,0 +1,120 @@
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
/**
* 2019-03-10
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
* GameEndGUI class, Initializes and displays the graphical interface for when you lose
*
*/
public class GameEndGUI extends Player{
private Label title;
private VBox vBox;
private Label firmName;
private Label gunsHeld;
private Label netWorth;
private BorderPane borderPane;
public GameEndGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* Sets up the graphical part of GameEndGUI and includes all logic for the class
*
* @param stage sets the stage to which we will execute the scene of the GameEndGUI class
* @return stage so that another class can switch to the stage
*/
public Stage initializeGameEndGUI(Stage stage) {
//Creating all the nodes
title = new Label();
vBox = new VBox();
firmName = new Label();
gunsHeld = new Label();
netWorth = new Label();
borderPane = new BorderPane();
int netWorthInt = 0;
borderPane.setPrefHeight(480.0);
borderPane.setPrefWidth(600.0);
//Setting positions and names of all the nodes
BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
title.setText("Game Over!");
title.setFont(new Font(43.0));
BorderPane.setMargin(title, new Insets(0.0));
title.setPadding(new Insets(50.0, 0.0, 0.0, 0.0));
borderPane.setTop(title);
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
vBox.setAlignment(javafx.geometry.Pos.CENTER);
vBox.setPrefHeight(200.0);
vBox.setPrefWidth(100.0);
firmName.setText("Name:");
firmName.setFont(new Font(22.0));
gunsHeld.setText("Guns Held:");
gunsHeld.setFont(new Font(22.0));
netWorth.setText("Net Worth:");
netWorth.setFont(new Font(22.0));
borderPane.setCenter(vBox);
//Adding the labels to the character's stats to the VBox which will show up on the screen
vBox.getChildren().add(firmName);
vBox.getChildren().add(gunsHeld);
vBox.getChildren().add(netWorth);
/**
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
* */
if (getHP() <= 0) {
title.setText("Game Over!");
} else {
title.setText("Congratulations!");
}
/**
* Calculates the networth of the player by the end of the game
* */
netWorthInt = getMoney() + (getOpiumHeld() * 16000) + (getSilkHeld() * 160) + (getArmsHeld() * 160) + (getGeneralHeld() * 8);
netWorthInt += (getwOpium() * 16000) + (getwSilk() * 160) + (getwArms() * 160) + (getwGeneral() * 8);
netWorthInt -= getDebt();
//Updating the endgame stats of the player
firmName.setText("Firm Name: " + getName());
gunsHeld.setText("Guns Held: " + getGuns());
netWorth.setText("Net Worth: " + netWorthInt);
Scene root = new Scene(borderPane, 600, 480);
root.getStylesheets().add("styleguide.css");
stage.setTitle("End Game Stats");
stage.setResizable(false);
stage.setScene(root);
return stage;
}
/**
* sets scene and runs stage
*
* @param primaryStage the stage in which the scene may be run and switched to
*/
public void start(Stage primaryStage) {
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(primaryStage);
primaryStage.show();
}
}

181
src/LoanSharkGUI.java Normal file
View File

@@ -0,0 +1,181 @@
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
* 2019-03-10
* Authors: Siddhant Dewani
* LoanShark GUI Class allows the user to get a loan from the loan shark
*/
public class LoanSharkGUI extends Player {
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public LoanSharkGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* This methods purpose is to loan the player the funds it wants
* or pay its outstanding debts. The method prompts the user if they
* would like to borrow money or repay. depending on what the player chooses
* the corresponding loop is evoked. The player can only be loaned 2 times the
* money they have minus the debt if their debt exceeds the cash balance, the loan
* cannot be given.
*
* @param primaryStage the stage upon which the GUI will be imposed
*/
public Stage initializeLoanShark(Stage primaryStage) {
primaryStage.setTitle("Loan Shark");
//Declaring each Layout
BorderPane brdr1 = new BorderPane();
HBox hbx1 = new HBox(10);
HBox hbx2 = new HBox(10);
VBox vbx1 = new VBox(10);
//Declaring all Variables
Label l1 = new Label("Player: " + getName());
Label l2 = new Label("Current Debt " + getDebt());
Label l4 = new Label("Current cash: " + getMoney());
Label l3 = new Label("Enter Amount: ");
Label l5 = new Label(" ");
//Declaring All Buttons
Button b1 = new Button("Borrow");
Button b2 = new Button("Repay");
Button b3 = new Button("Go back");
//Declaring All TextFields
TextField txtField1 = new TextField();
//Creating the buttons at the bottom of the screen
hbx1.setAlignment(Pos.CENTER);
hbx1.getChildren().add(b1);
hbx1.getChildren().add(b2);
hbx1.getChildren().add(b3);
hbx1.setPadding(new Insets(0,0,20,0));
brdr1.setBottom(hbx1);
//Creating the TextField at the center of the screen
hbx2.setAlignment(Pos.CENTER);
hbx2.getChildren().add(l3);
hbx2.getChildren().add(txtField1);
brdr1.setCenter(hbx2);
//Creating the Labels at the top of the Screen
vbx1.setAlignment(Pos.CENTER);
vbx1.getChildren().add(l1);
vbx1.getChildren().add(l2);
vbx1.getChildren().add(l4);
vbx1.getChildren().add(l5);
vbx1.setPadding(new Insets(20,0,0,0));
brdr1.setTop(vbx1);
// Set the event handler when the deposit button is clicked
b1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
int loanAsk = Integer.parseInt(txtField1.getText());
if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) {
setDebt(getDebt() + loanAsk);
setMoney(getMoney() + loanAsk);
l4.setText("Current cash: " + getMoney());
} else if (loanAsk < 0) {
l5.setText("Sorry you cannot enter negative numbers");
}
else{
l5.setText("Sorry you cannot get the loan requested");
}
l2.setText("Debt: " + getDebt());
} catch (Exception e) {
l5.setText("Please enter a valid value");
}
}
}
);
// Set the event handler when the withdraw button is clicked
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
int returnAsk = Integer.parseInt(txtField1.getText());
if (returnAsk > getDebt()) {
l5.setText("You dont need to return that much");
}
else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) {
setDebt(getDebt() - returnAsk);
setMoney(getMoney() - returnAsk);
l4.setText("Current cash: " + getMoney());
}
else if(getMoney() < returnAsk) {
l5.setText("Look " + getName() + ", you are being cheap!");
}
else {
l5.setText("Sorry you cannot return a negative amount");
}
l2.setText("Debt: " + getDebt());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
}
}
}
);
b3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
}
);
//Setting the Scene and displaying it
Scene scene = new Scene(brdr1, 600, 480);
scene.getStylesheets().add("styleguide.css");
primaryStage.setScene(scene);
//primaryStage.show();
return primaryStage;
}
public void start(Stage primaryStage) {
LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
loan.initializeLoanShark(primaryStage);
primaryStage.show();
}
}

28
src/MainGUI.java Normal file
View File

@@ -0,0 +1,28 @@
import javafx.application.Application;
import javafx.stage.Stage;
/**
* 2019-03-10
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
* MainGUI class, Initializes the entire game and runs the game for user to play
*
*/
public class MainGUI extends Application {
/**
* Updates main class with player data and starts the game.
* The game will only run as long as the player has not retired or has been destroyed.
*
* @param args Just the console for the player to look at.
*/
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) throws Exception {
StartGUI start = new StartGUI(new Player());
start.initializeStart(primaryStage);
primaryStage.show();
}
}

View File

@@ -1,6 +1,13 @@
import java.util.Scanner;
import java.io.Serializable;
public class Player {
/**
* 2019-03-10
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
* Player class, stores all the information about the player such as inventory, health, etc
*
*/
public class Player implements Serializable {
private String name = "Taipan";
private int bank = 0;
@@ -10,7 +17,7 @@ public class Player {
private int generalHeld = 0;
private int armsHeld = 0;
private int location = 1;
private int guns = 0;
private int guns = 5;
private int HP = 100;
private int debt = 0;
private int wOpium = 0;
@@ -19,9 +26,17 @@ public class Player {
private int wArms = 0;
private boolean retire = false;
private int cargoSpace = 60;
private int opiumPrice = 16000;
private int silkPrice = 1600;
private int armsPrice = 160;
private int generalPrice = 8;
private int isPriceChanged = 0;
private boolean attackingShips = true;
/**
* default constructor for player
*/
public Player(){
}
/**
@@ -30,6 +45,25 @@ public class Player {
* @param player object of the class Player
*/
public Player(Player player) {
setPlayer(player);
}
/**
* getter for this player object
*
* @return a copy of this player object
*/
public Player getPlayer(){
return new Player(this);
}
/**
* copies the provided player's properties into the instance variable of this object
*
* @param player
*/
public void setPlayer(Player player){
this.name = player.name;
this.bank = player.bank;
this.money = player.money;
this.opiumHeld = player.opiumHeld;
@@ -44,6 +78,14 @@ public class Player {
this.wSilk = player.wSilk;
this.wGeneral = player.wGeneral;
this.wArms = player.wArms;
this.retire = player.retire;
this.cargoSpace = player.cargoSpace;
this.opiumPrice = player.opiumPrice;
this.silkPrice = player.silkPrice;
this.armsPrice = player.armsPrice;
this.generalPrice = player.generalPrice;
this.isPriceChanged = player.isPriceChanged;
this.attackingShips = player.attackingShips;
}
/**
@@ -61,13 +103,30 @@ public class Player {
*
* @param cargoSpace takes an int that is greater than 0 as an argument
*/
public void setCargoSpace(int cargoSpace) {
if (cargoSpace > 0) {
this.cargoSpace = cargoSpace;
}
}
/**
* getter method for the instance variable attackingShips.
*
* @return returns the instance variable attackingShips
*/
public boolean getAttackingShips() {
return attackingShips;
}
/**
* setter method for the instance variable attackingShips.
*
* @param attackingShips takes an int that is greater than 0 as an argument
*/
public void setAttackingShips(boolean attackingShips) {
this.attackingShips = attackingShips;
}
/**
* getter method for the instance variable retire.
*
@@ -418,10 +477,109 @@ public class Player {
}
}
/**
* getter for opiumPrice instance variable.
*
* @return opiumPrice -- the price of opium in the shop
*/
public int getOpiumPrice() {
return opiumPrice;
}
/**
* setter for the opiumPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param opiumPrice -- what the instance variable opiumPrice should be changed to.
*/
public void setOpiumPrice(int opiumPrice) {
if (opiumPrice > 0) {
this.opiumPrice = opiumPrice;
}
}
/**
* getter for silkPrice instance variable.
*
* @return silkPrice -- the price of silk in the shop.
*/
public int getSilkPrice() {
return silkPrice;
}
/**
* setter for the silkPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param silkPrice -- what the instance variable silkPrice should be changed to.
*/
public void setSilkPrice(int silkPrice) {
if (silkPrice > 0) {
this.silkPrice = silkPrice;
}
}
/**
* getter for armsPrice instance variable.
*
* @return armsPrice -- the price of arms in the shop.
*/
public int getArmsPrice() {
return armsPrice;
}
/**
* setter for the armsPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param armsPrice -- what the instance variable armsPrice should be changed to.
*/
public void setArmsPrice(int armsPrice) {
if (armsPrice > 0) {
this.armsPrice = armsPrice;
}
}
/**
* getter for generalPrice instance variable.
*
* @return generalPrice -- the price of general cargo in the shop.
*/
public int getGeneralPrice() {
return generalPrice;
}
/**
* setter for the generalPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param generalPrice -- what the instance variable generalPrice should be changed to.
*/
public void setGeneralPrice(int generalPrice) {
if (generalPrice > 0) {
this.generalPrice = generalPrice;
}
}
/**
* getter for isPriceChanged instance variable.
*
* @return isPriceChanged -- Checks if the price has changed since last in shop.
*/
public int getIsPriceChanged() {
return isPriceChanged;
}
/**
* setter for the isPriceChanged instance variable. Runs as long as the parameter is greater than 0.
*
* @param isPriceChanged -- what the instance variable isPriceChanged should be changed to.
*/
public void setIsPriceChanged(int isPriceChanged) {
if(isPriceChanged >= 0) {
this.isPriceChanged = isPriceChanged;
}
}
/**
* Method to indicate that you have lost the game. If the player has lost, console will be cleared and will only
* show the statement "Game Over". After showing the message the game closes.
*
**/
public void gameOver() {

229
src/RandomEventGUI.java Normal file
View File

@@ -0,0 +1,229 @@
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.Random;
/**
* 2019-03-19
* Authors: Harkamal Randhawa
* Random Event GUI class generates random events that occur during travel, such as fixing your ship,
* liu yen asking for money and to purchase a gun.
*/
public class RandomEventGUI extends Player{
private HBox hBox;
private Button yesButton;
private Button noButton;
private VBox vBox;
private Label paymentLabel;
private Label sellingItemLabel;
private Label cannotAffordLabel;
private VBox vBox0;
private Label shipHPLabel;
private Label gunsShipLabel;
private Label moneyPlayerLabel;
private Label moneyBankLabel;
private Label cargoShipLabel;
private Label cargoWarehouseLabel;
private BorderPane borderPane;
private int eventNumber = 0;
private int itemPrice = 10;
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public RandomEventGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* Initializes randomEvent on the given stage as a parameter.
*
* @param stage
*/
public Stage initializeRandomEventGUI(Stage stage) {
//Creating the nodes within the event screen
hBox = new HBox();
yesButton = new Button();
noButton = new Button();
vBox = new VBox();
paymentLabel = new Label();
sellingItemLabel = new Label();
cannotAffordLabel = new Label();
vBox0 = new VBox();
shipHPLabel = new Label();
gunsShipLabel = new Label();
moneyPlayerLabel = new Label();
moneyBankLabel = new Label();
cargoShipLabel = new Label();
borderPane = new BorderPane();
//Messing with the alignments of the buttons and their text
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
hBox.setSpacing(10.0);
yesButton.setMnemonicParsing(false);
yesButton.setText("Yes");
yesButton.setDefaultButton(true);
noButton.setMnemonicParsing(false);
noButton.setText("No");
borderPane.setBottom(hBox);
//Making the vbox to put all Labels for the events
borderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
vBox.setAlignment(javafx.geometry.Pos.CENTER);
vBox.setPrefHeight(200.0);
vBox.setPrefWidth(100.0);
paymentLabel.setText("Would you like to pay?");
sellingItemLabel.setText("for a Gun?");
cannotAffordLabel.setText("You can't afford that!");
cannotAffordLabel.setFocusTraversable(false);
borderPane.setCenter(vBox);
borderPane.setAlignment(vBox0, javafx.geometry.Pos.CENTER);
vBox0.setAlignment(javafx.geometry.Pos.CENTER);
vBox0.setPrefHeight(200.0);
vBox0.setPrefWidth(100.0);
//Update the labels to fit the player's stats
shipHPLabel.setText("Ship Health: " + getPlayer().getHP());
gunsShipLabel.setText("Number of Guns Remaining: " + getPlayer().getGuns());
moneyPlayerLabel.setText("Money on Player: " + getPlayer().getMoney());
moneyBankLabel.setText("Money in Bank: " + getPlayer().getBank());
cargoShipLabel.setText("Ship Cargo Space: " + getPlayer().getCargoSpace());
//Adding all the buttons and labels to the elements in the scene
hBox.getChildren().add(yesButton);
hBox.getChildren().add(noButton);
vBox.getChildren().add(sellingItemLabel);
vBox.getChildren().add(paymentLabel);
vBox.getChildren().add(cannotAffordLabel);
vBox0.getChildren().add(shipHPLabel);
vBox0.getChildren().add(gunsShipLabel);
vBox0.getChildren().add(moneyPlayerLabel);
vBox0.getChildren().add(moneyBankLabel);
vBox0.getChildren().add(cargoShipLabel);
//Adding all the elements to the scene
borderPane.setTop(vBox0);
borderPane.setTop(vBox0);
borderPane.setCenter(vBox);
borderPane.setBottom(hBox);
//Make it so that the player can't see the can't afford label until after they actually can't understand
cannotAffordLabel.setVisible(false);
/*Pick a random number dictating the events that could happen.
* 1: New gun for player
* 2: Paying Liu Yuen
* 3: Repairing the Ship
*/
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
while(true){
//Buy Guns
if (randGenNum == 1) {
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?");
break;
}
//Liu Yuen
if (randGenNum == 2) {
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
setAttackingShips(true);
break;
}
//Ship Repair
if (randGenNum == 3 && getHP() < 101) {
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived, would be willing to repair your ship for $" + itemPrice);
break;
}
else {
randGenNum = 2;
}
}
eventNumber = randGenNum;
if((eventNumber == 1 && getCargoSpace() < 10)){
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
}
if((eventNumber == 3 && getPlayer().getHP() >= 100)){
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
}
//if yes button is clicked, executes the code depending on the type of event
yesButton.setOnAction(event -> {
if(getPlayer().getMoney() > itemPrice) {
//Buy Guns
if (eventNumber == 1 && (getCargoSpace() >= 10)) {
setGuns(getPlayer().getGuns() + 1);
setMoney(getPlayer().getMoney() - itemPrice);
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
}
//Liu Yuen
if (eventNumber == 2) {
setAttackingShips(false);
setMoney(getPlayer().getMoney() - itemPrice);
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
}
//Ship Repair
if (eventNumber == 3 && getPlayer().getHP() != 100) {
setHP(100);
setMoney(getPlayer().getMoney() - itemPrice);
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
}
}
else{
cannotAffordLabel.setVisible(true);
yesButton.setVisible(false);
noButton.setDefaultButton(true);
noButton.setVisible(true);
}
});
//If the no button is clicked then it skips to the location screen you wanted to go to.
noButton.setOnAction(event -> {
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
});
//Creates the scene and window
Scene root = new Scene(borderPane, 600, 480);
root.getStylesheets().add("styleguide.css");
stage.setTitle("Travel");
stage.setResizable(false);
stage.setScene(root);
return stage;
}
}

View File

@@ -1,466 +0,0 @@
import java.util.Scanner;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public class ShipWarfare {
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 Player player;
/**
* Class Constructor that takes in a type player as a parameter
* @param player object of the class 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;
}
/**
* 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;
}
} else if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away!");
if (destroyPeasantShipsOrEscape())
break;
} else {
System.out.println("Phew! Got away safely");
delayForSeconds(2);
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!");
delayForSeconds(1);
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;
}
/**
* 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 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();
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 delay
*/
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
while (exitValue == 0) {
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", player.getName());
delayForSeconds(1);
} else {
System.out.println("Darn! Their fleet tanked our attack");
delayForSeconds(1);
}
} else {
continue;
}
}
} else {
System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName());
delayForSeconds(1);
}
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;
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;
}
System.out.println("Got eem");
delayForSeconds(1);
} else {
System.out.printf("ARRG! We missed %s\n", player.getName());
delayForSeconds(1);
}
} else {
continue;
}
}
}
else{
System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName());
delayForSeconds(1);
}
if (numOfPeasantShips <= 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) {
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);
}
}
}
}
System.out.printf("%d ships remaining\n", numOfPeasantShips);
delayForSeconds(1);
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(10)));
}
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");
} else {
exitValue = 3;
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(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();
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;
}
}

668
src/ShipWarfareGUI.java Normal file
View File

@@ -0,0 +1,668 @@
import javafx.animation.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.io.FileInputStream;
import java.util.Random;
/**
* 2019-03-10 (Edited on 2019-03-23)
* Author: Haris Muhammad
* ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from
*/
public class ShipWarfareGUI extends Player {
private ShipWarfareGUI ship;
private Circle cannon;
private VBox buttonBox;
private HBox fightRunBox;
private Button fightButton;
private Button runButton;
private Button continueButton;
private VBox labelBox;
private Label title;
private Label HPLeft;
private Label gunsLeftOrTaken;
private Label runAwayOrLeft;
private Label shipsRemaining;
private Label report;
private boolean winOrLose= false;
private int counter1;
private int timeCounter;
private int numOfLittyShips = 0;
private boolean userAttacks = true;
private int startingLittyShips = 0;
private int howMuchRun = 0;
private int counter = 0;
private String pirateName = "Liu Yen";
private int beginningX = 150;
private int beginningY = 245;
private int endX = 350;
private int endY = 90;
private TranslateTransition shotsFired = new TranslateTransition();
private TranslateTransition enemyShots = new TranslateTransition();
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public ShipWarfareGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* 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();
if (getMoney() <= 100000) {
//Minimum one ship will attack, maximum 20
numOfShipsAttacking = randomValue.nextInt(20) + 1;
} else if (getMoney() <= 200000) {
//Minimum 30 Ships will attack, maximum 70
numOfShipsAttacking = randomValue.nextInt(40) + 31;
} else if (getMoney() <= 500000) {
//Minimum 50 ships will attack, maximum 140
numOfShipsAttacking = randomValue.nextInt(90) + 51;
} else if (getMoney() >= 1000000) {
//Minimum 100 ships will attack, maximum 300 ships
numOfShipsAttacking = randomValue.nextInt(200) + 101;
}
return numOfShipsAttacking;
}
/**
* setter method that takes in an integer as an argument
*
* @param numOfLittyShips the number of ships to be used in the peasant fleet attack
*/
public void setNumOfLittyShips(int numOfLittyShips) {
counter1++;
this.numOfLittyShips = numOfLittyShips;
if (counter1 == 1) {
startingLittyShips = numOfLittyShips;
}
}
/**
* 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(10) + 1;
if (runSuccessChance == 2) {
return true;
} else if (runSuccessChance == 1) {
return false;
}
return false;
}
/**
* Sets most of the labels invisible except for the "fight or run" label
*/
public void wipe() {
title.setVisible(false);
runAwayOrLeft.setVisible(false);
shipsRemaining.setVisible(false);
HPLeft.setVisible(false);
gunsLeftOrTaken.setVisible(false);
}
/**
* Sets most of the labels invisible including the fight or run label
*/
public void completeWipe() {
title.setVisible(false);
runAwayOrLeft.setVisible(false);
shipsRemaining.setVisible(false);
HPLeft.setVisible(false);
gunsLeftOrTaken.setVisible(false);
report.setVisible(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
*/
public boolean destroyLittyShipsOrEscape(Stage stage) throws Exception {
cannon.setLayoutX(beginningX);
cannon.setLayoutY(beginningY);
int calculateLoot = 0;
int chanceOfEnemyRun = 0;
int hitCounter = 0;
int missCounter = 0;
boolean gunFrustration = false;
Random randomValue = new Random();
int exitValue = 0;
//Player volley
//while (exitValue == 0) {
if (getGuns() > 0) {
for (int j = 0; j < getGuns(); j++) {
if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(2) + 1;
if (hitOrMiss == 2) {
numOfLittyShips--;
if (numOfLittyShips <= 0) {
exitValue = 1;
//break;
}
hitCounter++;
} else {
missCounter++;
}
} else {
//continue;
}
}
if (userAttacks == true) {
report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
}
} else {
report.setText("We don't have any guns!!!");
}
if (numOfLittyShips <= 0) {
exitValue = 1;
//break;
}
if (getGuns() > 0) {
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) {
howMuchRun = randomValue.nextInt(15) + 1;
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
setNumOfLittyShips(numOfLittyShips - howMuchRun);
if (userAttacks == true) {
if (howMuchRun > 0) {
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, getName()));
//runAwayOrLeft.setVisible(true);
}
} else {
report.setText((String.format("Escaped %d of them %s!", howMuchRun, getName())));
}
}
}
}
shipsRemaining.setText(String.format("%d ships remaining and they look angry!", numOfLittyShips));
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && getGuns() > 0) {
setGuns(getGuns() - 1);
gunFrustration = true;
} else {
if (numOfLittyShips > 0) {
int HPTaken = randomValue.nextInt(10);
setHP(getHP() - (HPTaken));
}
}
if (getHP() <= 0) {
exitValue = 2;
//break;
}
if (gunFrustration == true) {
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", getGuns()));
} else {
gunsLeftOrTaken.setText(String.format("We still have %d guns left", getGuns()));
}
HPLeft.setText(String.format("EEK, our current ship status is %d%% ", getHP()));
if (userAttacks == false) {
userAttacks = true;
}
if (exitValue == 1) {
wipe();
calculateLoot = (startingLittyShips * 100) + randomValue.nextInt(startingLittyShips) * 200;
setMoney(getMoney() + calculateLoot);
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
continueButton.setVisible(true);
completeWipe();
fightButton.setVisible(false);
runButton.setVisible(false);
continueButton.setDefaultButton(true);
return true;
} else if (exitValue == 2) {
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(stage);
stage.show();
return true;
} else if (exitValue == 3) {
report.setText(String.format("We made it out at %d%% ship status!", getHP()));
continueButton.setVisible(true);
completeWipe();
fightButton.setVisible(false);
runButton.setVisible(false);
continueButton.setDefaultButton(true);
return true;
}
return false;
}
/**
* Player attacks enemy ships in an animation
*/
public void playerShoots() {
userAttacks=true;
shotsFired.setFromX(0);
shotsFired.setFromY(0);
shotsFired.setToX(endX);
shotsFired.setToY(endY);
shotsFired.setDuration(Duration.seconds(1));
if(getGuns()>0) {
shotsFired.setCycleCount(getGuns());
}
else{
shotsFired.setCycleCount(0);
shotsFired.stop();
cannon.setVisible(false);
}
shotsFired.setNode(cannon);
shotsFired.play();
}
/**
* Ships attack player ship back in an animation
*/
public void shipsRetaliate(){
cannon.setVisible(true);
enemyShots.setFromX(270);
enemyShots.setFromY(0);
enemyShots.setToX(-30);
enemyShots.setToY(90);
enemyShots.setDuration(Duration.seconds(1));
enemyShots.setCycleCount(1);
enemyShots.setNode(cannon);
enemyShots.play();
}
/**
* Sets most buttons to being invisble and switches to TaipanShop scene
*
* @param stage stage the user incorporates when they utilize the GUI
*/
public void setVisibilitiesAndTransition(Stage stage) {
completeWipe();
continueButton.setVisible(true);
continueButton.setDefaultButton(true);
fightButton.setVisible(false);
runButton.setVisible(false);
/**
* Switches to Taipan Shop scene
* @param event, once button is clicked, executes graphical information
*/
continueButton.setOnAction(event -> {
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
});
}
/**
* Generaties ships and deploys logic for the shipwarfare
* @param primaryStage sets up the stage to whcih the GUI may be based around
* @throws Exception in case of interruptions withing the graphical interface
*/
public void initializeShip(Stage primaryStage) throws Exception {
setNumOfLittyShips(numOfShips());
Pane root = new Pane();
HBox usAgainstEnemyDivisor;
BorderPane centeringUserShipPane = new BorderPane();
Circle cannon;
BorderPane centeringLittyShipPane = new BorderPane();
BorderPane encompassingPane = new BorderPane();
usAgainstEnemyDivisor = new HBox();
cannon = new Circle();
this.cannon = cannon;
cannon.setVisible(false);
buttonBox = new VBox();
fightRunBox = new HBox();
fightButton = new Button();
runButton = new Button();
continueButton = new Button();
labelBox = new VBox();
title = new Label();
HPLeft = new Label();
gunsLeftOrTaken = new Label();
runAwayOrLeft = new Label();
shipsRemaining = new Label();
report = new Label();
title.setText(String.format("%d ships from Liu Yuen's Fleet are attacking, Would you like to fight or run?", numOfLittyShips));
fightButton.setText("Fight");
runButton.setText("Run");
continueButton.setText("Continue");
fightButton.setVisible(true);
runButton.setVisible(true);
continueButton.setVisible(false);
encompassingPane.setAlignment(labelBox, javafx.geometry.Pos.CENTER);
labelBox.setAlignment(javafx.geometry.Pos.CENTER);
labelBox.setPrefHeight(41.0);
labelBox.setPrefWidth(600.0);
labelBox.setSpacing(20.0);
labelBox.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
encompassingPane.setAlignment(buttonBox, javafx.geometry.Pos.CENTER);
buttonBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
fightRunBox.setAlignment(javafx.geometry.Pos.CENTER);
fightRunBox.setPrefHeight(100.0);
fightRunBox.setPrefWidth(200.0);
fightRunBox.setSpacing(10.0);
VBox.setMargin(continueButton, new Insets(0.0, 0.0, 20.0, 0.0));
root.getChildren().add(cannon);
encompassingPane.setPrefHeight(480);
encompassingPane.setPrefWidth(600);
usAgainstEnemyDivisor.setPrefHeight(0.0);
usAgainstEnemyDivisor.setPrefWidth(600.0);
centeringUserShipPane.setPrefHeight(200.0);
centeringUserShipPane.setPrefWidth(200.0);
Image ourShip = new Image(new FileInputStream("src/images/ourShip.png"));
Image enemyShip = new Image(new FileInputStream("src/images/enemyShip.png"));
//Setting the image view
ImageView userShip = new ImageView(ourShip);
ImageView littyShip = new ImageView(enemyShip);
BorderPane.setAlignment(userShip, javafx.geometry.Pos.CENTER);
userShip.setFitHeight(150.0);
userShip.setFitWidth(248.0);
userShip.setPickOnBounds(true);
userShip.setPreserveRatio(true);
centeringUserShipPane.setCenter(userShip);
BorderPane.setAlignment(buttonBox, javafx.geometry.Pos.CENTER);
buttonBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
usAgainstEnemyDivisor.setTranslateY(-20.0);
cannon.setRadius(10.0);
cannon.setStroke(javafx.scene.paint.Color.BLACK);
cannon.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
centeringUserShipPane.setRight(cannon);
centeringLittyShipPane.setPrefHeight(200.0);
centeringLittyShipPane.setPrefWidth(200.0);
centeringLittyShipPane.setOpaqueInsets(new Insets(0.0));
HBox.setMargin(centeringLittyShipPane, new Insets(0.0, 0.0, 0.0, 200.0));
encompassingPane.setAlignment(littyShip, javafx.geometry.Pos.CENTER);
littyShip.setFitHeight(165.0);
littyShip.setFitWidth(180.0);
littyShip.setPickOnBounds(true);
littyShip.setPreserveRatio(true);
encompassingPane.setMargin(littyShip, new Insets(0.0, 0.0, 20.0, 0.0));
centeringLittyShipPane.setCenter(littyShip);
usAgainstEnemyDivisor.getChildren().add(centeringUserShipPane);
usAgainstEnemyDivisor.getChildren().add(centeringLittyShipPane);
fightRunBox.getChildren().add(fightButton);
fightRunBox.getChildren().add(continueButton);
fightRunBox.getChildren().add(runButton);
buttonBox.getChildren().add(fightRunBox);
labelBox.getChildren().add(title);
labelBox.getChildren().add(HPLeft);
labelBox.getChildren().add(gunsLeftOrTaken);
labelBox.getChildren().add(runAwayOrLeft);
labelBox.getChildren().add(shipsRemaining);
labelBox.getChildren().add(report);
encompassingPane.setTop(labelBox);
encompassingPane.setCenter(usAgainstEnemyDivisor);
encompassingPane.setBottom(buttonBox);
root.getChildren().addAll(encompassingPane, cannon);
Scene scene = new Scene(root, 600, 480);
root.getStylesheets().add("styleguide.css");
primaryStage.setResizable(false);
primaryStage.setScene(scene);
primaryStage.show();
continueButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
/**
* Continue Button, engages in run logic and graphical interface
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
shotsFired.stop();
/**
* Switches to Taipan Shop scene
*/
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(primaryStage);
primaryStage.show();
}
});
//Flee
runButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
/**
* Run Button, engages in run logic and graphical interface
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
report.setVisible(true);
title.setVisible(true);
shipsRemaining.setVisible(true);
gunsLeftOrTaken.setVisible(true);
title.setText("Ayy captain we will try to run!");
report.setText("Epic");
counter++;
if (runFromShips() == false) {
report.setText(("Couldn't run away"));
try {
winOrLose= destroyLittyShipsOrEscape(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
if(winOrLose==true){
report.setVisible(true);
title.setVisible(true);
shipsRemaining.setVisible(true);
gunsLeftOrTaken.setVisible(true);
}
} else {
report.setText("Phew! Got away safely");
setVisibilitiesAndTransition(primaryStage);
}
}
});
//Fight
fightButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
/**
* Fight Button, engages in fight logic and graphical interface
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
report.setVisible(false);
runAwayOrLeft.setVisible(false);
shipsRemaining.setVisible(false);
HPLeft.setVisible(false);
gunsLeftOrTaken.setVisible(false);
fightButton.setVisible(false);
runButton.setVisible(false);
try {
winOrLose= destroyLittyShipsOrEscape(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
counter++;
cannon.setVisible(true);
cannon.setLayoutX(beginningX);
cannon.setLayoutY(beginningY);
if (counter >= 1) {
title.setVisible(false);
}
playerShoots();
shotsFired.setOnFinished(new EventHandler<ActionEvent>() {
@Override
/**
* When the user is completed their volley this information will be accessed
* @param event, once the shots fired transition is completed, execute graphical information
*/
public void handle(ActionEvent event) {
shotsFired.stop();
if(!winOrLose) {
shipsRetaliate();
}
else{
report.setVisible(true);
continueButton.setVisible(true);
usAgainstEnemyDivisor.setVisible(false);
cannon.setVisible(false);
shotsFired.stop();
}
enemyShots.setOnFinished(new EventHandler<ActionEvent>() {
@Override
/**
* When the user is completed their volley, this information will be accessed
* @param event, once the enemy shots transition is completed, execute graphical information
*/
public void handle(ActionEvent event) {
fightButton.setVisible(true);
runButton.setVisible(true);
report.setVisible(true);
cannon.setVisible(false);
runAwayOrLeft.setVisible(true);
gunsLeftOrTaken.setVisible(true);
shipsRemaining.setVisible(true);
HPLeft.setVisible(true);
gunsLeftOrTaken.setVisible(true);
if(winOrLose==true){
usAgainstEnemyDivisor.setVisible(false);
}
}
});
}
});
}
});
}
}

View File

@@ -1,79 +0,0 @@
import java.util.Scanner;
public class Start
{
private Player player;
/**
* gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
*
* @return playerDummy -- playerDummy is a copy of the player instance variable.
*/
public Player getPlayer() {
Player playerTemp = new Player(player);
return playerTemp;
}
/**
* sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
*
* @param player is a Player object that will replace the current instance of the player instance variable.
*/
public void setPlayer(Player player) {
Player playerTemp = new Player(player);
this.player = playerTemp;
}
/**
* Asks the user to input the name that they would like to be called in the game
*
* @param name the name that you would like to be called in the game
*/
public void setFirm (String name) {
if (name.length() <= 22) {
player.setName(name);
}
}
/**
* Initializes the game by asking for your name and if you would like to start with either: 1) money and a debt or
* 2) guns and no cash/debt.
*/
public void initialize()
{
Scanner userInput = new Scanner(System.in);
System.out.println("Taipan, \nWhat will you name your firm:");
setFirm(userInput.nextLine());
System.out.println("Do you want to start . . .\n\t1) With cash (and a debt)\n\t\t\t>> or <<\n\t" +
"2) With five guns and no cash (But no debt!)?\n ");
int input = userInput.nextInt();
if (input == 1)
{
player.setMoney(400);
player.setDebt(5000);
}
if (input == 2)
{
player.setGuns(5);
}
// purely for testing purposes.
if(player.getName().equalsIgnoreCase("Vikram")){
player.setMoney(999999999);
player.setBank(999999999);
player.setGuns(999);
player.setHP(99999999);
player.setCargoSpace(99999999);
}
}
/**
* Copy constructor.
* @param player object of the class Player
*/
public Start(Player player)
{
Player playerTemp = new Player(player);
this.player = playerTemp;
}
}

243
src/StartGUI.java Normal file
View File

@@ -0,0 +1,243 @@
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
/**
* 2019-03-10
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
* StartGUI class, Initializes and displays the start menu for Taipan
*
*/
public class StartGUI extends Player{
private BorderPane borderPane = new BorderPane();
private HBox hBox = new HBox();
private TextField nameField = new TextField();
private Button startButton = new Button();
private Button continueButton = new Button();
private VBox vBox = new VBox();
private Label choiceLabel = new Label();
private RadioButton gunChoice = new RadioButton();
private ToggleGroup Start = new ToggleGroup();
private RadioButton cashChoice = new RadioButton();
private VBox vBox0 = new VBox();
private Label title = new Label();
private Label authors = new Label();
/**
* Copy constructor.
* @param player object of the class Player
*/
public StartGUI(Player player) {
Player playerTemp = new Player(player);
setPlayer(playerTemp);
}
/**
* Asks the user to input the name that they would like to be called in the game
*
* @param name the name that you would like to be called in the game
*/
public void setFirm(String name) {
if (name.length() <= 22) {
super.setName(name);
} else {
super.setName("Taipan");
}
}
/**
* Initializes the Start GUI the game.
*
* @param stage object of type Stage
* @return returns the stage of GUI
*/
public Stage initializeStart(Stage stage) {
/**
* Creates an HBox at the center of the borderpane with a width of 200, height of 100 and spacing of 10.
*
*/
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
hBox.setSpacing(10.0);
/**
* Creates a borderpane window of width 600 and height 480.
*
*/
borderPane.setPrefHeight(480.0);
borderPane.setPrefWidth(600.0);
/**
* Creates a prompt text field that asks for your firm name and has a default text set to "Taipan".
*
*/
nameField.setPromptText("Enter Firm Name.");
nameField.setText("Taipan");
/**
* Creates a button with text "Start"
*
*/
startButton.setMnemonicParsing(false);
startButton.setText("New");
/**
* Creates a button with text "Continue"
*
*/
continueButton.setMnemonicParsing(false);
continueButton.setText("Load");
/**
* Creates a VBox at the left of center of the borderpane.
*
*/
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
/**
* Creates a label with text "Do you want to start with..." to indicate the user has to choose between 2 given scenarios.
*
*/
choiceLabel.setText("Do you want to start with...");
/**
* Label for scenario one which is you start with five guns and no cash or debt.
*
*/
gunChoice.setMnemonicParsing(false);
gunChoice.setSelected(true);
gunChoice.setText("Five guns and no cash (But no debt!)?");
gunChoice.setToggleGroup(Start);
/**
* Label for scenario 2 which is you start with cash but also a debt.
*
*/
cashChoice.setAlignment(javafx.geometry.Pos.TOP_LEFT);
cashChoice.setMnemonicParsing(false);
cashChoice.setText("Cash (and a debt)");
cashChoice.setToggleGroup(Start);
borderPane.setBottom(hBox);
/**
* Creates a VBox at the center of the borderpane with a width of 100 and height of 200.
*
*/
BorderPane.setAlignment(vBox0, javafx.geometry.Pos.CENTER);
vBox0.setAlignment(javafx.geometry.Pos.CENTER);
vBox0.setPrefHeight(200.0);
vBox0.setPrefWidth(100.0);
/**
* Creates a label with text "Taipan" in size 66 font and default font style.
*
*/
title.setText("Taipan");
title.setFont(new Font(66.0));
/**
* Creates a label with our names as text
*
*/
authors.setPrefHeight(80.0);
authors.setPrefWidth(480.0);
authors.setText("By Vikram Bawa, Haris Muhammad, Siddhant Dewani, Nathan Lum \nand Harkamal Randhawa");
/**
* Puts Vbox0 in the center of the borderpane.
*
*/
authors.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
authors.setAlignment(Pos.CENTER);
vBox0.setAlignment(Pos.CENTER);
borderPane.setCenter(vBox0);
/**
* Adds all the buttons and labels to their respective boxes.
*
*/
hBox.getChildren().add(nameField);
hBox.getChildren().add(startButton);
hBox.getChildren().add(continueButton);
vBox.getChildren().add(choiceLabel);
vBox.getChildren().add(gunChoice);
vBox.getChildren().add(cashChoice);
hBox.getChildren().add(vBox);
vBox0.getChildren().add(title);
vBox0.getChildren().add(authors);
startButton.setDefaultButton(true);
/**
* Adds function to the "Start" button, scenario 1 gives the player $400 and a $5000 debt at the start of the game;
* scenario 2 gives the player 5 guns.
*
*/
startButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (Start.getSelectedToggle() == cashChoice) {
setMoney(400);
setDebt(5000);
setGuns(0);
}
if (Start.getSelectedToggle() == gunChoice) {
setGuns(5);
}
String response = nameField.getText();
// purely for testing purposes.
if (response.equalsIgnoreCase("Vikram")) {
setMoney(999999999);
setBank(999999999);
setGuns(999);
setHP(99999999);
setCargoSpace(Integer.MAX_VALUE);
}
setFirm(response);
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
});
continueButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
FileSaving saving = new FileSaving();
if(saving.loadFile() != null){
TaipanShopGUI shop = new TaipanShopGUI(saving.loadFile());
shop.initializeShop(stage);
stage.show();
}
else{
authors.setText("There are no previous saves!");
}
}
});
Scene root = new Scene(borderPane, 600, 480);
root.getStylesheets().add("styleguide.css");
stage.setTitle("Start");
stage.setResizable(false);
stage.setScene(root);
stage.setHeight(510);
stage.setWidth(600);
return stage;
}
}

View File

@@ -1,726 +0,0 @@
import java.util.Random;
import java.util.Scanner;
public class TaipanShop {
private Player player;
private int opiumPrice = 16000;
private int silkPrice = 1600;
private int armsPrice = 160;
private int generalPrice = 8;
/**
* This method is evoked if the user is eligible to win, and chooses to end the game (by winning).
*/
public void retire(){
player.setRetire(true);
System.out.println("You win!");
System.exit(0);
}
/**
* sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
*
* @param player is a Player object that will replace the current instance of the player instance variable.
*/
public void setPlayer(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
*
* @return playerDummy -- playerDummy is a copy of the player instance variable.
*/
public Player getPlayer(){
Player playerDummy = new Player(player);
return playerDummy;
}
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public TaipanShop(Player player){
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* getter for opiumPrice instance variable.
*
* @return opiumPrice -- the price of opium in the shop
*/
public int getOpiumPrice() {
return opiumPrice;
}
/**
* setter for the opiumPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param opiumPrice -- what the instance variable opiumPrice should be changed to.
*/
public void setOpiumPrice(int opiumPrice) {
if(opiumPrice > 0){
this.opiumPrice = opiumPrice;
}
}
/**
* getter for silkPrice instance variable.
*
* @return silkPrice -- the price of silk in the shop.
*/
public int getSilkPrice() {
return silkPrice;
}
/**
* setter for the silkPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param silkPrice -- what the instance variable silkPrice should be changed to.
*/
public void setSilkPrice(int silkPrice) {
if(silkPrice > 0){
this.silkPrice = silkPrice;
}
}
/**
* getter for armsPrice instance variable.
*
* @return armsPrice -- the price of arms in the shop.
*/
public int getArmsPrice() {
return armsPrice;
}
/**
* setter for the armsPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param armsPrice -- what the instance variable armsPrice should be changed to.
*/
public void setArmsPrice(int armsPrice) {
if(armsPrice > 0){
this.armsPrice = armsPrice;
}
}
/**
* getter for generalPrice instance variable.
*
* @return generalPrice -- the price of general cargo in the shop.
*/
public int getGeneralPrice() {
return generalPrice;
}
/**
* setter for the generalPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param generalPrice -- what the instance variable generalPrice should be changed to.
*/
public void setGeneralPrice(int generalPrice) {
if(generalPrice > 0){
this.generalPrice = generalPrice;
}
}
/**
* this method is evoked if the user has decided to travel elsewhere.
*/
public void travel(){
Travel travel = new Travel(player);
travel.travelTo();
player = travel.getPlayer();
}
/**
* this method is evoked if the user wants to use the warehouse to store items or take items out.
*/
public void warehouse(){
Warehouse warehouse = new Warehouse(player);
warehouse.changeWarehouse();
player = warehouse.getPlayer();
}
/**
* this method is evoked if the user wants to use the bank to deposit or withdraw money.
*/
public void bank(){
Bank bank = new Bank(player);
bank.bank();
player = bank.getPlayer();
}
/**
* this method is evoked if the user wants to use get a loan or pay a loan off.
*/
public void loan(){
loanShark loan = new loanShark(player);
loan.loanMoney();
player = loan.getPlayer();
}
/**
* this method is when the shop is accessed, randomizing the prices of all the items.
*/
public void updatePrices(){
String s = "\n" + player.getName() + ", the price of ";
double value = 80*Math.random();
Random rand = new Random();
opiumPrice = (rand.nextInt(201) + 60)*100;
silkPrice = (rand.nextInt(201) + 60)*10;
armsPrice = (rand.nextInt(21) + 6)*10;
generalPrice = rand.nextInt(17) + 4;
// there is a 10% chance that the price of an item is increased/decreased beyond its regular range.
if(value < 8){
if(value < 2){
if(value < 1){
opiumPrice /= 5;
System.out.println(s + "Opium has dropped to " + opiumPrice +"!!!\n");
}else{
opiumPrice *= 5;
System.out.println(s + "Opium has risen to " + opiumPrice +"!!!\n");
}
}else if(value < 4){
if(value < 3){
silkPrice /= 5;
System.out.println(s + "Silk has dropped to " + silkPrice +"!!!\n");
}else{
silkPrice *= 5;
System.out.println(s + "Silk has risen to " + silkPrice +"!!!\n");
}
}else if(value < 6){
if(value < 3){
armsPrice /= 5;
System.out.println(s + "Arms has dropped to " + armsPrice +"!!!\n");
}else{
armsPrice *= 5;
System.out.println(s + "Arms has risen to " + armsPrice +"!!!\n");
}
}else{
if(value < 7){
generalPrice = 1;
System.out.println(s + "General Cargo has dropped to 1!!!\n");
}else{
generalPrice *= 5;
System.out.println(s + "General Cargo has risen to " + generalPrice + "!!!\n");
}
}
}
}
/**
* this method prints the shop UI and the player's inventory and status.
*/
public void printShop(){
int currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld();
if(player.getCargoSpace() - currentCargo < 0){
System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%");
}else{
System.out.println("Hold: " + (player.getCargoSpace()-currentCargo) + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%");
}
System.out.println("-------------------------------------------------------------");
System.out.println(" Opium: " + player.getOpiumHeld() + " Silk: " + player.getSilkHeld());
System.out.println(" Arms: " + player.getArmsHeld() + " General: " + player.getGeneralHeld());
System.out.println("-------------------------------------------------------------");
System.out.println("Cash: " + player.getMoney() + " Bank: " + player.getBank()+ " Debt: " + player.getDebt()+"\n");
System.out.println(player.getName() + ", present prices per unit here are:");
System.out.println(" Opium: " + opiumPrice + " Silk: " + silkPrice);
System.out.println(" Arms: " + armsPrice + " General: " + generalPrice);
}
/**
* This method is evoked if the user is at the location one port.
*/
public void atLocationOne(){
boolean notDone = true;
Scanner input = new Scanner(System.in);
// as long as the user does not enter a valid input, the code will run in a loop forever.
while(notDone){
printShop();
System.out.println("\nShall I Buy, Sell, Visit Bank, Get Loans, Transfer Cargo, or Quit Trading?");
String response = input.next();
if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?");
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / opiumPrice && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()+num);
player.setMoney(player.getMoney()-num * opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney()-num * silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / generalPrice && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} // when selling, the user must enter a non-negative amount of items, and not more than what they have.
else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num);
player.setMoney(player.getMoney() + num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num);
player.setMoney(player.getMoney() + num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num);
player.setMoney(player.getMoney() + num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} else if (response.equalsIgnoreCase("V")) {
bank();
} else if (response.equalsIgnoreCase("T")) {
warehouse();
}else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) {
loan();
} // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("Q")) {
travel();
notDone = false;
}
}
}
/**
* This method is evoked when the user is at any port other than location one.
*/
public void notAtLocationOne(){
boolean notDone = true;
Scanner input = new Scanner(System.in);
// as long as the user does not enter a valid input, the code will run in a loop forever.
while(notDone){
printShop();
System.out.println("\nShall I Buy, Sell, or Quit Trading?");
String response = input.next();
if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?");
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / opiumPrice && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()+num);
player.setMoney(player.getMoney() - num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney() - num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / generalPrice && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} // when selling, the user must enter a non-negative amount of items, and not more than what they have.
else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num);
player.setMoney(player.getMoney() + num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num);
player.setMoney(player.getMoney() + num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num);
player.setMoney(player.getMoney() + num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("Q")) {
travel();
notDone = false;
}
}
}
/**
* this method is run if the user is eligible to win, and is at location one.
*/
public void retireAndLocationOne(){
boolean notDone = true;
Scanner input = new Scanner(System.in);
// as long as the user does not enter a valid input, the code will run in a loop forever.
while(notDone){
printShop();
System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, Get Loans, Retire, or Quit Trading?");
String response = input.next();
if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?");
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / opiumPrice && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()+num);
player.setMoney(player.getMoney()-num * opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney()-num * silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / generalPrice && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} // when selling, the user must enter a non-negative amount of items, and not more than what they have.
else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num);
player.setMoney(player.getMoney() + num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num);
player.setMoney(player.getMoney() + num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num);
player.setMoney(player.getMoney() + num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} else if (response.equalsIgnoreCase("V")) {
bank();
} else if (response.equalsIgnoreCase("T")) {
warehouse();
} else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) {
loan();
} // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("Q")) {
travel();
notDone = false;
} // if the user wishes to retire and win the game, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("R")) {
retire();
notDone = false;
}
}
}
/**
* the general method that utilizes all the other methods to form a fully functioning shop.
*/
public void shop() {
updatePrices();
// first case is triggered if the user is at location one, and has less than $1 million net worth
if (player.getLocation() == 1 && player.getBank()+player.getMoney()-player.getDebt() < 1000000) {
atLocationOne();
} // the second case is triggered if the user is at a location other than location one.
else if(player.getLocation() != 1) {
notAtLocationOne();
} // the last case is triggered when the other conditions are not met; it is triggered when the user has a net
// worth that is greater than or equal to $1 million and is at location one.
else{
retireAndLocationOne();
}
}
}

880
src/TaipanShopGUI.java Normal file
View File

@@ -0,0 +1,880 @@
/**
* TaipanShopGUI deals with setting the stage for shop; the shop shows much of the user's inventory
* and features the buying and selling aspect of the game.
*
* Author: Vikram Bawa
*/
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.util.Random;
public class TaipanShopGUI extends Player{
private Label firm = new Label();
private Label wItemsText = new Label();
private Label wItemSpaceText = new Label();
private Label locationText = new Label();
private Label inventoryText = new Label();
private Label inventoryHeldText = new Label();
private Label gunsText = new Label();
private Label shipStatusText = new Label();
private Label cashText = new Label();
private Label bankText = new Label();
private Label textOut = new Label();
private Button quitButton = new Button();
private Button retireButton = new Button();
private Button bankButton = new Button();
private Button sellButton = new Button();
private Button buyButton = new Button();
private Button loanButton = new Button();
private Button cargoButton = new Button();
private Button opiumButton = new Button();
private Button silkButton = new Button();
private Button armsButton = new Button();
private Button generalButton = new Button();
private TextField numberInput = new TextField();
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public TaipanShopGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* This method is evoked if the user is eligible to win, and chooses to end the game (by winning).
*/
public void retire(Stage stage) {
setRetire(true);
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(stage);
stage.show();
}
/**
* this method is when the shop is accessed, randomizing the prices of all the items.
*/
public void updatePrices() {
String s = "\t" + getName() + ", the price of ";
double value = 80 * Math.random();
Random rand = new Random();
setOpiumPrice((rand.nextInt(201) + 60) * 100);
setSilkPrice((rand.nextInt(201) + 60) * 10);
setArmsPrice((rand.nextInt(21) + 6) * 10);
setGeneralPrice((rand.nextInt(17) + 4));
// there is a 10% chance that the price of an item is increased/decreased beyond its regular range.
if (value < 8) {
if (value < 2) {
if (value < 1) {
setOpiumPrice(getOpiumPrice() / 5);
textOut.setText(s + "Opium has dropped to " + getOpiumPrice() + "!!!\n" + textOut.getText());
} else {
setOpiumPrice(getOpiumPrice() * 5);
textOut.setText(s + "Opium has risen to " + getOpiumPrice() + "!!!\n" + textOut.getText());
}
} else if (value < 4) {
if (value < 3) {
setSilkPrice(getSilkPrice() / 5);
textOut.setText(s + "Silk has dropped to " + getSilkPrice() + "!!!\n" + textOut.getText());
} else {
setSilkPrice(getSilkPrice() * 5);
textOut.setText(s + "Silk has risen to " + getSilkPrice() + "!!!\n" + textOut.getText());
}
} else if (value < 6) {
if (value < 3) {
setArmsPrice(getArmsPrice() / 5);
textOut.setText(s + "Arms has dropped to " + getArmsPrice() + "!!!\n" + textOut.getText());
} else {
setArmsPrice(getArmsPrice() * 5);
textOut.setText(s + "Arms has risen to " + getArmsPrice() + "!!!\n" + textOut.getText());
}
} else {
if (value < 7) {
setGeneralPrice(1);
textOut.setText(s + "General Cargo has dropped to 1!!!\n" + textOut.getText());
} else {
setGeneralPrice(getGeneralPrice() * 5);
textOut.setText(s + "General Cargo has risen to " + getGeneralPrice() + "!!!\n" + textOut.getText());
}
}
}
}
/**
* Sets the default dialogue of simply stating the prices of the items.
*/
public void defaultTextOut() {
textOut.setText(String.format("\t%s, present prices per unit here are:\n\n\t\tOpium: %d\t\t\tSilk: %d\n\t\tArms: %d\t\t\tGeneral: %d", getName(), getOpiumPrice(), getSilkPrice(), getArmsPrice(), getGeneralPrice()));
}
/**
* Sets up buttons according to which "state" is inputted. When used in "shop", only the item buttons are visible.
* When used in "reset", all the item buttons are invisible; if the user is at location one and is eligible to win,
* then all utilities and the retire button are visible. If the user is not at location one, then the user can only
* buy, sell, or exit. If the user is at location one and is not eligible to win, then all utilities are visible but
* the retire button is not. When used in "input" everything near the bottom is invisible except for the text area.
*
* @param state -- the state determines which buttons are visible and which are not.
*/
public void buttonSetup(String state) {
if (state.equals("shop")) {
buyButton.setVisible(false);
sellButton.setVisible(false);
bankButton.setVisible(false);
numberInput.setVisible(false);
cargoButton.setVisible(false);
loanButton.setVisible(false);
armsButton.setVisible(true);
quitButton.setVisible(false);
opiumButton.setVisible(true);
silkButton.setVisible(true);
generalButton.setVisible(true);
retireButton.setVisible(false);
} else if (state.equals("reset")) {
buyButton.setText("Buy");
sellButton.setText("Sell");
opiumButton.setText("Opium");
silkButton.setText("Silk");
armsButton.setText("Arms");
generalButton.setText("General");
if (getLocation() != 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(false);
cargoButton.setVisible(false);
loanButton.setVisible(false);
armsButton.setVisible(false);
quitButton.setVisible(true);
//quitButton.setDefaultButton(true);
opiumButton.setVisible(false);
silkButton.setVisible(false);
numberInput.setVisible(false);
generalButton.setVisible(false);
retireButton.setVisible(false);
}
if (getBank() + getMoney() - getDebt() < 1000000 && getLocation() == 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
cargoButton.setVisible(true);
loanButton.setVisible(true);
quitButton.setVisible(true);
//quitButton.setDefaultButton(true);
opiumButton.setVisible(false);
silkButton.setVisible(false);
numberInput.setVisible(false);
generalButton.setVisible(false);
armsButton.setVisible(false);
retireButton.setVisible(false);
} else if (getLocation() == 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
cargoButton.setVisible(true);
loanButton.setVisible(true);
numberInput.setVisible(false);
quitButton.setVisible(true);
//quitButton.setDefaultButton(true);
opiumButton.setVisible(false);
silkButton.setVisible(false);
generalButton.setVisible(false);
armsButton.setVisible(false);
retireButton.setVisible(true);
}
} else if (state.equals("input")) {
buyButton.setVisible(false);
sellButton.setVisible(false);
bankButton.setVisible(false);
cargoButton.setVisible(false);
loanButton.setVisible(false);
numberInput.setVisible(true);
quitButton.setVisible(false);
opiumButton.setVisible(false);
silkButton.setVisible(false);
generalButton.setVisible(false);
armsButton.setVisible(false);
retireButton.setVisible(false);
}
}
/**
* this method is responsible for the actual purchasing/selling of items, and the text associated with the act.
*/
public void shop() {
String originalDialogue = textOut.getText();
int num = Integer.parseInt(numberInput.getText().replace(" ", ""));
if (buyButton.getText().contains(".")) {
if (opiumButton.getText().contains(".") && num <= getMoney() / getOpiumPrice() && num >= 0) {
setMoney(getMoney() - num * getOpiumPrice());
setOpiumHeld(getOpiumHeld() + num);
} else if (num >= 0 && opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
} else if (silkButton.getText().contains(".") && num <= getMoney() / getOpiumPrice() && num >= 0) {
setSilkHeld(getSilkHeld() + num);
setMoney(getMoney() - num * getOpiumPrice());
} else if (num >= 0 && silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
} else if (armsButton.getText().contains(".") && num <= getMoney() / getArmsPrice() && num >= 0) {
setArmsHeld(getArmsHeld() + num);
setMoney(getMoney() - num * getArmsPrice());
} else if (num >= 0 && armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
} else if (generalButton.getText().contains(".") && num <= getMoney() / getGeneralPrice() && num >= 0) {
setGeneralHeld(getGeneralHeld()+num);
setMoney(getMoney() - num * getGeneralPrice());
} else if (num >= 0 && generalButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (generalButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
} else if (sellButton.getText().contains(".")) {
if (opiumButton.getText().contains(".") && num <= getOpiumHeld() && num >= 0) {
setOpiumHeld(getOpiumHeld() - num);
setMoney(getMoney() + num * getOpiumPrice());
} else if (num >= 0 && opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
} else if (silkButton.getText().contains(".") && num <= getSilkHeld() && num >= 0) {
setSilkHeld(getSilkHeld() - num);
setMoney(getMoney() + num * getOpiumPrice());
} else if (num >= 0 && silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
} else if (armsButton.getText().contains(".") && num <= getArmsHeld() && num >= 0) {
setArmsHeld(getArmsHeld() - num);
setMoney(getMoney() + num * getArmsPrice());
} else if (num >= 0 && armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
} else if (generalButton.getText().contains(".") && num <= getGeneralHeld() && num >= 0) {
setGeneralHeld(getGeneralHeld() - num);
setMoney(getMoney() + num * getGeneralPrice());
} else if (num >= 0 && generalButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else {
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
/**
* Initializes the shop on the given stage as a parameter.
*
* @param stage
*/
public void initializeShop(Stage stage) {
FileSaving saving = new FileSaving();
saving.saveFile(getPlayer());
Font size14 = new Font(14.0);
Rectangle dialogueRectangle = new Rectangle();
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
dialogueRectangle.setHeight(180.0);
dialogueRectangle.setLayoutX(8.0);
dialogueRectangle.setLayoutY(294.0);
dialogueRectangle.setStroke(javafx.scene.paint.Color.BLACK);
dialogueRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
dialogueRectangle.setWidth(582.0);
Rectangle inventoryRectangle = new Rectangle();
inventoryRectangle.setFill(javafx.scene.paint.Color.WHITE);
inventoryRectangle.setHeight(108.0);
inventoryRectangle.setLayoutX(8.0);
inventoryRectangle.setLayoutY(147.0);
inventoryRectangle.setStroke(javafx.scene.paint.Color.BLACK);
inventoryRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
inventoryRectangle.setWidth(405.0);
Rectangle warehouseRectangle = new Rectangle();
warehouseRectangle.setFill(javafx.scene.paint.Color.WHITE);
warehouseRectangle.setHeight(108.0);
warehouseRectangle.setLayoutY(33.0);
warehouseRectangle.setLayoutX(8.0);
warehouseRectangle.setStroke(javafx.scene.paint.Color.BLACK);
warehouseRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
warehouseRectangle.setWidth(405.0);
AnchorPane anchorPane = new AnchorPane();
anchorPane.setPrefHeight(480.0);
anchorPane.setPrefWidth(600.0);
GridPane gridPane = new GridPane();
gridPane.setPrefHeight(480.0);
gridPane.setPrefWidth(600.0);
ColumnConstraints columnConstraints = new ColumnConstraints();
columnConstraints.setMaxWidth(590.0);
columnConstraints.setMinWidth(0.0);
columnConstraints.setPrefWidth(590.0);
RowConstraints rowConstraints = new RowConstraints();
rowConstraints.setMinHeight(20.0);
rowConstraints.setPrefHeight(20.0);
RowConstraints rowConstraints0 = new RowConstraints();
rowConstraints0.setMaxHeight(122.0);
rowConstraints0.setMinHeight(10.0);
rowConstraints0.setPrefHeight(117.0);
RowConstraints rowConstraints1 = new RowConstraints();
rowConstraints1.setMaxHeight(163.0);
rowConstraints1.setMinHeight(10.0);
rowConstraints1.setPrefHeight(112.0);
RowConstraints rowConstraints2 = new RowConstraints();
rowConstraints2.setMaxHeight(126.0);
rowConstraints2.setMinHeight(0.0);
rowConstraints2.setPrefHeight(42.0);
RowConstraints rowConstraints3 = new RowConstraints();
rowConstraints3.setMaxHeight(269.0);
rowConstraints3.setMinHeight(10.0);
rowConstraints3.setPrefHeight(118.0);
RowConstraints rowConstraints4 = new RowConstraints();
rowConstraints4.setMaxHeight(179.0);
rowConstraints4.setMinHeight(10.0);
rowConstraints4.setPrefHeight(52.0);
gridPane.setPadding(new Insets(10.0, 10.0, 10.0, 0.0));
HBox hBox = new HBox();
GridPane.setRowIndex(hBox, 1);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
HBox hBox0 = new HBox();
GridPane.setRowIndex(hBox0, 2);
hBox0.setPrefHeight(100.0);
hBox0.setPrefWidth(200.0);
FlowPane flowPane = new FlowPane();
GridPane.setRowIndex(flowPane, 5);
flowPane.setAlignment(javafx.geometry.Pos.CENTER);
flowPane.setHgap(5.0);
flowPane.setPrefHeight(200.0);
flowPane.setPrefWidth(200.0);
buyButton.setMnemonicParsing(false);
buyButton.setPrefHeight(25.0);
buyButton.setPrefWidth(45.0);
buyButton.setText("Buy");
buyButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* if the buy button is clicked, the main utility buttons are set to be invisible and the buying process begins.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
buttonSetup("shop");
buyButton.setText("Buy.");
defaultTextOut();
textOut.setText(textOut.getText() + "\n\tWhich good would you like to purchase?");
}
});
sellButton.setPrefHeight(25.0);
sellButton.setText("Sell");
// if the sell button is clicked, the main utility buttons are set to be invisible and the selling process begins.
sellButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* if the sell button is clicked, the main utility buttons are set to be invisible and the selling process begins.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
buttonSetup("shop");
sellButton.setText("Sell.");
defaultTextOut();
textOut.setText(textOut.getText() + "\n\tWhich good would you like to sell?");
}
});
sellButton.setPrefWidth(45.0);
sellButton.setMnemonicParsing(false);
bankButton.setPrefHeight(25.0);
bankButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* opens the bank if the bank button is clicked.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
BankGUI bank = new BankGUI(getPlayer());
bank.initializeBank(stage);
stage.show();
}
});
bankButton.setMnemonicParsing(false);
bankButton.setPrefWidth(74.0);
bankButton.setText("Bank");
cargoButton.setPrefHeight(25.0);
cargoButton.setText("Transfer");
cargoButton.setMnemonicParsing(false);
cargoButton.setPrefWidth(94.0);
cargoButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* warehouse is entered when the warehouse button is clicked.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
WarehouseGUI warehouseGUI = new WarehouseGUI(getPlayer());
warehouseGUI.initializeWarehouse(stage);
stage.show();
}
});
loanButton.setMnemonicParsing(false);
loanButton.setPrefHeight(25.0);
loanButton.setPrefWidth(73.0);
loanButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* loan office is entered when the loan button is clicked.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
loan.initializeLoanShark(stage);
stage.show();
}
});
loanButton.setText("Loans");
quitButton.setPrefHeight(25.0);
quitButton.setMnemonicParsing(false);
quitButton.setPrefWidth(90.0);
quitButton.setText("Quit");
quitButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* the user is free to travel once the quit button is clicked.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
setIsPriceChanged(1);
TravelGUI travelGUI = new TravelGUI(getPlayer());
travelGUI.initializeTravel(stage);
stage.show();
}
});
retireButton.setPrefHeight(25.0);
retireButton.setPrefWidth(49.0);
retireButton.setText("Retire");
retireButton.setVisible(false);
retireButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* the user wins the game when the retire button is clicked.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
retire(stage);
}
});
retireButton.setMnemonicParsing(false);
opiumButton.setMnemonicParsing(false);
opiumButton.setPrefWidth(86.0);
opiumButton.setPrefHeight(25.0);
opiumButton.setText("Opium");
opiumButton.setVisible(false);
opiumButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* the opium buying/selling process starts as soon as the user clicks the opium button.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
buttonSetup("input");
opiumButton.setText("Opium.");
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", getMoney() / getOpiumPrice());
} else {
extraText = String.format(" (You have %d)", getOpiumHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Opium?" + extraText);
}
});
silkButton.setPrefHeight(25.0);
silkButton.setPrefWidth(86.0);
silkButton.setMnemonicParsing(false);
silkButton.setText("Silk");
silkButton.setVisible(false);
silkButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* the silk buying/selling process starts as soon as the user clicks the silk button.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
buttonSetup("input");
silkButton.setText("Silk.");
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", getMoney() / getSilkPrice());
} else {
extraText = String.format(" (You have %d)", getSilkHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Silk?" + extraText);
}
});
armsButton.setPrefWidth(86.0);
armsButton.setMnemonicParsing(false);
armsButton.setVisible(false);
armsButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* the arms buying/selling process starts as soon as the user clicks the arms button.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
buttonSetup("input");
armsButton.setText("Arms.");
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", getMoney() / getArmsPrice());
} else {
extraText = String.format(" (You have %d)", getArmsHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Arms?" + extraText);
}
});
armsButton.setText("Arms");
armsButton.setPrefHeight(25.0);
generalButton.setMnemonicParsing(false);
generalButton.setPrefHeight(25.0);
generalButton.setPrefWidth(86.0);
generalButton.setText("General");
generalButton.setVisible(false);
generalButton.setOnAction(new EventHandler<ActionEvent>() {
/**
* the general cargo buying/selling process starts as soon as the user clicks the general cargo button.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(ActionEvent event) {
buttonSetup("input");
generalButton.setText("General.");
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", getMoney() / getGeneralPrice());
} else {
extraText = String.format(" (You have %d)", getGeneralHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of General Cargo?" + extraText);
}
});
numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT);
numberInput.setText("Enter amount here...");
numberInput.setVisible(false);
numberInput.setOnKeyPressed(new EventHandler<KeyEvent>() {
/**
* after the user inputs a valid input into the text field and presses Z or ENTER, the buying/selling ends
* and the user is returned to the regular shop dialogue.
*
* @param event -- the event corresponding to the button click
*/
@Override
public void handle(KeyEvent event) {
boolean exit = true;
defaultTextOut();
if (event.getCode().equals(KeyCode.ENTER) || event.getCode().equals(KeyCode.Z)) {
while (true) {
if (!textOut.getText().contains("You entered an invalid input!") && !exit) {
textOut.setText(textOut.getText() + "\n\n\tYou entered an invalid input! Please try again.");
break;
}
try {
shop();
} catch (Exception e) {
exit = false;
}
if (exit) {
break;
}
}
updateStage();
buttonSetup("reset");
}
}
});
firm.setAlignment(Pos.CENTER);
firm.setPrefHeight(27.0);
firm.setPrefWidth(632.0);
firm.setFont(new Font(18.0));
Label warehouseText = new Label();
warehouseText.setAlignment(Pos.CENTER);
warehouseText.setPrefHeight(108.0);
warehouseText.setPrefWidth(100.0);
warehouseText.setText(" Warehouse\n\tOpium\n\tSilk\n\tArms\n\tGeneral");
warehouseText.setFont(size14);
wItemsText.setAlignment(Pos.CENTER);
wItemsText.setPrefWidth(100.0);
wItemsText.setPrefHeight(108.0);
wItemsText.setFont(size14);
wItemSpaceText.setPrefHeight(108.0);
wItemSpaceText.setPrefWidth(215.0);
wItemSpaceText.setFont(size14);
locationText.setAlignment(Pos.BOTTOM_CENTER);
locationText.setPrefHeight(106.0);
locationText.setPrefWidth(175.0);
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
locationText.setFont(size14);
inventoryText.setAlignment(Pos.CENTER);
inventoryText.setFont(size14);
inventoryHeldText.setAlignment(Pos.CENTER);
inventoryHeldText.setPrefHeight(108.0);
inventoryHeldText.setPrefWidth(100.0);
inventoryHeldText.setFont(size14);
gunsText.setPrefHeight(108.0);
gunsText.setPrefWidth(212.0);
gunsText.setAlignment(Pos.CENTER_LEFT);
gunsText.setFont(size14);
shipStatusText.setAlignment(Pos.TOP_CENTER);
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
shipStatusText.setPrefHeight(110.0);
shipStatusText.setPrefWidth(180.0);
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
shipStatusText.setFont(size14);
GridPane.setRowIndex(cashText, 3);
cashText.setPrefHeight(17.0);
cashText.setPrefWidth(209.0);
cashText.setFont(size14);
GridPane.setHalignment(bankText, javafx.geometry.HPos.CENTER);
GridPane.setRowIndex(bankText, 3);
bankText.setAlignment(Pos.CENTER);
bankText.setPrefHeight(20.0);
bankText.setPrefWidth(264.0);
bankText.setFont(size14);
GridPane.setRowIndex(textOut, 4);
textOut.setAlignment(Pos.TOP_LEFT);
textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP);
textOut.setPrefHeight(163.0);
textOut.setPrefWidth(583.0);
defaultTextOut();
textOut.setFont(size14);
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
hBox.getChildren().addAll(warehouseText, wItemsText, wItemSpaceText, locationText);
hBox0.getChildren().addAll(inventoryText, inventoryHeldText, gunsText, shipStatusText);
flowPane.getChildren().addAll(buyButton, sellButton, bankButton, cargoButton, loanButton, quitButton, retireButton, opiumButton, silkButton, armsButton, generalButton, numberInput);
gridPane.getColumnConstraints().add(columnConstraints);
gridPane.getRowConstraints().addAll(rowConstraints, rowConstraints0, rowConstraints1, rowConstraints2, rowConstraints3, rowConstraints4);
gridPane.getChildren().addAll(firm, hBox, hBox0, cashText, bankText, textOut, flowPane);
anchorPane.getChildren().add(gridPane);
Scene root = new Scene(anchorPane, 600, 480);
root.getStylesheets().add("styleguide.css");
stage.setTitle("Shop");
stage.setResizable(false);
stage.setScene(root);
buyButton.setFocusTraversable(false);
sellButton.setFocusTraversable(false);
bankButton.setFocusTraversable(false);
loanButton.setFocusTraversable(false);
generalButton.setFocusTraversable(false);
armsButton.setFocusTraversable(false);
silkButton.setFocusTraversable(false);
opiumButton.setFocusTraversable(false);
sellButton.setFocusTraversable(false);
retireButton.setFocusTraversable(false);
cargoButton.setFocusTraversable(false);
quitButton.setFocusTraversable(false);
// general updates to the buttons, user stats/inventory, and text.
buttonSetup("reset");
if(getIsPriceChanged() == 0 || getIsPriceChanged() == 2){
updatePrices();
}
defaultTextOut();
updateStage();
}
/**
* converts the user's location (an integer) to a String, and returns it.
*
* @return location -- the user's location as a string; the actual name of the location.
*/
public String getStringLocation() {
String location;
switch (getLocation()) {
case 1:
location = "Hong Kong";
break;
case 2:
location = "Shanghai";
break;
case 3:
location = "Nagasaki";
break;
case 4:
location = "Saigon";
break;
case 5:
location = "Manila";
break;
case 6:
location = "Singapore";
break;
case 7:
location = "Batavia";
break;
default:
location = "Error";
break;
}
return location;
}
/**
* returns the user's condition based upon their current HP.
*
* @return shipStatus -- a representation of their ship's health in words.
*/
public String shipStatusString() {
String shipStatus;
switch (getHP() / 10) {
case 10:
shipStatus = "Mint Condition";
break;
case 9:
shipStatus = "Near Perfect";
break;
case 8:
shipStatus = "Great";
break;
case 7:
shipStatus = "Good";
break;
case 6:
shipStatus = "Acceptable";
break;
case 5:
shipStatus = "Tolerable";
break;
case 4:
shipStatus = "Needs Repair";
break;
case 3:
shipStatus = "Damaged";
break;
case 2:
shipStatus = "Indangered";
break;
case 1:
shipStatus = "Near Sinking";
break;
case 0:
shipStatus = "Sinking";
break;
default:
shipStatus = "Invincible";
break;
}
return shipStatus;
}
/**
* updates the text associated with the user's inventory.
*/
public void updateStage() {
firm.setText(String.format("Firm: %s, %s", getName(), getStringLocation()));
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", getwOpium(), getwSilk(), getwArms(), getwGeneral()));
int itemsInWarehouse = getwOpium() + getwGeneral() + getwArms() + getwSilk();
wItemSpaceText.setText(String.format("\n\t\tIn use:\n\t\t %d \n\t\tVacant:\n\t\t %d", itemsInWarehouse, (10000 - itemsInWarehouse)));
locationText.setText(String.format("Location\n%s", getStringLocation()));
int itemsInInventory = getCargoSpace() - getSilkHeld() - getOpiumHeld() - getGeneralHeld() - getArmsHeld() - 10 * getGuns();
if (itemsInInventory < 0) {
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
} else {
inventoryText.setText(String.format(" Hold %d\n\t Opium\n\t Silk\n\t Arms\n\t General", itemsInInventory));
}
gunsText.setText(String.format("Guns %d\n\n\n\n ", getGuns()));
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", getOpiumHeld(), getSilkHeld(), getArmsHeld(), getGeneralHeld()));
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", getDebt(), shipStatusString(), getHP()));
cashText.setText(String.format(" Cash: $%,d", getMoney()));
bankText.setText(String.format("Bank: $%,d", getBank()));
}
}

View File

@@ -1,174 +0,0 @@
import java.util.Random;
import java.util.Scanner;
public class Travel {
private Player player;
/**
* sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
*
* @param player is a Player object that will replace the current instance of the player instance variable.
*/
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;
}
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public Travel(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* When provided a location number: the method returns a print statement stating the location's name and call another
* method to change the location of the Player object.
*
* @param locationOfTravel is a Player object that will be copied and the player instance variable is set to the copy.
*/
private void seaAtlas(int locationOfTravel) {
switch (locationOfTravel) {
case 1:
System.out.println("\nArriving at Hong Kong");
player.setLocation(1);
break;
case 2:
System.out.println("\nArriving at Shanghai");
player.setLocation(2);
break;
case 3:
System.out.println("\nArriving at Nagasaki");
player.setLocation(3);
break;
case 4:
System.out.println("\nArriving at Saigon");
player.setLocation(4);
break;
case 5:
System.out.println("\nArriving at Manila");
player.setLocation(5);
break;
case 6:
System.out.println("\nArriving at Singapore");
player.setLocation(6);
break;
case 7:
System.out.println("\nArriving at Batavia");
player.setLocation(7);
break;
}
}
/**
* Based on random chance either attacks the player with enemy ships, throws them to a different location or does nothing.
*
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
* by a typhoon.
**/
private void randomEventSea(int locationOfTravel) throws Exception {
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if (randGenNum == 1) {
peasantFleet();
}else if (randGenNum == 2) {
disaster(locationOfTravel);
System.out.println("We made it!");
}
}
/**
* Based on random chance either throws the player character off course, or continues them on their way to their
* destination.
*
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
* by a typhoon.
**/
private void disaster(int locationOfTravel) {
//Tells player that there is a storm approaching.
System.out.print("Storm " + player.getName() + "! ");
Random rand = new Random();
int randGenNum = rand.nextInt(5) + 1;
//If the player lands within this range, nothing happens to them
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
if (randGenNum <= 2) {
System.out.println(" We made it through!");
}else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) {
System.out.println("We've been blown off course!");
seaAtlas(randGenNum);
}
}
}
}
/**
* To use the peasant fleet class while still maintaining encapsulation we have to create a ShipWarefare object and
* run the method from there. After the method has been run we can update the player object in this class.
* @throws Exception throws Exception so that we can use the time library to make the player if we want to.
**/
public void peasantFleet() throws Exception {
ShipWarfare attackShip = new ShipWarfare(player);
attackShip.peasantFleetAttack();
player = attackShip.getPlayer();
}
/**
*Used to travel between different areas inside of the game world.
* If the player's inventory is too full it won't run.
* Also calculates loan and bank interest between the jumps between islands.
**/
public void travelTo() {
Scanner keyboard = new Scanner(System.in);
String response;
int tempInt;
boolean hasTraveled = false;
//Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory.
if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
while (true) {
System.out.println("\n" + player.getName() + ", do you wish to go to:\n");
System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?");
response = keyboard.nextLine();
//Just in case the player types something that was not intended. It will refresh the question and ask it again
try {
tempInt = Integer.parseInt(response);
//Makes sure you can't travel to your own location.
if (tempInt != player.getLocation()) {
randomEventSea(tempInt);
seaAtlas(tempInt);
hasTraveled = true;
player.setBank((int) (player.getBank() * 1.01));
player.setDebt((int) (player.getDebt() * 1.01));
} else System.out.println("\nYou're already here " + player.getName() + ".");
} catch (Exception e) {
System.out.print("\nSorry, " + player.getName() + " could you say that again?");
}
if (hasTraveled) {
break;
}
}
}
else{
System.out.println(player.getName() + " the cargo is too heavy! We can't set sail!");
}
}
}

504
src/TravelGUI.java Normal file
View File

@@ -0,0 +1,504 @@
/**
* TravelGUI is the class in which takes the player from location to location
*
* Author: Harkamal Randhawa
*/
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
public class TravelGUI extends Player{
private TaipanShopGUI shop;
private Label firm = new Label();
private Label wItemsText = new Label();
private Label wItemSpaceText = new Label();
private Label locationText = new Label();
private Label inventoryText = new Label();
private Label inventoryHeldText = new Label();
private Label gunsText = new Label();
private Label shipStatusText = new Label();
private Label cashText = new Label();
private Label bankText = new Label();
private Label textOut = new Label();
private Button quitButton = new Button();
private Button continueButton = new Button();
private TextField numberInput = new TextField();
private Boolean peasantShipScene = false;
private Boolean littyShipScene = false;
private Boolean shopScene = false;
private Boolean stormScene = false;
private Boolean sceneContinue = false;
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public TravelGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* Sets up the graphical part of TravelGUI and includes all logic for the class
*
* @param stage sets the stage to which we will execute the scene of the TravelGUI class
* @return stage so that another class can switch to the stage
*/
public Stage initializeTravel(Stage stage) {
//Updates the stage for the first-time you read it
updateStage();
Font size14 = new Font(14.0);
Rectangle dialogueRectangle = new Rectangle();
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
dialogueRectangle.setHeight(180.0);
dialogueRectangle.setLayoutX(8.0);
dialogueRectangle.setLayoutY(294.0);
dialogueRectangle.setStroke(javafx.scene.paint.Color.BLACK);
dialogueRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
dialogueRectangle.setWidth(582.0);
Rectangle inventoryRectangle = new Rectangle();
inventoryRectangle.setFill(javafx.scene.paint.Color.WHITE);
inventoryRectangle.setHeight(108.0);
inventoryRectangle.setLayoutX(8.0);
inventoryRectangle.setLayoutY(147.0);
inventoryRectangle.setStroke(javafx.scene.paint.Color.BLACK);
inventoryRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
inventoryRectangle.setWidth(405.0);
Rectangle warehouseRectangle = new Rectangle();
warehouseRectangle.setFill(javafx.scene.paint.Color.WHITE);
warehouseRectangle.setHeight(108.0);
warehouseRectangle.setLayoutY(33.0);
warehouseRectangle.setLayoutX(8.0);
warehouseRectangle.setStroke(javafx.scene.paint.Color.BLACK);
warehouseRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
warehouseRectangle.setWidth(405.0);
AnchorPane anchorPane = new AnchorPane();
anchorPane.setPrefHeight(480.0);
anchorPane.setPrefWidth(600.0);
GridPane gridPane = new GridPane();
gridPane.setPrefHeight(480.0);
gridPane.setPrefWidth(600.0);
ColumnConstraints columnConstraints = new ColumnConstraints();
columnConstraints.setMaxWidth(590.0);
columnConstraints.setMinWidth(0.0);
columnConstraints.setPrefWidth(590.0);
RowConstraints rowConstraints = new RowConstraints();
rowConstraints.setMinHeight(20.0);
rowConstraints.setPrefHeight(20.0);
RowConstraints rowConstraints0 = new RowConstraints();
rowConstraints0.setMaxHeight(122.0);
rowConstraints0.setMinHeight(10.0);
rowConstraints0.setPrefHeight(117.0);
RowConstraints rowConstraints1 = new RowConstraints();
rowConstraints1.setMaxHeight(163.0);
rowConstraints1.setMinHeight(10.0);
rowConstraints1.setPrefHeight(112.0);
RowConstraints rowConstraints2 = new RowConstraints();
rowConstraints2.setMaxHeight(126.0);
rowConstraints2.setMinHeight(0.0);
rowConstraints2.setPrefHeight(42.0);
RowConstraints rowConstraints3 = new RowConstraints();
rowConstraints3.setMaxHeight(269.0);
rowConstraints3.setMinHeight(10.0);
rowConstraints3.setPrefHeight(118.0);
RowConstraints rowConstraints4 = new RowConstraints();
rowConstraints4.setMaxHeight(179.0);
rowConstraints4.setMinHeight(10.0);
rowConstraints4.setPrefHeight(52.0);
gridPane.setPadding(new Insets(10.0, 10.0, 10.0, 0.0));
HBox hBox = new HBox();
GridPane.setRowIndex(hBox, 1);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
HBox hBox0 = new HBox();
GridPane.setRowIndex(hBox0, 2);
hBox0.setPrefHeight(100.0);
hBox0.setPrefWidth(200.0);
FlowPane flowPane = new FlowPane();
GridPane.setRowIndex(flowPane, 5);
flowPane.setAlignment(javafx.geometry.Pos.CENTER);
flowPane.setHgap(5.0);
flowPane.setPrefHeight(200.0);
flowPane.setPrefWidth(200.0);
//Creating the continue and quit buttons
quitButton.setPrefHeight(25.0);
quitButton.setMnemonicParsing(false);
quitButton.setPrefWidth(90.0);
quitButton.setText("Go back");
continueButton.setPrefHeight(25.0);
continueButton.setMnemonicParsing(false);
continueButton.setPrefWidth(90.0);
continueButton.setText("Continue");
continueButton.setVisible(false);
//Goes back to shop
quitButton.setOnAction(event -> {
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
});
//Continues on to either shop or shipwarfare
continueButton.setOnAction(event -> {
if(peasantShipScene && getAttackingShips()){
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
try {
ship.initializeShip(stage);
} catch (Exception e) {
e.printStackTrace();
}
stage.show();
}
else if(shopScene){
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if(randGenNum >= 2) {
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
else {
RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer());
randomEventGUI.initializeRandomEventGUI(stage);
stage.show();
}
}
});
//Text input for where the player needs to go inside of the game world
numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT);
//numberInput.setText("Enter preferred location.");
numberInput.setOnKeyPressed(event -> {
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
int response;
try {
response = Integer.parseInt(numberInput.getText().replace(" ", ""));
}
catch (Exception e){
response = 0;
}
boolean hasTraveled = false;
//Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory.
if(getCargoSpace() >= (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
//Just in case the player types something that was not intended. It will refresh the question and ask it again
try {
//Makes sure you can't travel to your own location.
if (response != getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
hasTraveled = seaAtlas(response);
randomEventSea(response,stage);
setBank((int) (getBank() * 1.01));
setDebt((int) (getDebt() * 1.01));
setIsPriceChanged(2);
//shopScene = false;
//stormScene = false;
} else{
if(response == getLocation()){
textOut.setText(" " + "You're already here " + getName() + "\n");
}
else{
textOut.setText(" " + getName() + "; Sorry but could you say that again?");
}
textOut.setText(textOut.getText() + "\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?");
}
} catch (Exception e) {
textOut.setText(" " + "Sorry, " + getName() + " could you say that again?");
}
if (hasTraveled) {
continueButton.setVisible(true);
continueButton.setDefaultButton(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
shopScene = true;
}
}
}
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!");
}
});
firm.setAlignment(Pos.CENTER);
firm.setPrefHeight(27.0);
firm.setPrefWidth(632.0);
firm.setFont(new Font(18.0));
Label warehouseText = new Label();
warehouseText.setAlignment(Pos.CENTER);
warehouseText.setPrefHeight(108.0);
warehouseText.setPrefWidth(100.0);
warehouseText.setText(" Warehouse\n\tOpium\n\tSilk\n\tArms\n\tGeneral");
warehouseText.setFont(size14);
wItemsText.setAlignment(Pos.CENTER);
wItemsText.setPrefWidth(100.0);
wItemsText.setPrefHeight(108.0);
wItemsText.setFont(size14);
wItemSpaceText.setPrefHeight(108.0);
wItemSpaceText.setPrefWidth(215.0);
wItemSpaceText.setFont(size14);
locationText.setAlignment(Pos.BOTTOM_CENTER);
locationText.setPrefHeight(106.0);
locationText.setPrefWidth(175.0);
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
locationText.setFont(size14);
inventoryText.setAlignment(Pos.CENTER);
inventoryText.setFont(size14);
inventoryHeldText.setAlignment(Pos.CENTER);
inventoryHeldText.setPrefHeight(108.0);
inventoryHeldText.setPrefWidth(100.0);
inventoryHeldText.setFont(size14);
gunsText.setPrefHeight(108.0);
gunsText.setPrefWidth(212.0);
gunsText.setAlignment(Pos.CENTER_LEFT);
gunsText.setFont(size14);
shipStatusText.setAlignment(Pos.TOP_CENTER);
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
shipStatusText.setPrefHeight(110.0);
shipStatusText.setPrefWidth(180.0);
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
shipStatusText.setFont(size14);
GridPane.setRowIndex(cashText, 3);
cashText.setPrefHeight(17.0);
cashText.setPrefWidth(209.0);
cashText.setFont(size14);
GridPane.setHalignment(bankText, javafx.geometry.HPos.CENTER);
GridPane.setRowIndex(bankText, 3);
bankText.setAlignment(Pos.CENTER);
bankText.setPrefHeight(20.0);
bankText.setPrefWidth(264.0);
bankText.setFont(size14);
GridPane.setRowIndex(textOut, 4);
textOut.setAlignment(Pos.TOP_LEFT);
textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP);
textOut.setPrefHeight(163.0);
textOut.setPrefWidth(583.0);
textOut.setText(" Taipan, do you wish to go to:\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?\n After typing the number you want to go to press 'Enter' or 'Z'");
textOut.setFont(size14);
//Added all the nodes into a single scene
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
hBox.getChildren().addAll(warehouseText, wItemsText, wItemSpaceText, locationText);
hBox0.getChildren().addAll(inventoryText, inventoryHeldText, gunsText, shipStatusText);
numberInput.requestFocus();
flowPane.getChildren().addAll(numberInput, quitButton, continueButton);
gridPane.getColumnConstraints().add(columnConstraints);
gridPane.getRowConstraints().addAll(rowConstraints, rowConstraints0, rowConstraints1, rowConstraints2, rowConstraints3, rowConstraints4);
gridPane.getChildren().addAll(firm, hBox, hBox0, cashText, bankText, textOut, flowPane);
anchorPane.getChildren().add(gridPane);
Scene root = new Scene(anchorPane, 600, 480);
root.getStylesheets().add("styleguide.css");
stage.setTitle("Travel");
stage.setResizable(false);
stage.setScene(root);
return stage;
}
/**
* When provided a location number: the method returns a print statement stating the location's name and call another
* method to change the location of the Player object.
*
* @param locationOfTravel is a Player object that will be copied and the player instance variable is set to the copy.
*/
private Boolean seaAtlas(int locationOfTravel) {
switch (locationOfTravel) {
case 1:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong");
setLocation(1);
return true;
case 2:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai");
setLocation(2);
return true;
case 3:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki");
setLocation(3);
return true;
case 4:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon");
setLocation(4);
return true;
case 5:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila");
setLocation(5);
return true;
case 6:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore");
setLocation(6);
return true;
case 7:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia");
setLocation(7);
return true;
default:
textOut.setText(" " + "Sorry but could you say that again " + getName() + "?");
return false;
}
}
/**
* Based on random chance either attacks the player with enemy ships, throws them to a different location or does nothing.
*
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
* by a typhoon.
**/
private void randomEventSea(int locationOfTravel, Stage stage) {
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if (randGenNum == 1) {
continueButton.setVisible(true);
continueButton.setDefaultButton(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
textOut.setText(" We see a ship on the horizon " + getName() + "; Prepare for combat!");
peasantShipScene = true;
}else if (randGenNum == 2) {
disaster(locationOfTravel);
textOut.setText(textOut.getText() + "\n " + "We made it!");
}
}
/**
* Based on random chance either throws the player character off course, or continues them on their way to their
* destination.
*
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
* by a typhoon.
**/
private void disaster(int locationOfTravel) {
//Tells player that there is a storm approaching.
textOut.setText(" " + "Storm " + getName() + "! ");
Random rand = new Random();
int randGenNum = rand.nextInt(5) + 1;
//If the player lands within this range, nothing happens to them
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
if (randGenNum <= 2) {
textOut.setText(textOut.getText() + "\n " + "We got through the storm " + getName() + "!");
}else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) {
textOut.setText(textOut.getText() + "\n " + "We've been blown off course!");
seaAtlas(randGenNum);
}
}
}
}
/**
* converts the user's location (an integer) to a String, and returns it.
*
* @return location -- the user's location as a string; the actual name of the location.
*/
public String getStringLocation(){
String location;
switch(getLocation()){
case 1: location = "Hong Kong"; break;
case 2: location = "Shanghai"; break;
case 3: location = "Nagasaki"; break;
case 4: location = "Saigon"; break;
case 5: location = "Manila"; break;
case 6: location = "Singapore"; break;
case 7: location = "Batavia"; break;
default: location = "Error"; break;
}
return location;
}
/**
* returns the user's condition based upon their current HP.
*
* @return shipStatus -- a representation of their ship's health in words.
*/
public String shipStatusString(){
String shipStatus;
switch(getHP()/10){
case 10: shipStatus = "Mint Condition"; break;
case 9: shipStatus = "Near Perfect"; break;
case 8: shipStatus = "Great"; break;
case 7: shipStatus = "Good"; break;
case 6: shipStatus = "Acceptable"; break;
case 5: shipStatus = "Tolerable"; break;
case 4: shipStatus = "Needs Repair"; break;
case 3: shipStatus = "Damaged"; break;
case 2: shipStatus = "Indangered"; break;
case 1: shipStatus = "Near Sinking"; break;
case 0: shipStatus = "Sinking"; break;
default: shipStatus = "Invincible"; break;
}
return shipStatus;
}
/**
* updates the text associated with the user's inventory.
*/
public void updateStage(){
firm.setText(String.format("Firm: %s, %s", getName(), getStringLocation()));
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", getwOpium(), getwSilk(), getwArms(), getwGeneral()));
int itemsInWarehouse = getwOpium()+getwGeneral()+getwArms()+getwSilk();
wItemSpaceText.setText(String.format("\n\t\tIn use:\n\t\t %d \n\t\tVacant:\n\t\t %d", itemsInWarehouse, (10000-itemsInWarehouse)));
locationText.setText(String.format("Location\n%s", getStringLocation()));
int itemsInInventory = getCargoSpace()-getSilkHeld()-getOpiumHeld()-getGeneralHeld()-getArmsHeld()-10*getGuns();
if(itemsInInventory < 0){
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
}else{
inventoryText.setText(String.format(" Hold %d\n\t Opium\n\t Silk\n\t Arms\n\t General", itemsInInventory));
}
gunsText.setText(String.format("Guns %d\n\n\n\n ", getGuns()));
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", getOpiumHeld(), getSilkHeld(), getArmsHeld(), getGeneralHeld()));
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", getDebt(), shipStatusString(), getHP()));
cashText.setText(String.format(" Cash: $%,d", getMoney()));
bankText.setText(String.format("Bank: %d", getBank()));
}
}

View File

@@ -1,272 +0,0 @@
import java.util.Scanner;
/**
* The purpose of this class is to create a warehouse where the goods
* can be safely stored without holing space on the ship!
*/
public class Warehouse {
/*private int wOpium = 0;
private int wSilk = 0;
private int wGeneral = 0;
private int wArms = 0;*/
private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
public void setPlayer(Player player) {
Player playerDumy = new Player(player);
this.player = playerDumy;
}
/**
* getter method for obtaining a player object.
*
* @return returns player object
*/
public Player getPlayer() {
Player playerDummy = new Player(player);
return playerDummy;
}
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public Warehouse(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* This method adds an amount of a certain good
* the user is prompted to enter the amount they would like to
* add followed by the good they would like to add to the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
*
*/
public void addAmount() {
boolean askGood = false;
String amount;
int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to ADD.");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextLine();//Asks the user for the amount of the good they would like to add
/*The try function ensures that the program does not crash
due to any errors while giving the program an incorrect input*/
try {
//The if statement checks that you have enough resources to make the transfer
if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) {
finalAmount = Integer.parseInt(amount);
askGood = true;
}
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
else {
System.out.println("Nice try but you don't have any items of that quantity!");
askGood = false;
}
//Ensures that goods are only transferred if they have the specified amount
//The user is prompted to enter which good they want to transfer
if (askGood == true) {
String good;
System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine();
int held = 0;
//The following set of loops check to see which good the user has selected and makes the transfer
if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) {
if (player.getOpiumHeld() >= Integer.parseInt(amount)) {
player.setwOpium(player.getwOpium() + finalAmount);
held = player.getOpiumHeld();
player.setOpiumHeld(held - finalAmount);
System.out.println(player.getOpiumHeld());
} else {
System.out.println("You don't even have that much opium!");
}
} else if (good.equalsIgnoreCase("S")) {
if (player.getSilkHeld() >= Integer.parseInt(amount)) {
player.setwSilk(player.getwSilk() + finalAmount);
held = player.getSilkHeld();
player.setSilkHeld(held - finalAmount);
} else {
System.out.println("You don't even have that much silk!");
}
} else if (good.equalsIgnoreCase("G")) {
if (player.getGeneralHeld() >= Integer.parseInt(amount)) {
player.setwGeneral(player.getwGeneral() + finalAmount);
held = player.getGeneralHeld();
player.setGeneralHeld(held - finalAmount);
} else {
System.out.println("You don't even have that much general cargo!");
}
} else if (good.equalsIgnoreCase("A")) {
if (player.getArmsHeld() >= Integer.parseInt(amount)) {
player.setwArms(player.getwArms() + finalAmount);
held = player.getArmsHeld();
player.setArmsHeld(held - finalAmount);
} else {
System.out.println("You don't even have that much Arms!");
}
}
}
//Ensures no negative amounts are entered
else {
System.out.println("Sorry this transfer cannot be made");
}
}
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
} catch (Exception e) {
System.out.println("Wait, that's not a valid input please try again");
}
}
/**
* This method removes an amount of a certain good
* the user is prompted to enter the amount they would like to
* remove followed by the good they would like to remove from the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
*
*/
public void removeAmount() {
String amount;
boolean askGood = false;
int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to REMOVE");
Scanner keyboard = new Scanner(System.in);
//Prompts the user for the amount they would like to remove
amount = keyboard.nextLine();
//The if statement checks that you have enough resources to make the transfer
try {
//The if statement checks that you have enough resources to make the transfer
if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) {
finalAmount = Integer.parseInt(amount);
askGood = true;
}
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
else {
System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
askGood = false;
}
//Ensures that goods are only transferred if they have the specified amount
//The user is prompted to enter which good they want to transfer
if (askGood == true) {
String good;
System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine();
int held = 0;
//The following set of loops check to see which good the user has selected and makes the transfer and amount > 0
if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) {
if (player.getwOpium() >= Integer.parseInt(amount)) {
player.setwOpium(player.getwOpium() - Integer.parseInt(amount));
held = player.getOpiumHeld();
player.setOpiumHeld(held + finalAmount);
} else {
System.out.println("You don't have that much opium stored in the warehouse!");
}
} else if (good.equalsIgnoreCase("S")) {
if (player.getwSilk() >= Integer.parseInt(amount)) {
player.setwSilk(player.getwSilk() - Integer.parseInt(amount));
held = player.getSilkHeld();
player.setSilkHeld(held + finalAmount);
} else {
System.out.println("You don't have that much silk stored in the warehouse!");
}
} else if (good.equalsIgnoreCase("G")) {
if (player.getwGeneral() >= Integer.parseInt(amount)) {
player.setwGeneral(player.getwGeneral() - Integer.parseInt(amount));
held = player.getGeneralHeld();
player.setGeneralHeld(held + finalAmount);
} else {
System.out.println("You don't have that much general cargo stored in the warehouse!");
}
} else if (good.equalsIgnoreCase("A")) {
if (player.getwArms() >= Integer.parseInt(amount)) {
player.setwArms(player.getwArms() - Integer.parseInt(amount));
held = player.getArmsHeld();
player.setArmsHeld(held + finalAmount);
} else {
System.out.println("You don't have that much arms stored in the warehouse!");
}
}
}
//Ensures the value entered is positive
else {
System.out.println("Sorry this transfer cannot be made");
}
}
}
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
catch (Exception e){
System.out.println("Wait, that's not a valid input please try again");
}
}
/**
* This method prints the stock that is in the warehouse currently using the get and set
* methods from the player class. This is to allow the user to be able to know how much they have
* stored in the warehouse
*/
public void showWarehouse() {
System.out.println("--------------------\nWarehouse\n--------------------");
System.out.println("Opium : " + player.getwOpium());
System.out.println("Silk : " + player.getwSilk());
System.out.println("General : " + player.getwGeneral());
System.out.println("Arms : " + player.getwArms());
}
/**
* This method combines the add and remove methods and prompts the user to
* enter what they would like to do. Add or remove and accordingly invokes
* the required methods
*/
public void changeWarehouse() {
boolean keepGoing = true;
while (keepGoing) {
this.showWarehouse();
String input = " ";
System.out.println("Would you like to add(A) or remove(R) resources? ");
Scanner keyboard = new Scanner(System.in);
input = keyboard.next();
if (input.equalsIgnoreCase("R")) {
this.removeAmount();
this.showWarehouse();
} else if (input.equalsIgnoreCase("A")) {
this.addAmount();
this.showWarehouse();
}
else{
System.out.println("Don't waste the warehouse's time, try again later with a valid input");
}
String check;
//Check to see if the player wants to continue in the warehouse or they are done
System.out.println("Would you like to do any other business? Y / N?");
check = keyboard.nextLine();
check = keyboard.nextLine();
if (check.equalsIgnoreCase("Y")) {
keepGoing = true;
} else if (check.equalsIgnoreCase("N")) {
keepGoing = false;
}
}
}
}

336
src/WarehouseGUI.java Normal file
View File

@@ -0,0 +1,336 @@
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
/**
* 2019-03-19
* Authors:Siddhant, Vikram, Harkamal, Haris, Nathan
* WarehouseGUI allows the user to store goods in a warehouse in order to have more hold on the ship
*/
public class WarehouseGUI extends Player{
//Create the labels, buttons and textfields required
private HBox hBox;
private VBox vBox;
private TextField textField;
private RadioButton generalRadio;
private ToggleGroup Goods;
private RadioButton armsRadio;
private RadioButton silkRadio;
private RadioButton opiumRadio;
private Button withdrawButton;
private Button depositButton;
private Button quitButton;
private Label title;
private HBox hBox0;
private VBox vBox0;
private Label playerLabel;
private Label playerGeneral;
private Label playerArms;
private Label playerSilk;
private Label playerOpium;
private VBox vBox1;
private Label houseLabel;
private Label houseGeneral;
private Label houseArms;
private Label houseSilk;
private Label houseOpium;
private BorderPane borderPane;
/**
* constructor that creates an object of type player
* @param player
*/
public WarehouseGUI(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
*
* @param stage
* @return stage after creating buttons and layout
*/
public Stage initializeWarehouse(Stage stage){
//Initializes the instances created above to a new type
hBox = new HBox();
vBox = new VBox();
generalRadio = new RadioButton();
Goods = new ToggleGroup();
armsRadio = new RadioButton();
silkRadio = new RadioButton();
opiumRadio = new RadioButton();
withdrawButton = new Button();
depositButton = new Button();
quitButton = new Button();
title = new Label();
hBox0 = new HBox();
vBox0 = new VBox();
playerLabel = new Label();
playerGeneral = new Label();
playerArms = new Label();
playerSilk = new Label();
playerOpium = new Label();
vBox1 = new VBox();
houseLabel = new Label();
houseGeneral = new Label();
houseArms = new Label();
houseSilk = new Label();
houseOpium = new Label();
borderPane = new BorderPane();
textField = new TextField();
//Creating the box for the warehouse GUI
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
hBox.setSpacing(10.0);
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
vBox.setPrefHeight(200.0);
vBox.setPrefWidth(100.0);
//Adding general button
generalRadio.setMnemonicParsing(false);
generalRadio.setSelected(true);
generalRadio.setText("General");
generalRadio.setToggleGroup(Goods);
//Adding Arms Button
armsRadio.setMnemonicParsing(false);
armsRadio.setText("Arms");
armsRadio.setToggleGroup(Goods);
//Adding Silk button
silkRadio.setMnemonicParsing(false);
silkRadio.setText("Silk");
silkRadio.setToggleGroup(Goods);
// Adding opium button
opiumRadio.setMnemonicParsing(false);
opiumRadio.setText("Opium");
opiumRadio.setToggleGroup(Goods);
// Remove materials button
withdrawButton.setMnemonicParsing(false);
withdrawButton.setText("Withdraw");
// Add materials button
depositButton.setMnemonicParsing(false);
depositButton.setText("Deposit");
//Go back to the previous screen button
quitButton.setMnemonicParsing(false);
quitButton.setText("Go back");
borderPane.setBottom(hBox);
//Takes you to the HK warehouse
borderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
title.setText("Hong Kong Warehouse");
title.setFont(new Font(24.0));
title.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
borderPane.setTop(title);
// Making the BOX again
borderPane.setAlignment(hBox0, javafx.geometry.Pos.CENTER);
hBox0.setAlignment(javafx.geometry.Pos.CENTER);
hBox0.setPrefHeight(100.0);
hBox0.setPrefWidth(200.0);
hBox0.setSpacing(10.0);
vBox0.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
vBox0.setSpacing(10.0);
playerLabel.setText("Player:");
playerLabel.setFont(new Font(18.0));
// displays the hold of general
playerGeneral.setText("General:");
// displays the hold of Arms
playerArms.setText("Arms:");
// displays the hold of Silk
playerSilk.setText("Silk:");
// displays the hold of Opium
playerOpium.setText("Opium:");
vBox1.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
vBox1.setSpacing(10.0);
houseLabel.setAlignment(javafx.geometry.Pos.TOP_CENTER);
houseLabel.setText("Warehouse:");
houseLabel.setFont(new Font(18.0));
houseGeneral.setText("General:");
houseArms.setText("Arms:");
houseSilk.setText("Silk:");
houseOpium.setText("Opium:");
//Shows the values of the goods that are in the warehouse
borderPane.setMargin(hBox0, new Insets(0.0));
hBox0.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
vBox0.setPadding(new Insets(0, 0.0, 0.0, 0.0));
borderPane.setCenter(hBox0);
//Add buttons for the goods
vBox.getChildren().add(generalRadio);
vBox.getChildren().add(armsRadio);
vBox.getChildren().add(silkRadio);
vBox.getChildren().add(opiumRadio);
//Adds the buttons for withdraw, deposit and quitting
hBox.getChildren().add(vBox);
hBox.getChildren().add(textField);
hBox.getChildren().add(withdrawButton);
hBox.getChildren().add(depositButton);
hBox.getChildren().add(quitButton);
//Adds the buttons for the amount of the good the player has
vBox0.getChildren().add(playerLabel);
vBox0.getChildren().add(playerGeneral);
vBox0.getChildren().add(playerArms);
vBox0.getChildren().add(playerSilk);
vBox0.getChildren().add(playerOpium);
//Amount of stock the warehouse has of the goods
vBox1.getChildren().add(houseLabel);
vBox1.getChildren().add(houseGeneral);
vBox1.getChildren().add(houseArms);
vBox1.getChildren().add(houseSilk);
vBox1.getChildren().add(houseOpium);
hBox0.getChildren().add(vBox0);
hBox0.getChildren().add(vBox1);
updateLabels();
//Goes back to shop
quitButton.setOnAction(event -> {
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
});
//Runs when the withdraw button is selected. and removes the amount of the selected good
withdrawButton.setOnAction(event -> {
try {
int withdraw = Integer.parseInt(textField.getText());
if(withdraw <= 0){
title.setText("Please enter a valid value");
}
//Transfers general amount
else if(Goods.getSelectedToggle() == generalRadio && withdraw <= getwGeneral()){
setGeneralHeld(getPlayer().getGeneralHeld()+withdraw);
setwGeneral(getPlayer().getwGeneral()-withdraw);
}
//Transfers Arms amount
else if(Goods.getSelectedToggle() == armsRadio && withdraw <= getwArms()){
setArmsHeld(getPlayer().getArmsHeld()+withdraw);
setwArms(getPlayer().getwArms()-withdraw);
}
//Transfers Silk Amount
else if(Goods.getSelectedToggle() == silkRadio && withdraw <= getwSilk()){
setSilkHeld(getPlayer().getSilkHeld()+withdraw);
setwSilk(getPlayer().getwSilk()-withdraw);
}
//Transfers Opium amount
else if(Goods.getSelectedToggle() == opiumRadio && withdraw <= getwOpium()) {
setOpiumHeld(getPlayer().getOpiumHeld() + withdraw);
setwOpium(getPlayer().getwOpium() - withdraw);
}
// Ensures a valid value is entered
else{
title.setText("Please enter a valid value");
}
updateLabels();
}
catch (Exception e) {
title.setText("Please enter a valid value");
}
});
//Button to add a user entered amount to the warehouse
depositButton.setOnAction(event -> {
try {
int deposit = Integer.parseInt(textField.getText());
if(deposit <= 0){
title.setText("Please enter a valid value");
}
//Transfers general amount
else if(Goods.getSelectedToggle() == generalRadio && deposit <= getGeneralHeld()){
setGeneralHeld(getPlayer().getGeneralHeld()-deposit);
setwGeneral(getPlayer().getwGeneral()+deposit);
}
//Transfers Arms amount
else if(Goods.getSelectedToggle() == armsRadio && deposit <= getArmsHeld()){
setArmsHeld(getPlayer().getArmsHeld()-deposit);
setwArms(getPlayer().getwArms()+deposit);
}
//Transfers Silk amount
else if(Goods.getSelectedToggle() == silkRadio && deposit <= getSilkHeld()){
setSilkHeld(getPlayer().getSilkHeld()-deposit);
setwSilk(getPlayer().getwSilk()+deposit);
}
//Transfers Opium amount
else if(Goods.getSelectedToggle() == opiumRadio && deposit <= getOpiumHeld()){
setOpiumHeld(getPlayer().getOpiumHeld()-deposit);
setwOpium(getPlayer().getwOpium()+deposit);
}
//Checks if the correct value is entered
else{
title.setText("Please enter a valid value");
}
updateLabels();
}
catch (Exception e) {
title.setText("Please enter a valid value");
}
});
//Create the sceene and box of the desired size
Scene root = new Scene(borderPane, 600, 480);
root.getStylesheets().add("styleguide.css");
stage.setTitle("Warehouse");
stage.setResizable(false);
stage.setScene(root);
return stage;
}
/**
* As soon as the transfer is made the table of the amount of goods is updated using this method
*/
public void updateLabels(){
playerLabel.setText("Player: " + (getPlayer().getCargoSpace()-((getPlayer().getGuns()*10)+ getPlayer().getGeneralHeld() + getPlayer().getArmsHeld() + getPlayer().getSilkHeld() + getPlayer().getOpiumHeld())));
houseLabel.setText("Warehouse: " + (10000 -(getPlayer().getwGeneral() + getPlayer().getwArms() + getPlayer().getwSilk() + getPlayer().getwOpium())));
playerGeneral.setText("General: " + getPlayer().getGeneralHeld());
playerArms.setText("Arms: " + getPlayer().getArmsHeld());
playerSilk.setText("Silk: " + getPlayer().getSilkHeld() );
playerOpium.setText("Opium: " + getPlayer().getOpiumHeld());
houseGeneral.setText("General: " + getPlayer().getwGeneral());
houseArms.setText("Arms: " + getPlayer().getwArms());
houseSilk.setText("Silk: " + getPlayer().getwSilk());
houseOpium.setText("Opium: " + getPlayer().getwOpium());
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 KiB

BIN
src/images/ShipsRunning.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 KiB

BIN
src/images/enemyShip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

BIN
src/images/ourShip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

View File

@@ -1,97 +0,0 @@
import java.util.Scanner;
public class loanShark {
private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
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;
}
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public loanShark(Player player){
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* This methods purpose is to loan the player the funds it wants
* or pay its outstanding debts. The method prompts the user if they
* would like to borrow money or repay. depending on what the player chooses
* the corresponding loop is evoked. The player can only be loaned 2 times the
* money they have minus the debt id their debt exceeds the cash balance, the loan
* cannot be given.
*/
public void loanMoney() {
boolean keepGoing = true;
while(keepGoing) {
String check;
Scanner keyboard = new Scanner(System.in);
System.out.println("Would you like to return money or borrow money?");
//Prompts the user or what they would like to do
check = keyboard.nextLine();
//If the user chooses to return money, the money is subtracted from the cash amount and debt
if(check.equalsIgnoreCase("r")){
int returnAsk = 0;
System.out.println("Please enter how much you would like to return?");
returnAsk = keyboard.nextInt();
if(returnAsk <= player.getDebt() && returnAsk >= 0) {
player.setDebt(player.getDebt() - returnAsk);
player.setMoney(player.getMoney() - returnAsk);
}
//if you try to return more money than you owe it wont allow you to
else if(returnAsk > player.getDebt()){
System.out.println("You don't need to return that much!");
}
//No negative amounts are allowed
else{
System.out.println("You can't return a negative amount.");
}
}
//If the user chooses to borrow, the money is added to cash and the debt is increased
else if(check.equalsIgnoreCase("b")){
int loanAsk = 0;
System.out.println("Please enter how much you would like to borrow");
//Prompts user for the amount they would like to borrow
loanAsk = keyboard.nextInt();
if(loanAsk <= 2*(player.getMoney() - player.getDebt())&& loanAsk >= 0) {
player.setDebt(player.getDebt() + loanAsk);
player.setMoney(player.getMoney() + loanAsk);
}
//If the requested money exceeds 2*(cash - debt) then the loan cannot be given
else{
System.out.println("Sorry you can't be loaned that much");
break;
}
}
//Asks the player if they have any other things to do with the load shark
System.out.println("Would you like to do any other business? Y / N?");
check = keyboard.nextLine();
check = keyboard.nextLine();
if(check.equalsIgnoreCase("Y")) {
keepGoing = true;
}
else if(check.equalsIgnoreCase("N")) {
keepGoing = false;
}
}
}
}

View File

@@ -1,55 +0,0 @@
public class main {
private Player player = new Player();
/**
* getter method for the Player object player.
*
* @return returns a copy of the object player
*/
public Player getPlayer(){
Player copy = new Player(player);
return copy;
}
/**
* Initializes the Taipan shop with the players stats after the player finishes shopping, it updates the player object and returns it.
*
* @param shop player object from the main class used to update the shop class
*/
public void shop(TaipanShop shop){
shop.setPlayer(player);
shop.shop();
player = shop.getPlayer();
}
/**
* Initializes the player object with 5 guns or $400 and $5000 debt.
*
* @param start player object from the main class used to update the start class
*/
public void start(Start start){
start.setPlayer(player);
start.initialize();
player = start.getPlayer();
}
/**
* Updates main class with player data and starts the game.
* The game will only run as long as the player has not retired or has been destroyed.
* @param args Just the console for the player to look at.
*/
public static void main(String[] args) {
main main = new main();
TaipanShop littyShop = new TaipanShop(main.getPlayer());
Start start = new Start(main.getPlayer());
main.start(start);
while(!main.getPlayer().getRetire()){
main.shop(littyShop);
}
}
}

BIN
src/saves/playerSave.txt Normal file

Binary file not shown.

8
src/styleguide.css Normal file
View File

@@ -0,0 +1,8 @@
.text-field:focused{
-fx-faint-focus-color: transparent;
-fx-focus-color:rgba(0,0,0,0.2);
}
.button:default{
-fx-default-button: #e5f8ff;
}