made everything use inheritance instead of whatever we were doing before.

This commit is contained in:
Vikram
2019-03-19 17:14:42 -06:00
parent 0f9ef34f54
commit 2bc96e5d07
11 changed files with 459 additions and 585 deletions

238
.idea/workspace.xml generated
View File

@@ -3,6 +3,13 @@
<component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/BankGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/BankGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/GameEndGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GameEndGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/LoanSharkGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/LoanSharkGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/MainGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/MainGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Player.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Player.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ShipWarfareGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfareGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/StartGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/StartGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/TaipanShopGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TaipanShopGUI.java" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
@@ -17,54 +24,14 @@
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/MainGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="651">
<caret line="38" column="39" selection-start-line="38" selection-start-column="39" selection-end-line="38" selection-end-column="39" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/StartGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
<caret line="214" column="38" selection-start-line="214" selection-start-column="38" selection-end-line="214" selection-end-column="38" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1764">
<caret line="84" column="44" selection-start-line="84" selection-start-column="44" selection-end-line="84" selection-end-column="44" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/TravelGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="9114">
<caret line="459" column="33" selection-start-line="459" selection-start-column="33" selection-end-line="459" selection-end-column="33" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/TaipanShopGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-48">
<caret line="626" column="115" selection-start-line="626" selection-start-column="115" selection-end-line="626" selection-end-column="115" />
<state relative-caret-position="294">
<caret line="14" column="34" lean-forward="true" selection-start-line="14" selection-start-column="34" selection-end-line="14" selection-end-column="34" />
<folding>
<element signature="n#!!doc" expanded="true" />
<element signature="imports" expanded="true" />
<element signature="e#23685#23686#0" expanded="true" />
<element signature="e#23730#23731#0" expanded="true" />
<element signature="e#23112#23113#0" expanded="true" />
<element signature="e#23157#23158#0" expanded="true" />
</folding>
</state>
</provider>
@@ -73,8 +40,17 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/GameEndGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="42">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
<state relative-caret-position="506">
<caret line="114" column="58" selection-start-line="114" selection-start-column="58" selection-end-line="114" selection-end-column="58" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/LoanSharkGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="622">
<caret line="160" column="58" lean-forward="true" selection-start-line="160" selection-start-column="58" selection-end-line="160" selection-end-column="58" />
</state>
</provider>
</entry>
@@ -82,8 +58,20 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="281">
<caret line="435" column="11" selection-start-line="435" selection-start-column="8" selection-end-line="435" selection-end-column="11" />
<state relative-caret-position="4067">
<caret line="452" column="71" selection-start-line="452" selection-start-column="71" selection-end-line="452" selection-end-column="71" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/StartGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="476">
<caret line="74" column="5" lean-forward="true" selection-start-line="67" selection-start-column="4" selection-end-line="74" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -92,10 +80,38 @@
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/LoanSharkGUI.java">
<entry file="file://$PROJECT_DIR$/src/BankGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="525">
<caret line="35" column="7" selection-start-line="35" selection-start-column="7" selection-end-line="35" selection-end-column="7" />
<state relative-caret-position="168">
<caret line="18" column="7" lean-forward="true" selection-start-line="18" selection-start-column="7" selection-end-line="18" selection-end-column="7" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/MainGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="504">
<caret line="25" column="28" lean-forward="true" selection-start-line="25" selection-start-column="28" selection-end-line="25" selection-end-column="28" />
<folding>
<element signature="e#1205#1206#0" expanded="true" />
<element signature="e#1233#1234#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1512">
<caret line="72" column="5" selection-start-line="72" selection-start-column="5" selection-end-line="72" selection-end-column="5" />
<folding>
<element signature="e#1049#1050#0" expanded="true" />
<element signature="e#1082#1083#0" expanded="true" />
<element signature="e#1114#1115#0" expanded="true" />
<element signature="e#1153#1154#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@@ -111,8 +127,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>destr</find>
<find>destro</find>
<find>hitco</find>
<find>game</find>
<find>numOf</find>
@@ -141,6 +155,8 @@
<find>warehouse</find>
<find>warehouse\n</find>
<find>run</find>
<find>player.</find>
<find>GUI()</find>
</findStrings>
<replaceStrings>
<replace>HP</replace>
@@ -149,10 +165,10 @@
<replace>shipWarfare.getHowMuchRun()</replace>
<replace>shipWarfare.isUserAttacks()</replace>
<replace>shipWarfare.getNumOfPeasantShips()</replace>
<replace>GUI(getPlayer())</replace>
</replaceStrings>
</component>
<component name="Git.Settings">
<option name="UPDATE_TYPE" value="MERGE" />
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
@@ -167,9 +183,13 @@
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
<option value="$PROJECT_DIR$/src/TravelGUI.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/TaipanShopGUI.java" />
<option value="$PROJECT_DIR$/src/BankGUI.java" />
<option value="$PROJECT_DIR$/src/MainGUI.java" />
<option value="$PROJECT_DIR$/src/GameEndGUI.java" />
<option value="$PROJECT_DIR$/src/LoanSharkGUI.java" />
<option value="$PROJECT_DIR$/src/ShipWarfareGUI.java" />
<option value="$PROJECT_DIR$/src/StartGUI.java" />
<option value="$PROJECT_DIR$/src/TaipanShopGUI.java" />
</list>
</option>
</component>
@@ -185,7 +205,7 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@@ -202,14 +222,14 @@
<select />
</subPane>
</pane>
<pane id="Scope" />
<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="1552351596289" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1553037216345" />
<property name="extract.method.default.visibility" value="private" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" />
<property name="project.structure.last.edited" value="Modules" />
@@ -325,6 +345,8 @@
<workItem from="1552241394045" duration="178000" />
<workItem from="1552254283748" duration="9473000" />
<workItem from="1552277298937" duration="10904000" />
<workItem from="1553035977312" duration="71000" />
<workItem from="1553036106507" duration="948000" />
</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>
@@ -617,13 +639,13 @@
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="86013000" />
<option name="totallyTimeSpent" value="87696000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18123667" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.19349681" />
<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" />
@@ -632,7 +654,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.9357143" />
<window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.08342362" />
<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" />
@@ -798,15 +820,8 @@
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java" />
<entry file="file://$PROJECT_DIR$/src/TravelGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="9114">
<caret line="459" column="33" selection-start-line="459" selection-start-column="33" selection-end-line="459" selection-end-column="33" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1764">
<caret line="84" column="44" selection-start-line="84" selection-start-column="44" selection-end-line="84" selection-end-column="44" />
<state relative-caret-position="546">
<caret line="41" column="42" selection-start-line="41" selection-start-column="42" selection-end-line="41" selection-end-column="42" />
</state>
</provider>
</entry>
@@ -817,49 +832,79 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/GameEndGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="42">
<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/MainGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="651">
<caret line="38" column="39" selection-start-line="38" selection-start-column="39" selection-end-line="38" selection-end-column="39" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/StartGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
<caret line="214" column="38" selection-start-line="214" selection-start-column="38" selection-end-line="214" selection-end-column="38" />
<state relative-caret-position="504">
<caret line="25" column="28" lean-forward="true" selection-start-line="25" selection-start-column="28" selection-end-line="25" selection-end-column="28" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1205#1206#0" expanded="true" />
<element signature="e#1233#1234#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="281">
<caret line="435" column="11" selection-start-line="435" selection-start-column="8" selection-end-line="435" selection-end-column="11" />
<state relative-caret-position="1512">
<caret line="72" column="5" selection-start-line="72" selection-start-column="5" selection-end-line="72" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1049#1050#0" expanded="true" />
<element signature="e#1082#1083#0" expanded="true" />
<element signature="e#1114#1115#0" expanded="true" />
<element signature="e#1153#1154#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/BankGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="168">
<caret line="18" column="7" lean-forward="true" selection-start-line="18" selection-start-column="7" selection-end-line="18" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShopGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-48">
<caret line="626" column="115" selection-start-line="626" selection-start-column="115" selection-end-line="626" selection-end-column="115" />
<state relative-caret-position="294">
<caret line="14" column="34" lean-forward="true" selection-start-line="14" selection-start-column="34" selection-end-line="14" selection-end-column="34" />
<folding>
<element signature="n#!!doc" expanded="true" />
<element signature="e#23112#23113#0" expanded="true" />
<element signature="e#23157#23158#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/GameEndGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="506">
<caret line="114" column="58" selection-start-line="114" selection-start-column="58" selection-end-line="114" selection-end-column="58" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/LoanSharkGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="622">
<caret line="160" column="58" lean-forward="true" selection-start-line="160" selection-start-column="58" selection-end-line="160" selection-end-column="58" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4067">
<caret line="452" column="71" selection-start-line="452" selection-start-column="71" selection-end-line="452" selection-end-column="71" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/StartGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="476">
<caret line="74" column="5" lean-forward="true" selection-start-line="67" selection-start-column="4" selection-end-line="74" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#23685#23686#0" expanded="true" />
<element signature="e#23730#23731#0" expanded="true" />
</folding>
</state>
</provider>
@@ -904,7 +949,7 @@
</state>
<state key="JdkListConfigurable.UI">
<settings>
<last-edited>1.8.0_201</last-edited>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
@@ -921,6 +966,7 @@
<option name="proportions">
<list>
<option value="0.2" />
<option value="0.6" />
</list>
</option>
</splitter-proportions>

