diff --git a/.idea/misc.xml b/.idea/misc.xml
index fa20b13..c496ad9 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -9,7 +9,7 @@
-
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ccfdf14..b6e4175 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,13 +2,8 @@
-
-
-
-
-
-
+
@@ -21,83 +16,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -106,10 +29,37 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -125,6 +75,10 @@
+ numOfLittyShips
+ delay
+ Hp
+ shipwarfaredestroyPeasadestrdestro
@@ -151,10 +105,6 @@
continuecashTexcashTe
- 10000
- too
- shipstatusstr
- shipstatusHP
@@ -178,20 +128,19 @@
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
@@ -199,7 +148,6 @@
-
@@ -217,16 +165,17 @@
+
-
+
-
+
@@ -337,7 +286,8 @@
-
+
+ 1550458470138
@@ -563,17 +513,31 @@
1552269681200
-
+
+ 1552270321401
+
+
+
+ 1552270321402
+
+
+ 1552279406065
+
+
+
+ 1552279406066
+
+
-
+
-
+
-
+
@@ -582,7 +546,7 @@
-
+
@@ -670,8 +634,6 @@
-
-
@@ -695,7 +657,9 @@
-
+
+
+
@@ -737,122 +701,86 @@
-
+
+
+
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
@@ -913,7 +841,6 @@
diff --git a/TaipanClone.iml b/TaipanClone.iml
index d5c0743..a860761 100644
--- a/TaipanClone.iml
+++ b/TaipanClone.iml
@@ -5,8 +5,7 @@
-
+
-
-
+
\ No newline at end of file
diff --git a/src/Player.java b/src/Player.java
index 7fd869e..f06d49f 100644
--- a/src/Player.java
+++ b/src/Player.java
@@ -59,6 +59,7 @@ public class Player {
this.wSilk = player.wSilk;
this.wGeneral = player.wGeneral;
this.wArms = player.wArms;
+ this.cargoSpace = player.cargoSpace;
}
/**
diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java
index 44fe25b..f028417 100644
--- a/src/ShipWarfareGUI.java
+++ b/src/ShipWarfareGUI.java
@@ -250,7 +250,10 @@ public class ShipWarfareGUI {
player.setGuns(player.getGuns() - 1);
gunFrustration = true;
} else {
- player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
+ if (numOfPeasantShips>0) {
+ player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
+
+ }
}
if (player.getHP() <= 0) {
exitValue = 2;
@@ -290,6 +293,12 @@ public class ShipWarfareGUI {
return false;
}
+ /**
+ * 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
+ * @return stage so that another class can switch to the stage
+ */
+
public Stage initializeShip(Stage stage){
setNumOfPeasantShips(numOfShips());
@@ -375,6 +384,10 @@ public class ShipWarfareGUI {
//Fight
fightButton.setOnAction(new EventHandler() {
@Override
+ /**
+ * Fight Button, engages in fight logic and graphical interface
+ * @param event, once button is clicked, executes graphical information
+ */
public void handle(ActionEvent event) {
counter++;
chooseFightOrRun.setText("Ohh, Fight ehh?");
@@ -386,6 +399,10 @@ public class ShipWarfareGUI {
runButton.setVisible(false);
continueButton.setOnAction(new EventHandler() {
@Override
+ /**
+ * Switches to Taipan Shop scene
+ * @param event, once button is clicked, executes graphical information
+ */
public void handle(ActionEvent event) {
TaipanShopGUI shop = new TaipanShopGUI(player);
shop.initializeShop(stage);
@@ -408,6 +425,10 @@ public class ShipWarfareGUI {
//Flee
runButton.setOnAction(new EventHandler() {
@Override
+ /**
+ * Run Button, engages in run logic and graphical interface
+ * @param event, once button is clicked, executes graphical information
+ */
public void handle(ActionEvent event) {
chooseFightOrRun.setText("Ayy captain we will try to run!");
counter++;
@@ -424,6 +445,10 @@ public class ShipWarfareGUI {
runButton.setVisible(false);
continueButton.setOnAction(new EventHandler() {
@Override
+ /**
+ * Switches to Taipan Shop scene
+ * @param event, once button is clicked, executes graphical information
+ */
public void handle(ActionEvent event) {
TaipanShopGUI shop = new TaipanShopGUI(player);
shop.initializeShop(stage);
@@ -458,6 +483,10 @@ public class ShipWarfareGUI {
return stage;
}
+ /**
+ * sets scene and runs stage
+ * @param primaryStage the stage in which the scene may be run and switched to
+ */
public void start(Stage primaryStage){
primaryStage = initializeShip(primaryStage);
primaryStage.show();
diff --git a/src/StartGUI.java b/src/StartGUI.java
index f545a7c..992b1ad 100644
--- a/src/StartGUI.java
+++ b/src/StartGUI.java
@@ -143,9 +143,9 @@ public class StartGUI {
if (response.equalsIgnoreCase("Vikram")) {
player.setMoney(999999999);
player.setBank(999999999);
- player.setGuns(0);
- player.setHP(99999999);
- player.setCargoSpace(Integer.MAX_VALUE);
+ player.setGuns(999);
+ player.setHP(999999999);
+ player.setCargoSpace(999999999);
}
setFirm(response);
diff --git a/src/TaipanShopGUI.java b/src/TaipanShopGUI.java
index c400376..3e38509 100644
--- a/src/TaipanShopGUI.java
+++ b/src/TaipanShopGUI.java
@@ -55,13 +55,6 @@ public class TaipanShopGUI {
this.player = playerDummy;
}
- public void startTaipanShop(Stage stage){
- stage = initializeShop(stage);
- updateStage();
- updatePrices();
- stage.show();
- }
-
/**
* This method is evoked if the user is eligible to win, and chooses to end the game (by winning).
*/
@@ -222,11 +215,23 @@ 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(), getOpiumPrice(), getSilkPrice(), getArmsPrice(), getGeneralPrice()));
}
+ /**
+ * Sets up buttons according to which "state" is inputted. When used in "shop", only the item buttons are visible.
+ * When used in "reset", all the item buttons are invisible; if the user is at location one and is eligible to win,
+ * then all utilities and the retire button are visible. If the user is not at location one, then the user can only
+ * buy, sell, or exit. If the user is at location one and is not eligible to win, then all utilities are visible but
+ * the retire button is not. When used in "input" everything near the bottom is invisible except for the text area.
+ *
+ * @param state -- the state determines which buttons are visible and which are not.
+ */
public void buttonSetup(String state) {
if (state.equals("shop")) {
buyButton.setVisible(false);
@@ -248,7 +253,7 @@ public class TaipanShopGUI {
silkButton.setText("Silk");
armsButton.setText("Arms");
generalButton.setText("General");
- if (player.getLocation() != 1 && player.getBank() + player.getMoney() - player.getDebt() < 1000000) {
+ if (player.getLocation() != 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(false);
@@ -261,7 +266,8 @@ public class TaipanShopGUI {
numberInput.setVisible(false);
generalButton.setVisible(false);
retireButton.setVisible(false);
- }else if(player.getBank() + player.getMoney() - player.getDebt() < 1000000){
+ }
+ if(player.getBank() + player.getMoney() - player.getDebt() < 1000000 && player.getLocation() == 1){
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -274,7 +280,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false);
armsButton.setVisible(false);
retireButton.setVisible(false);
- }else{
+ }else if(player.getLocation() == 1){
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -304,6 +310,9 @@ public class TaipanShopGUI {
}
}
+ /**
+ *
+ */
public void shop(){
String originalDialogue = textOut.getText();
int num = Integer.parseInt(numberInput.getText().replace(" ", ""));
@@ -370,7 +379,7 @@ public class TaipanShopGUI {
}
}
- public Stage initializeShop(Stage stage){
+ public void initializeShop(Stage stage){
Font size14 = new Font(14.0);
Rectangle dialogueRectangle = new Rectangle();
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
@@ -759,8 +768,6 @@ public class TaipanShopGUI {
updatePrices();
defaultTextOut();
updateStage();
-
- return stage;
}
public String getStringLocation(){
diff --git a/src/WarehouseGUI.java b/src/WarehouseGUI.java
index 0cf711b..31c4f3a 100644
--- a/src/WarehouseGUI.java
+++ b/src/WarehouseGUI.java
@@ -11,6 +11,10 @@ import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
+/**
+ * A class that makes the GUI for the Warehouse class.
+ *
+ */
public class WarehouseGUI {
private Player player;
@@ -19,6 +23,7 @@ public class WarehouseGUI {
private HBox hBox;
private Button withdraw;
private Button deposit;
+ private Button goBack;
private VBox vBox;
private Text playerName;
private Text text;
@@ -43,22 +48,42 @@ public class WarehouseGUI {
private CheckMenuItem arms;
private CheckMenuItem silk;
private CheckMenuItem opium;
-
+ /**
+ * A constructor that takes an object of type Player as an argument
+ *
+ * @param player object of the class Player
+ */
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;
}
+ /**
+ * initializes the GUI for the warehouse aspect of our game.
+ *
+ * @param stage an object of type Stage
+ * @return returns the stage of the GUI
+ */
public Stage initializeWarehouse(Stage stage) {
title = new Text();
@@ -93,10 +118,19 @@ public class WarehouseGUI {
borderPane.setPrefHeight(480.0);
borderPane.setPrefWidth(600.0);
+ /**
+ * Sets the preferred width and height of the borderpane window to 600 by 480.
+ *
+ */
borderPane.setPrefHeight(480.0);
borderPane.setPrefWidth(600.0);
+ /**
+ * Creates a label "Hong Kong Warehouse: at the top of the borderpane.
+ *
+ */
borderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
+
title.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
title.setStrokeWidth(0.0);
title.setText("Hong Kong Warehouse");
@@ -115,17 +149,29 @@ public class WarehouseGUI {
title.setFont(new Font(24.0));
borderPane.setTop(title);
- BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
+ /**
+ * creates an HBox at the center of the borderpane with a width of 200 and height of 100.
+ *
+ */
+ borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
+ /**
+ * Creates a button with text "Withdraw" which handles user events.
+ *
+ */
withdraw.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
withdraw.setMnemonicParsing(false);
+ withdraw.setPrefWidth(250.0);
withdraw.setText("Withdraw");
- // Set the event handler when the deposit button is clicked
withdraw.setOnAction(new EventHandler() {
+ /**
+ * Creates a button with text "Deposit" which handles user events.
+ *
+ */
@Override
public void handle(ActionEvent event) {
int withdraw = Integer.parseInt(textIn.getText());
@@ -142,10 +188,11 @@ public class WarehouseGUI {
);
deposit.setMnemonicParsing(false);
+ deposit.setPrefWidth(250.0);
deposit.setText("Deposit");
deposit.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
+ borderPane.setBottom(hBox);
- // Set the event handler when the deposit button is clicked
deposit.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
@@ -154,7 +201,6 @@ public class WarehouseGUI {
}
);
-
splitMenu.setMnemonicParsing(false);
splitMenu.setText("Item");
@@ -175,6 +221,10 @@ public class WarehouseGUI {
vBox.setPrefHeight(156.0);
vBox.setPrefWidth(106.0);
+ /**
+ * Creates a label with text "Player" with size 18 font and default font style.
+ *
+ */
playerName.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
playerName.setStrokeWidth(0.0);
playerName.setText("Player");
@@ -182,12 +232,20 @@ public class WarehouseGUI {
playerName.setWrappingWidth(103.47265625);
playerName.setFont(new Font(18.0));
+ /**
+ * Creates a label with no text for aesthetic spacing purposes.
+ *
+ */
text.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
text.setStrokeWidth(0.0);
text.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
text.setWrappingWidth(103.47265625);
text.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "Opium" under the "Player" label with size 18 font and default font style
+ *
+ */
opiumPlayer.setAlignment(javafx.geometry.Pos.CENTER);
opiumPlayer.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
opiumPlayer.setPrefWidth(100.0);
@@ -195,16 +253,28 @@ public class WarehouseGUI {
opiumPlayer.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
opiumPlayer.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "Silk" under the "Player" label with size 18 font and default font style.
+ *
+ */
silkPlayer.setAlignment(javafx.geometry.Pos.CENTER);
silkPlayer.setPrefWidth(100.0);
silkPlayer.setText("Silk");
silkPlayer.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "Arms" under the "Player" label with size 18 font and default font style.
+ *
+ */
armsPlayer.setAlignment(javafx.geometry.Pos.CENTER);
armsPlayer.setPrefWidth(100.0);
armsPlayer.setText("Arms");
armsPlayer.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "General" under the "Player" label with size 18 font and default font style.
+ *
+ */
generalPlayer.setAlignment(javafx.geometry.Pos.CENTER);
generalPlayer.setPrefWidth(100.0);
generalPlayer.setText("General");
@@ -212,6 +282,10 @@ public class WarehouseGUI {
generalPlayer.setFont(new Font(18.0));
borderPane.setLeft(vBox);
+ /**
+ * Creates a VBox at the center of the borderpane with a width of 261 and a height of 343.
+ *
+ */
BorderPane.setAlignment(vBox0, javafx.geometry.Pos.TOP_LEFT);
vBox0.setAlignment(javafx.geometry.Pos.CENTER);
vBox0.setPrefHeight(343.0);
@@ -350,6 +424,10 @@ public class WarehouseGUI {
vBox0.setPrefHeight(343.0);
vBox0.setPrefWidth(261.0);
+ /**
+ * Creates a label with text "Warehouse" with size 18 font and default font style.
+ *
+ */
text0.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
text0.setStrokeWidth(0.0);
text0.setText("Warehouse");
@@ -357,12 +435,20 @@ public class WarehouseGUI {
text0.setWrappingWidth(103.47265625);
text0.setFont(new Font(18.0));
+ /**
+ * Creates a label with no text for aesthetic spacing purposes.
+ *
+ */
text1.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
text1.setStrokeWidth(0.0);
text1.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
text1.setWrappingWidth(103.47265625);
text1.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "Opium" under the "Warehouse" label with size 18 font and default font style.
+ *
+ */
opiumWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
opiumWarehouse.setStrokeWidth(0.0);
opiumWarehouse.setText("Opium");
@@ -370,6 +456,10 @@ public class WarehouseGUI {
opiumWarehouse.setWrappingWidth(103.47265625);
opiumWarehouse.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "Silk" under the "Warehouse" label with size 18 font and default font style.
+ *
+ */
silkWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
silkWarehouse.setStrokeWidth(0.0);
silkWarehouse.setText("Silk");
@@ -377,6 +467,10 @@ public class WarehouseGUI {
silkWarehouse.setWrappingWidth(103.47265625);
silkWarehouse.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "Arms" under the "Warehouse" label with size 18 font and default font style.
+ *
+ */
armsWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
armsWarehouse.setStrokeWidth(0.0);
armsWarehouse.setText("Arms");
@@ -384,6 +478,10 @@ public class WarehouseGUI {
armsWarehouse.setWrappingWidth(103.47265625);
armsWarehouse.setFont(new Font(18.0));
+ /**
+ * Creates a label with text "General" under the "Warehouse" label with size 18 font and default font style.
+ *
+ */
generalWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
generalWarehouse.setStrokeWidth(0.0);
generalWarehouse.setText("General");
@@ -392,22 +490,37 @@ public class WarehouseGUI {
generalWarehouse.setFont(new Font(18.0));
borderPane.setCenter(vBox0);
+ /**
+ * Creates a VBox at the center of the borderpane with a width of 152 and a height of 48.
+ *
+ */
borderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER);
vBox1.setPrefHeight(48.0);
vBox1.setPrefWidth(152.0);
+ /**
+ * Creates a label with "In use:" text with size 18 font and default font style.
+ *
+ */
inUseWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
inUseWarehouse.setStrokeWidth(0.0);
inUseWarehouse.setText("In use:");
inUseWarehouse.setFont(new Font(18.0));
+ /**
+ * Creates a label with "Vacant:" text with size 18 font and default font style.
+ *
+ */
vacantWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
vacantWarehouse.setStrokeWidth(0.0);
vacantWarehouse.setText("Vacant:");
vacantWarehouse.setFont(new Font(18.0));
borderPane.setRight(vBox1);
-
+ /**
+ * Adds all the labels and buttons to their respective boxes.
+ *
+ */
splitMenu.getItems().add(general);
splitMenu.getItems().add(arms);
splitMenu.getItems().add(silk);
@@ -439,9 +552,287 @@ public class WarehouseGUI {
return stage;
}
+ /**
+ * When run, shows the stage as a graphical interface through JavaFX.
+ *
+ * @param primaryStage object of type Stage
+ */
public void start(Stage primaryStage) {
WarehouseGUI warehouseGUI = new WarehouseGUI(player);
warehouseGUI.initializeWarehouse(primaryStage);
primaryStage.show();
}
+
+ /**
+ * The purpose of this class is to create a warehouse where the goods
+ * can be safely stored without holing space on the ship!
+ */
+
+ public class Warehouse {
+ /*private int wOpium = 0;
+ private int wSilk = 0;
+ private int wGeneral = 0;
+ private int wArms = 0;*/
+ private Player player;
+
+ /**
+ * setter method that takes in a Player object as an argument.
+ *
+ * @param player object of the class Player
+ */
+
+ public void setPlayer(Player player) {
+ Player playerDummy = new Player(player);
+ this.player = playerDummy;
+ }
+
+ /**
+ * getter method for obtaining a player object.
+ *
+ * @return returns player object
+ */
+
+ public Player getPlayer() {
+ Player playerDummy = new Player(player);
+ return playerDummy;
+ }
+
+ /**
+ * Class Constructor that takes in a type player as a parameter
+ *
+ * @param player object of the class Player
+ */
+
+ public Warehouse(Player player) {
+ Player playerDummy = new Player(player);
+ this.player = playerDummy;
+ }
+
+ /**
+ * This method adds an amount of a certain good
+ * the user is prompted to enter the amount they would like to
+ * add followed by the good they would like to add to the warehouse.
+ * the method checks if the player has sufficient goods to transfer, and if the player does
+ * then the method executes the transfer
+ *
+ */
+ public void addAmount() {
+ boolean askGood = false;
+ String amount;
+ int finalAmount = 0;
+ System.out.println("Please enter the amount of the good you would like to ADD.");
+ Scanner keyboard = new Scanner(System.in);
+ amount = keyboard.nextLine();//Asks the user for the amount of the good they would like to add
+ /*The try function ensures that the program does not crash
+ due to any errors while giving the program an incorrect input*/
+ try {
+ //The if statement checks that you have enough resources to make the transfer
+ if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) {
+ finalAmount = Integer.parseInt(amount);
+ askGood = true;
+ }
+ //Else statement lets the user know that they do not hav enough goods to make the requested transfer
+ else {
+ System.out.println("Nice try but you don't have any items of that quantity!");
+ askGood = false;
+ }
+ //Ensures that goods are only transferred if they have the specified amount
+ //The user is prompted to enter which good they want to transfer
+ if (askGood == true) {
+ String good;
+ System.out.println("Please enter a good to transfer O, S, G, A :");
+ good = keyboard.nextLine();
+ int held = 0;
+ //The following set of loops check to see which good the user has selected and makes the transfer
+ if (Integer.parseInt(amount) > 0) {
+ if (good.equalsIgnoreCase("O")) {
+ if (player.getOpiumHeld() >= Integer.parseInt(amount)) {
+ player.setwOpium(player.getwOpium() + finalAmount);
+ held = player.getOpiumHeld();
+ player.setOpiumHeld(held - finalAmount);
+ System.out.println(player.getOpiumHeld());
+ } else {
+ System.out.println("You don't even have that much opium!");
+ }
+ } else if (good.equalsIgnoreCase("S")) {
+ if (player.getSilkHeld() >= Integer.parseInt(amount)) {
+ player.setwSilk(player.getwSilk() + finalAmount);
+ held = player.getSilkHeld();
+ player.setSilkHeld(held - finalAmount);
+ } else {
+ System.out.println("You don't even have that much silk!");
+
+ }
+ } else if (good.equalsIgnoreCase("G")) {
+ if (player.getGeneralHeld() >= Integer.parseInt(amount)) {
+ player.setwGeneral(player.getwGeneral() + finalAmount);
+ held = player.getGeneralHeld();
+ player.setGeneralHeld(held - finalAmount);
+ } else {
+ System.out.println("You don't even have that much general cargo!");
+
+ }
+ } else if (good.equalsIgnoreCase("A")) {
+ if (player.getArmsHeld() >= Integer.parseInt(amount)) {
+ player.setwArms(player.getwArms() + finalAmount);
+ held = player.getArmsHeld();
+ player.setArmsHeld(held - finalAmount);
+ } else {
+ System.out.println("You don't even have that much Arms!");
+ }
+ }
+ }
+ //Ensures no negative amounts are entered
+ else {
+ System.out.println("Sorry this transfer cannot be made");
+ }
+ }
+ //If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
+ } catch (Exception e) {
+ System.out.println("Wait, that's not a valid input please try again");
+ }
+ }
+
+ /**
+ * This method removes an amount of a certain good
+ * the user is prompted to enter the amount they would like to
+ * remove followed by the good they would like to remove from the warehouse.
+ * the method checks if the player has sufficient goods to transfer, and if the player does
+ * then the method executes the transfer
+ *
+ */
+
+ public void removeAmount() {
+ String amount;
+ boolean askGood = false;
+ int finalAmount = 0;
+ System.out.println("Please enter the amount of the good you would like to REMOVE");
+ Scanner keyboard = new Scanner(System.in);
+ //Prompts the user for the amount they would like to remove
+ amount = keyboard.nextLine();
+ //The if statement checks that you have enough resources to make the transfer
+ try {
+ //The if statement checks that you have enough resources to make the transfer
+ if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) {
+ finalAmount = Integer.parseInt(amount);
+ askGood = true;
+ }
+ //Else statement lets the user know that they do not hav enough goods to make the requested transfer
+ else {
+ System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
+ askGood = false;
+ }
+
+ //Ensures that goods are only transferred if they have the specified amount
+ //The user is prompted to enter which good they want to transfer
+
+ if (askGood == true) {
+ String good;
+ System.out.println("Please enter a good to transfer O, S, G, A :");
+ good = keyboard.nextLine();
+ int held = 0;
+ //The following set of loops check to see which good the user has selected and makes the transfer and amount > 0
+ if (Integer.parseInt(amount) > 0) {
+ if (good.equalsIgnoreCase("O")) {
+ if (player.getwOpium() >= Integer.parseInt(amount)) {
+ player.setwOpium(player.getwOpium() - Integer.parseInt(amount));
+ held = player.getOpiumHeld();
+ player.setOpiumHeld(held + finalAmount);
+ } else {
+ System.out.println("You don't have that much opium stored in the warehouse!");
+ }
+ } else if (good.equalsIgnoreCase("S")) {
+ if (player.getwSilk() >= Integer.parseInt(amount)) {
+ player.setwSilk(player.getwSilk() - Integer.parseInt(amount));
+ held = player.getSilkHeld();
+ player.setSilkHeld(held + finalAmount);
+ } else {
+ System.out.println("You don't have that much silk stored in the warehouse!");
+ }
+ } else if (good.equalsIgnoreCase("G")) {
+ if (player.getwGeneral() >= Integer.parseInt(amount)) {
+ player.setwGeneral(player.getwGeneral() - Integer.parseInt(amount));
+ held = player.getGeneralHeld();
+ player.setGeneralHeld(held + finalAmount);
+ } else {
+ System.out.println("You don't have that much general cargo stored in the warehouse!");
+
+ }
+ } else if (good.equalsIgnoreCase("A")) {
+ if (player.getwArms() >= Integer.parseInt(amount)) {
+ player.setwArms(player.getwArms() - Integer.parseInt(amount));
+ held = player.getArmsHeld();
+ player.setArmsHeld(held + finalAmount);
+ } else {
+ System.out.println("You don't have that much arms stored in the warehouse!");
+
+ }
+ }
+ }
+ //Ensures the value entered is positive
+ else {
+ System.out.println("Sorry this transfer cannot be made");
+ }
+ }
+ }
+ //If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
+ catch (Exception e){
+ System.out.println("Wait, that's not a valid input please try again");
+ }
+ }
+
+ /**
+ * This method prints the stock that is in the warehouse currently using the get and set
+ * methods from the player class. This is to allow the user to be able to know how much they have
+ * stored in the warehouse
+ */
+ public void showWarehouse() {
+ System.out.println("--------------------\nWarehouse\n--------------------");
+ System.out.println("Opium : " + player.getwOpium());
+ System.out.println("Silk : " + player.getwSilk());
+ System.out.println("General : " + player.getwGeneral());
+ System.out.println("Arms : " + player.getwArms());
+ }
+
+ /**
+ * This method combines the add and remove methods and prompts the user to
+ * enter what they would like to do. Add or remove and accordingly invokes
+ * the required methods
+ */
+ public void changeWarehouse() {
+ boolean keepGoing = true;
+ while (keepGoing) {
+ this.showWarehouse();
+ String input = " ";
+ System.out.println("Would you like to add(A) or remove(R) resources? ");
+ Scanner keyboard = new Scanner(System.in);
+ input = keyboard.next();
+ if (input.equalsIgnoreCase("R")) {
+ this.removeAmount();
+ this.showWarehouse();
+ } else if (input.equalsIgnoreCase("A")) {
+ this.addAmount();
+ this.showWarehouse();
+
+ }
+ else{
+ System.out.println("Don't waste the warehouse's time, try again later with a valid input");
+ }
+
+ String check;
+ //Check to see if the player wants to continue in the warehouse or they are done
+ System.out.println("Would you like to do any other business? Y / N?");
+ check = keyboard.nextLine();
+ check = keyboard.nextLine();
+
+ if (check.equalsIgnoreCase("Y")) {
+ keepGoing = true;
+ } else if (check.equalsIgnoreCase("N")) {
+ keepGoing = false;
+ }
+ }
+ }
+
+ }
+
}