Merge remote-tracking branch 'origin/master'

This commit is contained in:
2019-03-10 23:50:56 -06:00
5 changed files with 199 additions and 66 deletions

43
.idea/workspace.xml generated
View File

@@ -19,8 +19,8 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="7290"> <state relative-caret-position="379">
<caret line="486" column="32" lean-forward="true" selection-start-line="486" selection-start-column="32" selection-end-line="486" selection-end-column="32" /> <caret line="76" column="6" lean-forward="true" selection-start-line="76" selection-start-column="6" selection-end-line="76" selection-end-column="6" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
</folding> </folding>
@@ -40,7 +40,7 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/TaipanShopGUI.java"> <entry file="file://$PROJECT_DIR$/src/TaipanShopGUI.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="810"> <state relative-caret-position="662">
<caret line="69" column="16" selection-start-line="69" selection-start-column="16" selection-end-line="69" selection-end-column="16" /> <caret line="69" column="16" selection-start-line="69" selection-start-column="16" selection-end-line="69" selection-end-column="16" />
</state> </state>
</provider> </provider>
@@ -172,7 +172,7 @@
<property name="ChangesTree.GroupingKeys" value="" /> <property name="ChangesTree.GroupingKeys" value="" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1552280276915" /> <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1552280591238" />
<property name="extract.method.default.visibility" value="private" /> <property name="extract.method.default.visibility" value="private" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" />
<property name="project.structure.last.edited" value="Modules" /> <property name="project.structure.last.edited" value="Modules" />
@@ -287,7 +287,7 @@
<workItem from="1552240770629" duration="40000" /> <workItem from="1552240770629" duration="40000" />
<workItem from="1552241394045" duration="178000" /> <workItem from="1552241394045" duration="178000" />
<workItem from="1552254283748" duration="9473000" /> <workItem from="1552254283748" duration="9473000" />
<workItem from="1552277298937" duration="2115000" /> <workItem from="1552277298937" duration="2427000" />
</task> </task>
<task id="LOCAL-00001" summary="This should fix the ShipWarfare file and bring it up to date with the rest of the file."> <task id="LOCAL-00001" summary="This should fix the ShipWarfare file and bring it up to date with the rest of the file.">
<created>1550458470138</created> <created>1550458470138</created>
@@ -527,11 +527,18 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1552279406066</updated> <updated>1552279406066</updated>
</task> </task>
<option name="localTasksCounter" value="35" /> <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>
<option name="localTasksCounter" value="36" />
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="75188000" /> <option name="totallyTimeSpent" value="75500000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="6" y="26" width="1189" height="652" extended-state="0" /> <frame x="6" y="26" width="1189" height="652" extended-state="0" />
@@ -634,7 +641,6 @@
<ignored-roots> <ignored-roots>
<path value="$PROJECT_DIR$" /> <path value="$PROJECT_DIR$" />
</ignored-roots> </ignored-roots>
<MESSAGE value="Added time stuff to Shipwarfare GUI" />
<MESSAGE value="Nitified of getting attacked" /> <MESSAGE value="Nitified of getting attacked" />
<MESSAGE value="Notified of getting attacked" /> <MESSAGE value="Notified of getting attacked" />
<MESSAGE value="Added fight stuff" /> <MESSAGE value="Added fight stuff" />
@@ -659,7 +665,8 @@
<MESSAGE value="Completed ShipWarfareGUI" /> <MESSAGE value="Completed ShipWarfareGUI" />
<MESSAGE value="Probably should upload" /> <MESSAGE value="Probably should upload" />
<MESSAGE value="Fixed ShipWarfare bug about one-shotting." /> <MESSAGE value="Fixed ShipWarfare bug about one-shotting." />
<option name="LAST_COMMIT_MESSAGE" value="Fixed ShipWarfare bug about one-shotting." /> <MESSAGE value="Completed javadocs for shipwarfare GUI" />
<option name="LAST_COMMIT_MESSAGE" value="Completed javadocs for shipwarfare GUI" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="uml://JAVA/ShipWarfare"> <entry file="uml://JAVA/ShipWarfare">
@@ -746,13 +753,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShopGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="810">
<caret line="69" column="16" selection-start-line="69" selection-start-column="16" selection-end-line="69" selection-end-column="16" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/MainGUI.java"> <entry file="file://$PROJECT_DIR$/src/MainGUI.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="780"> <state relative-caret-position="780">
@@ -774,10 +774,17 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShopGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="662">
<caret line="69" column="16" selection-start-line="69" selection-start-column="16" selection-end-line="69" selection-end-column="16" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="7290"> <state relative-caret-position="379">
<caret line="486" column="32" lean-forward="true" selection-start-line="486" selection-start-column="32" selection-end-line="486" selection-end-column="32" /> <caret line="76" column="6" lean-forward="true" selection-start-line="76" selection-start-column="6" selection-end-line="76" selection-end-column="6" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
</folding> </folding>