View File

@@ -10,37 +10,16 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class BankGUI {
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;
}
public class BankGUI extends Player{
/**
* Class Constructor that takes in a type player as a parameter
* <p>
* //* @param player object of the class Player
*
* @param player object of the class Player
*/
public BankGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
setPlayer(playerDummy);
}
/**
@@ -61,10 +40,10 @@ public class BankGUI {
HBox hbx2 = new HBox(30);
VBox vbx1 = new VBox(30);
Label l1 = new Label("Player: " + player.getName());
Label l2 = new Label("Current Balance: " + player.getBank());
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: " + player.getMoney());
Label l4 = new Label("Current cash: " + getMoney());
Label l5 = new Label(" ");
Button b1 = new Button("Withdraw");
@@ -114,17 +93,17 @@ public class BankGUI {
try {
int withdraw = Integer.parseInt(txtField1.getText());
if(withdraw < 0){
l5.setText("Come on " + player.getName() + " are you trying to fool me??? \n No negative Numbers Please");
l5.setText("Come on " + getName() + " are you trying to fool me??? \n No negative Numbers Please");
}
else if (withdraw <= player.getBank()) {
player.setMoney(withdraw + player.getMoney());
player.setBank(player.getBank() - withdraw);
else if (withdraw <= getBank()) {
setMoney(withdraw + getMoney());
setBank(getBank() - withdraw);
}
else {
l5.setText("Sorry you cannot withdraw that much");
}
l2.setText("Current Balance: " + player.getBank());
l4.setText("Current cash: " + player.getMoney());
l2.setText("Current Balance: " + getBank());
l4.setText("Current cash: " + getMoney());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
@@ -146,14 +125,14 @@ public class BankGUI {
if(deposit < 0){
l5.setText("Nice Try!!! No negative Numbers Please");
}
else if (deposit <= player.getMoney()) {
player.setBank(deposit + player.getBank());
player.setMoney(player.getMoney() - deposit);
else if (deposit <= getMoney()) {
setBank(deposit + getBank());
setMoney(getMoney() - deposit);
} else {
l5.setText("Sorry you cannot deposit that much.$");
}
l2.setText("Current Balance: " + player.getBank());
l4.setText("Current cash: " + player.getMoney());
l2.setText("Current Balance: " + getBank());
l4.setText("Current cash: " + getMoney());
}
catch (Exception e) {
@@ -170,7 +149,7 @@ public class BankGUI {
b3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(player);
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
@@ -193,7 +172,7 @@ public class BankGUI {
* @param primaryStage the stage in which the scene may be run and switched to
*/
public void start(Stage primaryStage) {
BankGUI bank = new BankGUI(player);
BankGUI bank = new BankGUI(getPlayer());
bank.initializeBank(primaryStage);
primaryStage.show();
}