View File

@@ -9,6 +9,7 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.util.Random; import java.util.Random;
public class ShipWarfareGUI { public class ShipWarfareGUI {
@@ -31,21 +32,16 @@ public class ShipWarfareGUI {
private Button continueButton; private Button continueButton;
/**
/* * constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
/** *
* 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.
* */
* @param player is a Player object that will be copied and the player instance variable is set to the copy. public ShipWarfareGUI(Player player) {
*/
public ShipWarfareGUI(Player player){
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
//public static void main(String args[]) {
// launch(args);
//}
private int numOfPeasantShips = 0; private int numOfPeasantShips = 0;
private int numOfLittyShips = 0; private int numOfLittyShips = 0;
@@ -58,6 +54,7 @@ public class ShipWarfareGUI {
/** /**
* setter method for player * setter method for player
*
* @param player object of the class Player * @param player object of the class Player
*/ */
public void setPlayer(Player player) { public void setPlayer(Player player) {
@@ -67,6 +64,7 @@ public class ShipWarfareGUI {
/** /**
* getter method for obtaining a player object. * getter method for obtaining a player object.
*
* @return returns player object * @return returns player object
*/ */
public Player getPlayer() { public Player getPlayer() {
@@ -76,12 +74,13 @@ public class ShipWarfareGUI {
/** /**
* setter method that takes in an integer as an argument * setter method that takes in an integer as an argument
*
* @param numOfPeasantShips the number of ships to be used in the peasant fleet attack * @param numOfPeasantShips the number of ships to be used in the peasant fleet attack
*/ */
public void setNumOfPeasantShips(int numOfPeasantShips){ public void setNumOfPeasantShips(int numOfPeasantShips) {
counter1++; counter1++;
this.numOfPeasantShips = numOfPeasantShips; this.numOfPeasantShips = numOfPeasantShips;
if(counter1==1) { if (counter1 == 1) {
startingPeasantShips = numOfPeasantShips; startingPeasantShips = numOfPeasantShips;
} }
@@ -89,6 +88,7 @@ public class ShipWarfareGUI {
/** /**
* The number of ships that attack is based on the amount of money one has on hand * The number of ships that attack is based on the amount of money one has on hand
*
* @return the number of ships which will attack * @return the number of ships which will attack
*/ */
public int numOfShips() { public int numOfShips() {
@@ -116,6 +116,7 @@ public class ShipWarfareGUI {
/** /**
* One in two chance of running away * One in two chance of running away
*
* @return true if the user is allowed to run, false if not, the "default" is false * @return true if the user is allowed to run, false if not, the "default" is false
*/ */
public boolean runFromShips() { public boolean runFromShips() {
@@ -133,7 +134,7 @@ public class ShipWarfareGUI {
/** /**
* Sets most of the labels invisible except for the "fight or run" label * Sets most of the labels invisible except for the "fight or run" label
*/ */
public void wipe(){ public void wipe() {
title.setVisible(false); title.setVisible(false);
runAwayOrLeft.setVisible(false); runAwayOrLeft.setVisible(false);
shipsRemaining.setVisible(false); shipsRemaining.setVisible(false);
@@ -159,6 +160,7 @@ public class ShipWarfareGUI {
/** /**
* The user faces off against the peasant ships and either prevails, dies, or runs away * 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 * @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the delay * @throws Exception in case of errors due to the delay
*/ */
@@ -207,7 +209,8 @@ public class ShipWarfareGUI {
} else { } else {
//continue; //continue;
} }
}if(userAttacks==true) { }
if (userAttacks == true) {
report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter)); report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
} }
} else { } else {
@@ -235,7 +238,7 @@ public class ShipWarfareGUI {
} }
} else { } else {
report.setText((String.format("Escaped %d of them %s!", howMuchRun,player.getName()))); report.setText((String.format("Escaped %d of them %s!", howMuchRun, player.getName())));
} }
} }
@@ -249,7 +252,7 @@ public class ShipWarfareGUI {
player.setGuns(player.getGuns() - 1); player.setGuns(player.getGuns() - 1);
gunFrustration = true; gunFrustration = true;
} else { } else {
if (numOfPeasantShips>0) { if (numOfPeasantShips > 0) {
player.setHP(player.getHP() - (1 + randomValue.nextInt(10))); player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
} }
@@ -269,12 +272,12 @@ public class ShipWarfareGUI {
userAttacks = true; userAttacks = true;
} }
continueToFight.setText(String.format("Shall we continue to fight? (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)", player.getGuns()));
if (exitValue == 1) { if (exitValue == 1) {
wipe(); 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!", player.getHP()));
calculateLoot = (startingPeasantShips *100) + randomValue.nextInt(startingPeasantShips) *200; calculateLoot = (startingPeasantShips * 100) + randomValue.nextInt(startingPeasantShips) * 200;
player.setMoney(player.getMoney() + calculateLoot); player.setMoney(player.getMoney() + calculateLoot);
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot)); report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
continueButton.setVisible(true); continueButton.setVisible(true);
@@ -294,11 +297,12 @@ public class ShipWarfareGUI {
/** /**
* Sets up the graphical part of ShipWarfare and includes all logic for the class * Sets up the graphical part of ShipWarfare and includes all logic for the class
*
* @param stage sets the stage to which we will execute the scene of the ShipWarfare class * @param stage sets the stage to which we will execute the scene of the ShipWarfare class
* @return stage so that another class can switch to the stage * @return stage so that another class can switch to the stage
*/ */
public Stage initializeShip(Stage stage){ public Stage initializeShip(Stage stage) {
setNumOfPeasantShips(numOfShips()); setNumOfPeasantShips(numOfShips());
BorderPane BorderPane = new BorderPane(); BorderPane BorderPane = new BorderPane();
@@ -324,7 +328,6 @@ public class ShipWarfareGUI {
continueButton.setVisible(false); continueButton.setVisible(false);
BorderPane.setPrefHeight(400.0); BorderPane.setPrefHeight(400.0);
BorderPane.setPrefWidth(600.0); BorderPane.setPrefWidth(600.0);
hBox.setAlignment(javafx.geometry.Pos.CENTER); hBox.setAlignment(javafx.geometry.Pos.CENTER);
@@ -335,7 +338,7 @@ public class ShipWarfareGUI {
title.setAlignment(javafx.geometry.Pos.TOP_CENTER); title.setAlignment(javafx.geometry.Pos.TOP_CENTER);
title.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER); title.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
title.setId("Label1"); title.setId("Label1");
title.setText(String.format("%d ships attacking. Would you like to Fight or Run?",numOfPeasantShips)); title.setText(String.format("%d ships attacking. Would you like to Fight or Run?", numOfPeasantShips));
title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0)); title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
continueButton.setMnemonicParsing(false); continueButton.setMnemonicParsing(false);
@@ -351,7 +354,8 @@ public class ShipWarfareGUI {
runButton.setId("Button2"); runButton.setId("Button2");
runButton.setMnemonicParsing(false); runButton.setMnemonicParsing(false);
BorderPane.setBottom(hBox);runButton.setText("Run"); BorderPane.setBottom(hBox);
runButton.setText("Run");
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER); vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
@@ -391,7 +395,7 @@ public class ShipWarfareGUI {
counter++; counter++;
chooseFightOrRun.setText("Ohh, Fight ehh?"); chooseFightOrRun.setText("Ohh, Fight ehh?");
try { try {
if (destroyPeasantShipsOrEscape(stage)){ if (destroyPeasantShipsOrEscape(stage)) {
completeWipe(); completeWipe();
continueButton.setVisible(true); continueButton.setVisible(true);
fightButton.setVisible(false); fightButton.setVisible(false);
@@ -437,7 +441,7 @@ public class ShipWarfareGUI {
chooseFightOrRun.setVisible(false); chooseFightOrRun.setVisible(false);
report.setText(("Couldn't run away")); report.setText(("Couldn't run away"));
try { try {
if(destroyPeasantShipsOrEscape(stage)==true){ if (destroyPeasantShipsOrEscape(stage) == true) {
completeWipe(); completeWipe();
continueButton.setVisible(true); continueButton.setVisible(true);
fightButton.setVisible(false); fightButton.setVisible(false);
@@ -467,7 +471,7 @@ public class ShipWarfareGUI {
} }
if (counter>=2){ if (counter >= 2) {
title.setVisible(false); title.setVisible(false);
} }
} }
@@ -484,9 +488,10 @@ public class ShipWarfareGUI {
/** /**
* sets scene and runs stage * sets scene and runs stage
*
* @param primaryStage the stage in which the scene may be run and switched to * @param primaryStage the stage in which the scene may be run and switched to
*/ */
public void start(Stage primaryStage){ public void start(Stage primaryStage) {
primaryStage = initializeShip(primaryStage); primaryStage = initializeShip(primaryStage);
primaryStage.show(); primaryStage.show();
} }

View File

@@ -69,54 +69,112 @@ public class StartGUI {
this.player = playerTemp; this.player = playerTemp;
} }
/**
* Initializes the Start GUI the game.
*
* @param stage object of type Stage
* @return returns the stage of GUI
*/
public Stage initializeStart(Stage stage){ 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); borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER); hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0); hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0); hBox.setPrefWidth(200.0);
hBox.setSpacing(10.0); hBox.setSpacing(10.0);
/**
* Creates a borderpane window of width 600 and height 480.
*
*/
borderPane.setPrefHeight(480.0); borderPane.setPrefHeight(480.0);
borderPane.setPrefWidth(600.0); borderPane.setPrefWidth(600.0);
nameField.setPromptText("Enter your name."); /**
* 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"); nameField.setText("Taipan");
/**
* Creates a button with text "Start"
*
*/
startButton.setMnemonicParsing(false); startButton.setMnemonicParsing(false);
startButton.setText("Start"); startButton.setText("Start");
/**
* Creates a VBox at the left of center of the borderpane.
*
*/
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT); 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..."); 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.setMnemonicParsing(false);
gunChoice.setSelected(true); gunChoice.setSelected(true);
gunChoice.setText("Five guns and no cash (But no debt!)?"); gunChoice.setText("Five guns and no cash (But no debt!)?");
gunChoice.setToggleGroup(Start); 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.setAlignment(javafx.geometry.Pos.TOP_LEFT);
cashChoice.setMnemonicParsing(false); cashChoice.setMnemonicParsing(false);
cashChoice.setText("Cash (and a debt)"); cashChoice.setText("Cash (and a debt)");
cashChoice.setToggleGroup(Start); cashChoice.setToggleGroup(Start);
borderPane.setBottom(hBox); 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); BorderPane.setAlignment(vBox0, javafx.geometry.Pos.CENTER);
vBox0.setAlignment(javafx.geometry.Pos.CENTER); vBox0.setAlignment(javafx.geometry.Pos.CENTER);
vBox0.setPrefHeight(200.0); vBox0.setPrefHeight(200.0);
vBox0.setPrefWidth(100.0); vBox0.setPrefWidth(100.0);
/**
* Creates a label with text "Taipan" in size 66 font and default font style.
*
*/
title.setText("Taipan"); title.setText("Taipan");
title.setFont(new Font(66.0)); title.setFont(new Font(66.0));
/**
* Creates a label with our names as text
*
*/
authors.setPrefHeight(80.0); authors.setPrefHeight(80.0);
authors.setPrefWidth(499.0); authors.setPrefWidth(499.0);
authors.setText("By Vikram Bawa, Haris Muhammad, Siddhant Dewani, Nathan Lum and Harkamal Randhawa"); authors.setText("By Vikram Bawa, Haris Muhammad, Siddhant Dewani, Nathan Lum and Harkamal Randhawa");
/**
* Puts Vbox0 in the center of the borderpane.
*
*/
authors.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); authors.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
borderPane.setCenter(vBox0); borderPane.setCenter(vBox0);
/**
* Adds all the buttons and labels to their respective boxes.
*
*/
hBox.getChildren().add(nameField); hBox.getChildren().add(nameField);
hBox.getChildren().add(startButton); hBox.getChildren().add(startButton);
vBox.getChildren().add(choiceLabel); vBox.getChildren().add(choiceLabel);
@@ -126,6 +184,11 @@ public class StartGUI {
vBox0.getChildren().add(title); vBox0.getChildren().add(title);
vBox0.getChildren().add(authors); vBox0.getChildren().add(authors);
/**
* 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>() { startButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -143,9 +206,9 @@ public class StartGUI {
if (response.equalsIgnoreCase("Vikram")) { if (response.equalsIgnoreCase("Vikram")) {
player.setMoney(999999999); player.setMoney(999999999);
player.setBank(999999999); player.setBank(999999999);
player.setGuns(999); player.setGuns(0);
player.setHP(999999999); player.setHP(99999999);
player.setCargoSpace(999999999); player.setCargoSpace(Integer.MAX_VALUE);
} }
setFirm(response); setFirm(response);

View File

@@ -1,4 +1,3 @@
import javafx.application.Application;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Pos; import javafx.geometry.Pos;
@@ -311,7 +310,7 @@ public class TaipanShopGUI {
} }
/** /**
* * this method is responsible for the actual purchasing/selling of items, and the text associated with the act.
*/ */
public void shop(){ public void shop(){
String originalDialogue = textOut.getText(); String originalDialogue = textOut.getText();
@@ -379,6 +378,11 @@ public class TaipanShopGUI {
} }
} }
/**
* Initializes the shop on the given stage as a parameter.
*
* @param stage
*/
public void initializeShop(Stage stage){ public void initializeShop(Stage stage){
Font size14 = new Font(14.0); Font size14 = new Font(14.0);
Rectangle dialogueRectangle = new Rectangle(); Rectangle dialogueRectangle = new Rectangle();
@@ -473,6 +477,7 @@ public class TaipanShopGUI {
buyButton.setPrefHeight(25.0); buyButton.setPrefHeight(25.0);
buyButton.setPrefWidth(45.0); buyButton.setPrefWidth(45.0);
buyButton.setText("Buy"); buyButton.setText("Buy");
// if the buy button is clicked, the main utility buttons are set to be invisible and the buying process begins.
buyButton.setOnAction(new EventHandler<ActionEvent>() { buyButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -485,6 +490,7 @@ public class TaipanShopGUI {
sellButton.setPrefHeight(25.0); sellButton.setPrefHeight(25.0);
sellButton.setText("Sell"); 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>() { sellButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -498,6 +504,7 @@ public class TaipanShopGUI {
sellButton.setMnemonicParsing(false); sellButton.setMnemonicParsing(false);
bankButton.setPrefHeight(25.0); bankButton.setPrefHeight(25.0);
// opens the bank if the bank button is clicked.
bankButton.setOnAction(new EventHandler<ActionEvent>() { bankButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -514,6 +521,7 @@ public class TaipanShopGUI {
cargoButton.setText("Transfer Cargo"); cargoButton.setText("Transfer Cargo");
cargoButton.setMnemonicParsing(false); cargoButton.setMnemonicParsing(false);
cargoButton.setPrefWidth(94.0); cargoButton.setPrefWidth(94.0);
// warehouse is entered when the warehouse button is clicked.
cargoButton.setOnAction(new EventHandler<ActionEvent>() { cargoButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -527,6 +535,7 @@ public class TaipanShopGUI {
loanButton.setMnemonicParsing(false); loanButton.setMnemonicParsing(false);
loanButton.setPrefHeight(25.0); loanButton.setPrefHeight(25.0);
loanButton.setPrefWidth(73.0); loanButton.setPrefWidth(73.0);
// loan office is entered when the loan button is clicked.
loanButton.setOnAction(new EventHandler<ActionEvent>() { loanButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -541,6 +550,7 @@ public class TaipanShopGUI {
quitButton.setMnemonicParsing(false); quitButton.setMnemonicParsing(false);
quitButton.setPrefWidth(90.0); quitButton.setPrefWidth(90.0);
quitButton.setText("Quit Trading"); quitButton.setText("Quit Trading");
// the user is free to travel once the quit button is clicked.
quitButton.setOnAction(new EventHandler<ActionEvent>() { quitButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -555,6 +565,7 @@ public class TaipanShopGUI {
retireButton.setPrefWidth(49.0); retireButton.setPrefWidth(49.0);
retireButton.setText("Retire"); retireButton.setText("Retire");
retireButton.setVisible(false); retireButton.setVisible(false);
// the user wins the game when the retire button is clicked.
retireButton.setOnAction(new EventHandler<ActionEvent>() { retireButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -568,6 +579,7 @@ public class TaipanShopGUI {
opiumButton.setPrefHeight(25.0); opiumButton.setPrefHeight(25.0);
opiumButton.setText("Opium"); opiumButton.setText("Opium");
opiumButton.setVisible(false); opiumButton.setVisible(false);
// the opium buying/selling process starts as soon as the user clicks the opium button.
opiumButton.setOnAction(new EventHandler<ActionEvent>() { opiumButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -589,6 +601,7 @@ public class TaipanShopGUI {
silkButton.setMnemonicParsing(false); silkButton.setMnemonicParsing(false);
silkButton.setText("Silk"); silkButton.setText("Silk");
silkButton.setVisible(false); silkButton.setVisible(false);
// the silk buying/selling process starts as soon as the user clicks the silk button.
silkButton.setOnAction(new EventHandler<ActionEvent>() { silkButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -608,6 +621,7 @@ public class TaipanShopGUI {
armsButton.setPrefWidth(86.0); armsButton.setPrefWidth(86.0);
armsButton.setMnemonicParsing(false); armsButton.setMnemonicParsing(false);
armsButton.setVisible(false); armsButton.setVisible(false);
// the arms buying/selling process starts as soon as the user clicks the arms button.
armsButton.setOnAction(new EventHandler<ActionEvent>() { armsButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -631,6 +645,7 @@ public class TaipanShopGUI {
generalButton.setPrefWidth(86.0); generalButton.setPrefWidth(86.0);
generalButton.setText("General"); generalButton.setText("General");
generalButton.setVisible(false); generalButton.setVisible(false);
// the general cargo buying/selling process starts as soon as the user clicks the general cargo button.
generalButton.setOnAction(new EventHandler<ActionEvent>() { generalButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -650,6 +665,8 @@ public class TaipanShopGUI {
numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT); numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT);
numberInput.setText("Enter amount here..."); numberInput.setText("Enter amount here...");
numberInput.setVisible(false); numberInput.setVisible(false);
// 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.
numberInput.setOnKeyPressed(new EventHandler<KeyEvent>() { numberInput.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override @Override
public void handle(KeyEvent event) { public void handle(KeyEvent event) {
@@ -764,12 +781,18 @@ public class TaipanShopGUI {
stage.setResizable(false); stage.setResizable(false);
stage.setScene(root); stage.setScene(root);
// general updates to the buttons, user stats/inventory, and text.
buttonSetup("reset"); buttonSetup("reset");
updatePrices(); updatePrices();
defaultTextOut(); defaultTextOut();
updateStage(); 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(){ public String getStringLocation(){
String location; String location;
switch(player.getLocation()){ switch(player.getLocation()){
@@ -784,7 +807,12 @@ public class TaipanShopGUI {
} }
return location; 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(){ public String shipStatusString(){
String shipStatus; String shipStatus;
switch(player.getHP()/10){ switch(player.getHP()/10){
@@ -803,7 +831,10 @@ public class TaipanShopGUI {
} }
return shipStatus; return shipStatus;
} }
/**
* updates the text associated with the user's inventory.
*/
public void updateStage(){ public void updateStage(){
firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation())); 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())); wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));

View File

@@ -41,31 +41,40 @@ public class bankGUI{
this.player = playerDummy; this.player = playerDummy;
} }
/**
* Initializes the GUI for the Bank in our game.
*
* @param primaryStage
* @return
*/
public Stage initializeBank(Stage primaryStage) { public Stage initializeBank(Stage primaryStage) {
primaryStage.setTitle("Bank"); primaryStage.setTitle("Bank");
//Declaring each Layout /**
* Creating all the layouts, labels, buttons, and a textfield.
*
*/
BorderPane brdr1 = new BorderPane(); BorderPane brdr1 = new BorderPane();
HBox hbx1 = new HBox(30); HBox hbx1 = new HBox(30);
HBox hbx2 = new HBox(30); HBox hbx2 = new HBox(30);
VBox vbx1 = new VBox(30); VBox vbx1 = new VBox(30);
//Declaring all Variables
Label l1 = new Label("Player: " + player.getName()); Label l1 = new Label("Player: " + player.getName());
Label l2 = new Label("Current Balance: " + player.getBank()); Label l2 = new Label("Current Balance: " + player.getBank());
Label l3 = new Label("Enter Amount: "); Label l3 = new Label("Enter Amount: ");
Label l4 = new Label("Current cash: " + player.getMoney()); Label l4 = new Label("Current cash: " + player.getMoney());
Label l5 = new Label(" "); Label l5 = new Label(" ");
//Declaring All Buttons
Button b1 = new Button("Withdraw"); Button b1 = new Button("Withdraw");
Button b2 = new Button("Deposit"); Button b2 = new Button("Deposit");
Button b3 = new Button("Go back"); Button b3 = new Button("Go back");
//Declaring All TextFields
TextField txtField1 = new TextField(); TextField txtField1 = new TextField();
//Creating the buttons at the bottom of the screen /**
* Adds the buttons so that they are at the bottom of the screen.
*
*/
hbx1.setAlignment(Pos.CENTER); hbx1.setAlignment(Pos.CENTER);
hbx1.getChildren().add(b1); hbx1.getChildren().add(b1);
hbx1.getChildren().add(b2); hbx1.getChildren().add(b2);
@@ -73,13 +82,19 @@ public class bankGUI{
brdr1.setBottom(hbx1); brdr1.setBottom(hbx1);
//Creating the TextField at the center of the screen /**
* Adds the text field to the center of the screen.
*
*/
hbx2.setAlignment(Pos.CENTER); hbx2.setAlignment(Pos.CENTER);
hbx2.getChildren().add(l3); hbx2.getChildren().add(l3);
hbx2.getChildren().add(txtField1); hbx2.getChildren().add(txtField1);
brdr1.setCenter(hbx2); brdr1.setCenter(hbx2);
//Creating the Labels at the top of the Screen /**
* Adds the labels to the top of the screen.
*
*/
vbx1.setAlignment(Pos.CENTER); vbx1.setAlignment(Pos.CENTER);
vbx1.getChildren().add(l1); vbx1.getChildren().add(l1);
vbx1.getChildren().add(l2); vbx1.getChildren().add(l2);
@@ -87,7 +102,10 @@ public class bankGUI{
vbx1.getChildren().add(l5); vbx1.getChildren().add(l5);
brdr1.setTop(vbx1); brdr1.setTop(vbx1);
// Set the event handler when the deposit button is clicked /**
* 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>() { b1.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -105,6 +123,10 @@ public class bankGUI{
} }
); );
/**
* 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 // Set the event handler when the withdraw button is clicked
b2.setOnAction(new EventHandler<ActionEvent>() { b2.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
@@ -124,6 +146,10 @@ public class bankGUI{
} }
); );
/**
* Adds function to button 3 which, when clicked, brings you back to the Shop GUI.
*
*/
b3.setOnAction(new EventHandler<ActionEvent>() { b3.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
@@ -135,15 +161,16 @@ public class bankGUI{
); );
/**
//Setting the Scene and displaying it * 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 scene = new Scene(brdr1, 600, 480);
primaryStage.setScene(scene); primaryStage.setScene(scene);
//primaryStage.show(); //primaryStage.show();
return primaryStage; return primaryStage;
} }
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
bankGUI bank = new bankGUI(player); bankGUI bank = new bankGUI(player);
bank.initializeBank(primaryStage); bank.initializeBank(primaryStage);