View File

@@ -12,7 +12,7 @@ import javafx.stage.Stage;
* GameEndGUI class, Initializes and displays the graphical interface for when you lose
*
*/
public class GameEndGUI {
public class GameEndGUI extends Player{
private Label title;
private VBox vBox;
@@ -20,11 +20,10 @@ public class GameEndGUI {
private Label gunsHeld;
private Label netWorth;
private BorderPane borderPane;
private Player player;
public GameEndGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
setPlayer(playerDummy);
}
/**
@@ -79,7 +78,7 @@ public class GameEndGUI {
/**
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
* */
if (player.getHP() <= 0) {
if (getHP() <= 0) {
title.setText("Game Over!");
} else {
title.setText("Congratulations!");
@@ -88,14 +87,14 @@ public class GameEndGUI {
/**
* Calculates the networth of the player by the end of the game
* */
netWorthInt = player.getMoney() + (player.getOpiumHeld() * 16000) + (player.getSilkHeld() * 160) + (player.getArmsHeld() * 160) + (player.getGeneralHeld() * 8);
netWorthInt += (player.getwOpium() * 16000) + (player.getwSilk() * 160) + (player.getwArms() * 160) + (player.getwGeneral() * 8);
netWorthInt -= player.getDebt();
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: " + player.getName());
gunsHeld.setText("Guns Held: " + player.getGuns());
firmName.setText("Firm Name: " + getName());
gunsHeld.setText("Guns Held: " + getGuns());
netWorth.setText("Net Worth: " + netWorthInt);
Scene root = new Scene(borderPane, 600, 480);
@@ -113,7 +112,7 @@ public class GameEndGUI {
* @param primaryStage the stage in which the scene may be run and switched to
*/
public void start(Stage primaryStage) {
GameEndGUI gameEndGUI = new GameEndGUI(player);
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(primaryStage);
primaryStage.show();
}

View File

@@ -10,39 +10,28 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class LoanSharkGUI {
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;
}
public class LoanSharkGUI extends Player {
/**
* Class Constructor that takes in a type player as a parameter
* <p>
* //* @param player object of the class Player
*
* @param player object of the class Player
*/
public LoanSharkGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
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");
@@ -53,9 +42,9 @@ public class LoanSharkGUI {
VBox vbx1 = new VBox(10);
//Declaring all Variables
Label l1 = new Label("Player: " + player.getName());
Label l2 = new Label("Current Debt " + player.getDebt());
Label l4 = new Label("Current cash: " + player.getMoney());
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(" ");
@@ -96,10 +85,10 @@ public class LoanSharkGUI {
try {
int loanAsk = Integer.parseInt(txtField1.getText());
if (loanAsk <= 2 * (player.getMoney() - player.getDebt()) && loanAsk >= 0) {
player.setDebt(player.getDebt() + loanAsk);
player.setMoney(player.getMoney() + loanAsk);
l4.setText("Current cash: " + player.getMoney());
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");
}
@@ -108,7 +97,7 @@ public class LoanSharkGUI {
}
l2.setText("Debt: " + player.getDebt());
l2.setText("Debt: " + getDebt());
} catch (Exception e) {
l5.setText("Please enter a valid value");
}
@@ -121,26 +110,26 @@ public class LoanSharkGUI {
// Set the event handler when the withdraw button is clicked
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
public void handle(ActionEvent event) {
try {
int returnAsk = Integer.parseInt(txtField1.getText());
if (returnAsk > player.getDebt()) {
if (returnAsk > getDebt()) {
l5.setText("You dont need to return that much");
}
else if (returnAsk <= player.getDebt() && returnAsk >= 0 && player.getMoney() >= returnAsk) {
player.setDebt(player.getDebt() - returnAsk);
player.setMoney(player.getMoney() - returnAsk);
l4.setText("Current cash: " + player.getMoney());
else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) {
setDebt(getDebt() - returnAsk);
setMoney(getMoney() - returnAsk);
l4.setText("Current cash: " + getMoney());
}
else if(player.getMoney() < returnAsk) {
l5.setText("Look " + player.getName() + ", you are being cheap!");
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: " + player.getDebt());
l2.setText("Debt: " + getDebt());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
@@ -152,7 +141,7 @@ public class LoanSharkGUI {
b3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(player);
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
@@ -169,20 +158,10 @@ public class LoanSharkGUI {
public void start(Stage primaryStage) {
LoanSharkGUI loan = new LoanSharkGUI(player);
LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
loan.initializeLoanShark(primaryStage);
primaryStage.show();
}
/**
* 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.
*/
}

View File

@@ -9,30 +9,6 @@ import javafx.stage.Stage;
*/
public class MainGUI extends Application {
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(TaipanShopGUI shop) {
shop.setPlayer(player);
shop.shop();
player = shop.getPlayer();
}
/**
* Updates main class with player data and starts the game.
@@ -45,7 +21,7 @@ public class MainGUI extends Application {
}
public void start(Stage primaryStage) throws Exception {
StartGUI start = new StartGUI(player);
StartGUI start = new StartGUI(new Player());
start.initializeStart(primaryStage);
primaryStage.show();
}

View File

@@ -5,8 +5,6 @@
*
*/
import java.util.Random;
public class Player {
private String name = "Taipan";
@@ -33,28 +31,7 @@ public class Player {
private int isPriceChanged = 0;
public Player() {
this.name = "Taipan";
this.bank = 0;
this.money = 0;
this.opiumHeld = 0;
this.silkHeld = 0;
this.generalHeld = 0;
this.armsHeld = 0;
this.location = 1;
this.guns = 0;
this.HP = 100;
this.debt = 0;
this.wOpium = 0;
this.wSilk = 0;
this.wGeneral = 0;
this.wArms = 0;
this.retire = false;
this.opiumPrice = 1600;
this.silkPrice = 1600;
this.armsPrice = 160;
this.generalPrice = 8;
this.cargoSpace = 60;
this.isPriceChanged = 0;
}
/**
@@ -63,6 +40,14 @@ public class Player {
* @param player object of the class Player
*/
public Player(Player player) {
setPlayer(player);
}
public Player getPlayer(){
return new Player(this);
}
public void setPlayer(Player player){
this.name = player.name;
this.bank = player.bank;
this.money = player.money;
@@ -84,6 +69,7 @@ public class Player {
this.generalPrice = player.generalPrice;
this.cargoSpace = player.cargoSpace;
this.isPriceChanged = player.isPriceChanged;
this.retire = player.retire;
}
/**

View File

@@ -19,10 +19,8 @@ import javafx.stage.Stage;
import java.util.Random;
public class ShipWarfareGUI {
public class ShipWarfareGUI extends Player{
private Player player = new Player();
private HBox hBox;
private Button fightButton;
private Button runButton;
@@ -39,17 +37,6 @@ public class ShipWarfareGUI {
private Button continueButton;
/**
* 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);
this.player = playerDummy;
}
private int numOfPeasantShips = 0;
private int numOfLittyShips = 0;
private boolean userAttacks = true;
@@ -59,24 +46,15 @@ public class ShipWarfareGUI {
private int counter = 0;
private String pirateName = "Liu Yen";
/**
* 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.
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @return returns player object
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public Player getPlayer() {
public ShipWarfareGUI(Player player) {
Player playerDummy = new Player(player);
return playerDummy;
setPlayer(playerDummy);
}
/**
@@ -103,16 +81,16 @@ public class ShipWarfareGUI {
int numOfShipsAttacking = 0;
Random randomValue = new Random();
if (player.getMoney() <= 100000) {
if (getMoney() <= 100000) {
//Minimum one ship will attack, maximum 20
numOfShipsAttacking = randomValue.nextInt(20) + 1;
} else if (player.getMoney() <= 200000) {
} else if (getMoney() <= 200000) {
//Minimum 30 Ships will attack, maximum 70
numOfShipsAttacking = randomValue.nextInt(40) + 31;
} else if (player.getMoney() <= 500000) {
} else if (getMoney() <= 500000) {
//Minimum 50 ships will attack, maximum 140
numOfShipsAttacking = randomValue.nextInt(90) + 51;
} else if (player.getMoney() >= 1000000) {
} else if (getMoney() >= 1000000) {
//Minimum 100 ships will attack, maximum 300 ships
numOfShipsAttacking = randomValue.nextInt(200) + 101;
}
@@ -196,9 +174,9 @@ public class ShipWarfareGUI {
//Player volley
//while (exitValue == 0) {
if (player.getGuns() > 0) {
if (getGuns() > 0) {
for (int j = 0; j < player.getGuns(); j++) {
for (int j = 0; j < getGuns(); j++) {
if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(2) + 1;
if (hitOrMiss == 2) {
@@ -230,7 +208,7 @@ public class ShipWarfareGUI {
exitValue = 1;
//break;
}
if (player.getGuns() > 0) {
if (getGuns() > 0) {
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) {
howMuchRun = randomValue.nextInt(15) + 1;
@@ -240,12 +218,12 @@ public class ShipWarfareGUI {
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
if (userAttacks == true) {
if (howMuchRun > 0) {
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, player.getName()));
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, player.getName())));
report.setText((String.format("Escaped %d of them %s!", howMuchRun, getName())));
}
}
@@ -255,47 +233,47 @@ public class ShipWarfareGUI {
shipsRemaining.setText(String.format("%d ships remaining and they look angry!", numOfPeasantShips));
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) {
player.setGuns(player.getGuns() - 1);
if (takeGunChance == 1 && getGuns() > 0) {
setGuns(getGuns() - 1);
gunFrustration = true;
} else {
if (numOfPeasantShips > 0) {
player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
setHP(getHP() - (1 + randomValue.nextInt(10)));
}
}
if (player.getHP() <= 0) {
if (getHP() <= 0) {
exitValue = 2;
//break;
}
if (gunFrustration == true) {
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", getGuns()));
} else {
gunsLeftOrTaken.setText(String.format("We still have %d guns left", player.getGuns()));
gunsLeftOrTaken.setText(String.format("We still have %d guns left", getGuns()));
}
HPLeft.setText(String.format("EEK, our current ship status is %d%% ", player.getHP()));
HPLeft.setText(String.format("EEK, our current ship status is %d%% ", getHP()));
if (userAttacks == false) {
userAttacks = true;
}
continueToFight.setText(String.format("Captain, what are your orders? (Click the fight button or the run button)", player.getGuns()));
continueToFight.setText(String.format("Captain, what are your orders? (Click the fight button or the run button)", getGuns()));
if (exitValue == 1) {
wipe();
chooseFightOrRun.setText(String.format("Ayy! We won and survived at %d%% ship status!", player.getHP()));
chooseFightOrRun.setText(String.format("Ayy! We won and survived at %d%% ship status!", getHP()));
calculateLoot = (startingPeasantShips * 100) + randomValue.nextInt(startingPeasantShips) * 200;
player.setMoney(player.getMoney() + calculateLoot);
setMoney(getMoney() + calculateLoot);
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
continueButton.setVisible(true);
return true;
} else if (exitValue == 2) {
GameEndGUI gameEndGUI = new GameEndGUI(player);
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(stage);
stage.show();
return true;
} else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
System.out.printf("We made it out at %d%% ship status!\n", getHP());
continueButton.setVisible(true);
return true;
}
@@ -414,7 +392,7 @@ public class ShipWarfareGUI {
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
TaipanShopGUI shop = new TaipanShopGUI(player);
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
@@ -460,7 +438,7 @@ public class ShipWarfareGUI {
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
TaipanShopGUI shop = new TaipanShopGUI(player);
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
@@ -472,7 +450,7 @@ public class ShipWarfareGUI {
} else {
completeWipe();
report.setText("Phew! Got away safely");
TaipanShopGUI shop = new TaipanShopGUI(player);
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();

View File

@@ -9,16 +9,15 @@ 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
*
*/
* 2019-03-10
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
* StartGUI class, Initializes and displays the start menu for Taipan
*
*/
public class StartGUI {
public class StartGUI extends Player{
private Player player;
private BorderPane borderPane = new BorderPane();
private HBox hBox = new HBox();
private TextField nameField = new TextField();
@@ -33,23 +32,12 @@ public class StartGUI {
private Label authors = new Label();
/**
* 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.
* Copy constructor.
* @param player object of the class Player
*/
public Player getPlayer() {
public StartGUI(Player player) {
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;
setPlayer(playerTemp);
}
/**
@@ -59,22 +47,12 @@ public class StartGUI {
*/
public void setFirm(String name) {
if (name.length() <= 22) {
player.setName(name);
super.setName(name);
} else {
player.setName("Taipan");
super.setName("Taipan");
}
}
/*
**
* Copy constructor.
* @param player object of the class Player
*/
public StartGUI(Player player) {
Player playerTemp = new Player(player);
this.player = playerTemp;
}
/**
* Initializes the Start GUI the game.
*
@@ -199,26 +177,26 @@ public class StartGUI {
@Override
public void handle(ActionEvent event) {
if (Start.getSelectedToggle() == cashChoice) {
player.setMoney(400);
player.setDebt(5000);
setMoney(400);
setDebt(5000);
}
if (Start.getSelectedToggle() == gunChoice) {
player.setGuns(5);
setGuns(5);
}
String response = nameField.getText();
// purely for testing purposes.
if (response.equalsIgnoreCase("Vikram")) {
player.setMoney(999999999);
player.setBank(999999999);
player.setGuns(999);
player.setHP(99999999);
player.setCargoSpace(Integer.MAX_VALUE);
setMoney(999999999);
setBank(999999999);
setGuns(999);
setHP(99999999);
setCargoSpace(Integer.MAX_VALUE);
}
setFirm(response);
TaipanShopGUI shop = new TaipanShopGUI(player);
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
//title.setText("SHOP PLACEHOLDER");

View File

@@ -20,8 +20,7 @@ import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.util.Random;
public class TaipanShopGUI {
private Player player;
public class TaipanShopGUI extends Player{
private Label firm = new Label();
private Label wItemsText = new Label();
private Label wItemSpaceText = new Label();
@@ -53,86 +52,64 @@ public class TaipanShopGUI {
*/
public TaipanShopGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
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) {
player.setRetire(true);
GameEndGUI gameEndGUI = new GameEndGUI(player);
setRetire(true);
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(stage);
stage.show();
}
/**
* 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;
}
/**
* this method is when the shop is accessed, randomizing the prices of all the items.
*/
public void updatePrices() {
String s = "\t" + player.getName() + ", the price of ";
String s = "\t" + getName() + ", the price of ";
double value = 80 * Math.random();
Random rand = new Random();
player.setOpiumPrice((rand.nextInt(201) + 60) * 100);
player.setSilkPrice((rand.nextInt(201) + 60) * 10);
player.setArmsPrice((rand.nextInt(21) + 6) * 10);
player.setGeneralPrice((rand.nextInt(17) + 4));
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) {
player.setOpiumPrice(player.getOpiumPrice() / 5);
textOut.setText(s + "Opium has dropped to " + player.getOpiumPrice() + "!!!\n" + textOut.getText());
setOpiumPrice(getOpiumPrice() / 5);
textOut.setText(s + "Opium has dropped to " + getOpiumPrice() + "!!!\n" + textOut.getText());
} else {
player.setOpiumPrice(player.getOpiumPrice() * 5);
textOut.setText(s + "Opium has risen to " + player.getOpiumPrice() + "!!!\n" + textOut.getText());
setOpiumPrice(getOpiumPrice() * 5);
textOut.setText(s + "Opium has risen to " + getOpiumPrice() + "!!!\n" + textOut.getText());
}
} else if (value < 4) {
if (value < 3) {
player.setSilkPrice(player.getSilkPrice() / 5);
textOut.setText(s + "Silk has dropped to " + player.getSilkPrice() + "!!!\n" + textOut.getText());
setSilkPrice(getSilkPrice() / 5);
textOut.setText(s + "Silk has dropped to " + getSilkPrice() + "!!!\n" + textOut.getText());
} else {
player.setSilkPrice(player.getSilkPrice() * 5);
textOut.setText(s + "Silk has risen to " + player.getSilkPrice() + "!!!\n" + textOut.getText());
setSilkPrice(getSilkPrice() * 5);
textOut.setText(s + "Silk has risen to " + getSilkPrice() + "!!!\n" + textOut.getText());
}
} else if (value < 6) {
if (value < 3) {
player.setArmsPrice(player.getArmsPrice() / 5);
textOut.setText(s + "Arms has dropped to " + player.getArmsPrice() + "!!!\n" + textOut.getText());
setArmsPrice(getArmsPrice() / 5);
textOut.setText(s + "Arms has dropped to " + getArmsPrice() + "!!!\n" + textOut.getText());
} else {
player.setArmsPrice(player.getArmsPrice() * 5);
textOut.setText(s + "Arms has risen to " + player.getArmsPrice() + "!!!\n" + textOut.getText());
setArmsPrice(getArmsPrice() * 5);
textOut.setText(s + "Arms has risen to " + getArmsPrice() + "!!!\n" + textOut.getText());
}
} else {
if (value < 7) {
player.setGeneralPrice(1);
setGeneralPrice(1);
textOut.setText(s + "General Cargo has dropped to 1!!!\n" + textOut.getText());
} else {
player.setGeneralPrice(player.getGeneralPrice() * 5);
textOut.setText(s + "General Cargo has risen to " + player.getGeneralPrice() + "!!!\n" + textOut.getText());
setGeneralPrice(getGeneralPrice() * 5);
textOut.setText(s + "General Cargo has risen to " + getGeneralPrice() + "!!!\n" + textOut.getText());
}
}
}
@@ -142,7 +119,7 @@ public class TaipanShopGUI {
* 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", player.getName(), player.getOpiumPrice(), player.getSilkPrice(), player.getArmsPrice(), player.getGeneralPrice()));
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()));
}
@@ -176,7 +153,7 @@ public class TaipanShopGUI {
silkButton.setText("Silk");
armsButton.setText("Arms");
generalButton.setText("General");
if (player.getLocation() != 1) {
if (getLocation() != 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(false);
@@ -190,7 +167,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false);
retireButton.setVisible(false);
}
if (player.getBank() + player.getMoney() - player.getDebt() < 1000000 && player.getLocation() == 1) {
if (getBank() + getMoney() - getDebt() < 1000000 && getLocation() == 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -203,7 +180,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false);
armsButton.setVisible(false);
retireButton.setVisible(false);
} else if (player.getLocation() == 1) {
} else if (getLocation() == 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -240,64 +217,64 @@ public class TaipanShopGUI {
String originalDialogue = textOut.getText();
int num = Integer.parseInt(numberInput.getText().replace(" ", ""));
if (buyButton.getText().contains(".")) {
if (opiumButton.getText().contains(".") && num <= player.getMoney() / player.getOpiumPrice() && num >= 0) {
player.setMoney(player.getMoney() - num * player.getOpiumPrice());
player.setOpiumHeld(player.getOpiumHeld() + num);
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" + player.getName() + ", you can't afford that!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
} else if (silkButton.getText().contains(".") && num <= player.getMoney() / player.getOpiumPrice() && num >= 0) {
player.setSilkHeld(player.getSilkHeld() + num);
player.setMoney(player.getMoney() - num * player.getOpiumPrice());
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" + player.getName() + ", you can't afford that!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
} else if (armsButton.getText().contains(".") && num <= player.getMoney() / player.getArmsPrice() && num >= 0) {
player.setArmsHeld(player.getArmsHeld() + num);
player.setMoney(player.getMoney() - num * player.getArmsPrice());
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" + player.getName() + ", you can't afford that!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
} else if (generalButton.getText().contains(".") && num <= player.getMoney() / player.getGeneralPrice() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num * player.getGeneralPrice());
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" + player.getName() + ", you can't afford that!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (generalButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
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 <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld() - num);
player.setMoney(player.getMoney() + num * player.getOpiumPrice());
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" + player.getName() + ", you don't have that many to sell!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
} else if (silkButton.getText().contains(".") && num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld() - num);
player.setMoney(player.getMoney() + num * player.getOpiumPrice());
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" + player.getName() + ", you don't have that many to sell!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
} else if (armsButton.getText().contains(".") && num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld() - num);
player.setMoney(player.getMoney() + num * player.getArmsPrice());
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" + player.getName() + ", you don't have that many to sell!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
} else if (generalButton.getText().contains(".") && num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld() - num);
player.setMoney(player.getMoney() + num * player.getGeneralPrice());
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" + player.getName() + ", you don't have that many to sell!");
textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else {
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
@@ -470,7 +447,7 @@ public class TaipanShopGUI {
*/
@Override
public void handle(ActionEvent event) {
WarehouseGUI warehouseGUI = new WarehouseGUI(player);
WarehouseGUI warehouseGUI = new WarehouseGUI(getPlayer());
warehouseGUI.initializeWarehouse(stage);
stage.show();
}
@@ -509,8 +486,8 @@ public class TaipanShopGUI {
*/
@Override
public void handle(ActionEvent event) {
player.setIsPriceChanged(1);
TravelGUI travelGUI = new TravelGUI(player);
setIsPriceChanged(1);
TravelGUI travelGUI = new TravelGUI(getPlayer());
travelGUI.initializeTravel(stage);
stage.show();
//System.out.println("PLACEHOLDER FOR TRAVEL");
@@ -554,9 +531,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / player.getOpiumPrice());
extraText = String.format(" (You can afford %d)", getMoney() / getOpiumPrice());
} else {
extraText = String.format(" (You have %d)", player.getOpiumHeld());
extraText = String.format(" (You have %d)", getOpiumHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Opium?" + extraText);
}
@@ -581,9 +558,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / player.getSilkPrice());
extraText = String.format(" (You can afford %d)", getMoney() / getSilkPrice());
} else {
extraText = String.format(" (You have %d)", player.getSilkHeld());
extraText = String.format(" (You have %d)", getSilkHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Silk?" + extraText);
}
@@ -606,9 +583,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / player.getArmsPrice());
extraText = String.format(" (You can afford %d)", getMoney() / getArmsPrice());
} else {
extraText = String.format(" (You have %d)", player.getArmsHeld());
extraText = String.format(" (You have %d)", getArmsHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Arms?" + extraText);
}
@@ -635,9 +612,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / player.getGeneralPrice());
extraText = String.format(" (You can afford %d)", getMoney() / getGeneralPrice());
} else {
extraText = String.format(" (You have %d)", player.getGeneralHeld());
extraText = String.format(" (You have %d)", getGeneralHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of General Cargo?" + extraText);
}
@@ -769,7 +746,7 @@ public class TaipanShopGUI {
// general updates to the buttons, user stats/inventory, and text.
buttonSetup("reset");
if(player.getIsPriceChanged() == 0 || player.getIsPriceChanged() == 2){
if(getIsPriceChanged() == 0 || getIsPriceChanged() == 2){
updatePrices();
}
defaultTextOut();
@@ -783,7 +760,7 @@ public class TaipanShopGUI {
*/
public String getStringLocation() {
String location;
switch (player.getLocation()) {
switch (getLocation()) {
case 1:
location = "Hong Kong";
break;
@@ -819,7 +796,7 @@ public class TaipanShopGUI {
*/
public String shipStatusString() {
String shipStatus;
switch (player.getHP() / 10) {
switch (getHP() / 10) {
case 10:
shipStatus = "Mint Condition";
break;
@@ -864,22 +841,22 @@ public class TaipanShopGUI {
* updates the text associated with the user's inventory.
*/
public void updateStage() {
firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation()));
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));
int itemsInWarehouse = player.getwOpium() + player.getwGeneral() + player.getwArms() + player.getwSilk();
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 = player.getCargoSpace() - player.getSilkHeld() - player.getOpiumHeld() - player.getGeneralHeld() - player.getArmsHeld() - 10 * player.getGuns();
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 ", player.getGuns()));
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", player.getOpiumHeld(), player.getSilkHeld(), player.getArmsHeld(), player.getGeneralHeld()));
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", player.getDebt(), shipStatusString(), player.getHP()));
cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
bankText.setText(String.format("Bank: $%,d", player.getBank()));
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,8 +1,8 @@
/**
* TravelGUI is the class in which takes the player from location to location
*
* Author: Harkamal Randhawa
*/
* 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;
@@ -16,8 +16,7 @@ import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import java.util.Random;
public class TravelGUI{
private Player player;
public class TravelGUI extends Player{
private TaipanShopGUI shop;
private Label firm = new Label();
private Label wItemsText = new Label();
@@ -41,7 +40,6 @@ public class TravelGUI{
private Boolean stormScene = false;
private Boolean sceneContinue = false;
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
@@ -50,7 +48,7 @@ public class TravelGUI{
public TravelGUI(Player player) {
Player playerDummy = new Player(player);
this.shop = new TaipanShopGUI(player);
this.player = playerDummy;
setPlayer(playerDummy);
}
/**
@@ -166,7 +164,7 @@ public class TravelGUI{
//Goes back to shop
quitButton.setOnAction(event -> {
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player);
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
});
@@ -174,12 +172,12 @@ public class TravelGUI{
//Continues on to either shop or shipwarfare
continueButton.setOnAction(event -> {
if(peasantShipScene){
ShipWarfareGUI ship = new ShipWarfareGUI(player);
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
ship.initializeShip(stage);
stage.show();
}
else if(shopScene){
TaipanShopGUI shop = new TaipanShopGUI(player);
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
@@ -199,43 +197,43 @@ public class TravelGUI{
}
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())){
//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 != player.getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
hasTraveled = seaAtlas(response);
randomEventSea(response,stage);
player.setBank((int) (player.getBank() * 1.01));
player.setDebt((int) (player.getDebt() * 1.01));
player.setIsPriceChanged(2);
//shopScene = false;
//stormScene = false;
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 == player.getLocation()){
textOut.setText(" " + "You're already here " + player.getName() + "\n");
}
else{
textOut.setText(" " + player.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?");
} else{
if(response == getLocation()){
textOut.setText(" " + "You're already here " + getName() + "\n");
}
} catch (Exception e) {
textOut.setText(" " + "Sorry, " + player.getName() + " could you say that again?");
}
if (hasTraveled) {
continueButton.setVisible(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
shopScene = true;
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);
quitButton.setVisible(false);
numberInput.setVisible(false);
shopScene = true;
}
}
else if (player.getCargoSpace() < (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
textOut.setText(" "+player.getName() + " the cargo is too heavy! We can't set sail!");
}
}
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);
@@ -338,34 +336,34 @@ public class TravelGUI{
switch (locationOfTravel) {
case 1:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong");
player.setLocation(1);
setLocation(1);
return true;
case 2:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai");
player.setLocation(2);
setLocation(2);
return true;
case 3:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki");
player.setLocation(3);
setLocation(3);
return true;
case 4:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon");
player.setLocation(4);
setLocation(4);
return true;
case 5:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila");
player.setLocation(5);
setLocation(5);
return true;
case 6:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore");
player.setLocation(6);
setLocation(6);
return true;
case 7:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia");
player.setLocation(7);
setLocation(7);
return true;
default:
textOut.setText(" " + "Sorry but could you say that again " + player.getName() + "?");
textOut.setText(" " + "Sorry but could you say that again " + getName() + "?");
return false;
}
}
@@ -383,7 +381,7 @@ public class TravelGUI{
continueButton.setVisible(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
textOut.setText(" We see a ship on the horizon " + player.getName() + "; Prepare for combat!");
textOut.setText(" We see a ship on the horizon " + getName() + "; Prepare for combat!");
peasantShipScene = true;
}else if (randGenNum == 2) {
disaster(locationOfTravel);
@@ -400,14 +398,14 @@ public class TravelGUI{
**/
private void disaster(int locationOfTravel) {
//Tells player that there is a storm approaching.
textOut.setText(" " + "Storm " + player.getName() + "! ");
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 " + player.getName() + "!");
textOut.setText(textOut.getText() + "\n " + "We got through the storm " + getName() + "!");
}else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
@@ -426,7 +424,7 @@ public class TravelGUI{
*/
public String getStringLocation(){
String location;
switch(player.getLocation()){
switch(getLocation()){
case 1: location = "Hong Kong"; break;
case 2: location = "Shanghai"; break;
case 3: location = "Nagasaki"; break;
@@ -446,7 +444,7 @@ public class TravelGUI{
*/
public String shipStatusString(){
String shipStatus;
switch(player.getHP()/10){
switch(getHP()/10){
case 10: shipStatus = "Mint Condition"; break;
case 9: shipStatus = "Near Perfect"; break;
case 8: shipStatus = "Great"; break;
@@ -467,21 +465,21 @@ public class TravelGUI{
* updates the text associated with the user's inventory.
*/
public void updateStage(){
firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation()));
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));
int itemsInWarehouse = player.getwOpium()+player.getwGeneral()+player.getwArms()+player.getwSilk();
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 = player.getCargoSpace()-player.getSilkHeld()-player.getOpiumHeld()-player.getGeneralHeld()-player.getArmsHeld()-10*player.getGuns();
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 ", player.getGuns()));
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", player.getOpiumHeld(), player.getSilkHeld(), player.getArmsHeld(), player.getGeneralHeld()));
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", player.getDebt(), shipStatusString(), player.getHP()));
cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
bankText.setText(String.format("Bank: %d", player.getBank()));
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

@@ -10,14 +10,12 @@ import javafx.scene.text.Text;
import javafx.stage.Stage;
/**
* 2019-03-10
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
* WarehouseGUI class, Initializes and displays the graphical interface for the warehouse in Taipan
*
*/
public class WarehouseGUI {
private Player player;
* 2019-03-10
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
* WarehouseGUI class, Initializes and displays the graphical interface for the warehouse in Taipan
*
*/
public class WarehouseGUI extends Player{
private Text title;
private HBox hBox;
@@ -56,27 +54,7 @@ public class WarehouseGUI {
*/
public WarehouseGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* Setter method for the Player object, player
*
* @param player an object of type Player
*/
public void setPlayer(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/**
* Getter method for the Player object, player.
*
* @return returns a copy of the Player object, player
*/
public Player getPlayer() {
Player playerDummy = new Player(player);
return playerDummy;
setPlayer(playerDummy);
}
/**
@@ -179,33 +157,33 @@ public class WarehouseGUI {
int withdraw = Integer.parseInt(textIn.getText());
updateLabels();
if (opium.isSelected()) {
if (player.getwOpium() >= withdraw) {
player.setwOpium(player.getwOpium() - withdraw);
player.setOpiumHeld(player.getOpiumHeld() + withdraw);
if (getwOpium() >= withdraw) {
setwOpium(getwOpium() - withdraw);
setOpiumHeld(getOpiumHeld() + withdraw);
} else {
title.setText("You don't have that much opium stored in the warehouse!");
}
}
if (silk.isSelected()) {
if (player.getwSilk() >= withdraw) {
player.setwSilk(player.getwSilk() - withdraw);
player.setSilkHeld(player.getSilkHeld() + withdraw);
if (getwSilk() >= withdraw) {
setwSilk(getwSilk() - withdraw);
setSilkHeld(getSilkHeld() + withdraw);
} else {
title.setText("You don't have that much silk stored in the warehouse!");
}
}
if (arms.isSelected()) {
if (player.getwArms() >= withdraw) {
player.setwArms(player.getwArms() - withdraw);
player.setArmsHeld(player.getArmsHeld() + withdraw);
if (getwArms() >= withdraw) {
setwArms(getwArms() - withdraw);
setArmsHeld(getArmsHeld() + withdraw);
} else {
title.setText("You don't have that much arms stored in the warehouse!");
}
}
if (general.isSelected()) {
if (player.getwGeneral() >= withdraw) {
player.setwGeneral(player.getwGeneral() - withdraw);
player.setGeneralHeld(player.getGeneralHeld() + withdraw);
if (getwGeneral() >= withdraw) {
setwGeneral(getwGeneral() - withdraw);
setGeneralHeld(getGeneralHeld() + withdraw);
} else {
title.setText("You don't have that much general stored in the warehouse!");
}
@@ -225,33 +203,33 @@ public class WarehouseGUI {
updateLabels();
int deposit = Integer.parseInt(textIn.getText());
if (opium.isSelected()) {
if (player.getOpiumHeld() >= deposit) {
player.setwOpium(player.getwOpium() + deposit);
player.setOpiumHeld(player.getOpiumHeld() - deposit);
if (getOpiumHeld() >= deposit) {
setwOpium(getwOpium() + deposit);
setOpiumHeld(getOpiumHeld() - deposit);
} else {
title.setText("You don't have that much opium stored in the ship!");
}
}
if (silk.isSelected()) {
if (player.getwSilk() >= deposit) {
player.setwSilk(player.getwSilk() + deposit);
player.setSilkHeld(player.getSilkHeld() - deposit);
if (getwSilk() >= deposit) {
setwSilk(getwSilk() + deposit);
setSilkHeld(getSilkHeld() - deposit);
} else {
title.setText("You don't have that much silk stored in the ship!");
}
}
if (arms.isSelected()) {
if (player.getwArms() >= deposit) {
player.setwArms(player.getwArms() + deposit);
player.setArmsHeld(player.getArmsHeld() - deposit);
if (getwArms() >= deposit) {
setwArms(getwArms() + deposit);
setArmsHeld(getArmsHeld() - deposit);
} else {
title.setText("You don't have that much arms stored in the ship!");
}
}
if (general.isSelected()) {
if (player.getwGeneral() >= deposit) {
player.setwGeneral(player.getwGeneral() + deposit);
player.setGeneralHeld(player.getGeneralHeld() - deposit);
if (getwGeneral() >= deposit) {
setwGeneral(getwGeneral() + deposit);
setGeneralHeld(getGeneralHeld() - deposit);
} else {
title.setText("You don't have that much general stored in the ship!");
}
@@ -618,7 +596,7 @@ public class WarehouseGUI {
* @param primaryStage object of type Stage
*/
public void start(Stage primaryStage) {
WarehouseGUI warehouseGUI = new WarehouseGUI(player);
WarehouseGUI warehouseGUI = new WarehouseGUI(getPlayer());
warehouseGUI.initializeWarehouse(primaryStage);
primaryStage.show();
}
@@ -628,14 +606,14 @@ public class WarehouseGUI {
* can be safely stored without holing space on the ship!
*/
public void updateLabels() {
generalPlayer.setText("General: " + player.getGeneralHeld());
armsPlayer.setText("Arms: " + player.getArmsHeld());
silkPlayer.setText("Silk: " + player.getSilkHeld());
opiumPlayer.setText("Opium: " + player.getOpiumHeld());
generalPlayer.setText("General: " + getGeneralHeld());
armsPlayer.setText("Arms: " + getArmsHeld());
silkPlayer.setText("Silk: " + getSilkHeld());
opiumPlayer.setText("Opium: " + getOpiumHeld());
generalWarehouse.setText("General: " + player.getwGeneral());
armsWarehouse.setText("Arms: " + player.getwArms());
silkWarehouse.setText("Silk: " + player.getwSilk());
opiumWarehouse.setText("Opium: " + player.getwOpium());
generalWarehouse.setText("General: " + getwGeneral());
armsWarehouse.setText("Arms: " + getwArms());
silkWarehouse.setText("Silk: " + getwSilk());
opiumWarehouse.setText("Opium: " + getwOpium());
}
}