From f89c1aa20967e5d22d82c57eaa499238c977218e Mon Sep 17 00:00:00 2001 From: Solargale Date: Fri, 12 Apr 2019 03:54:20 -0600 Subject: [PATCH] Redid a bunch of commenting making sure that every method was commented. --- src/gui/BankGUI.java | 54 +++++------- src/gui/GameEndGUI.java | 27 +++--- src/gui/LoanSharkGUI.java | 147 +++++++++++++++++--------------- src/gui/MainGUI.java | 2 - src/gui/RandomEventGUI.java | 11 +-- src/gui/ShipWarfareGUI.java | 4 - src/gui/StartGUI.java | 12 +-- src/gui/TaipanShopGUI.java | 18 +++- src/gui/TravelGUI.java | 27 +++++- src/logic/BankLogic.java | 27 ++++++ src/logic/FileSaving.java | 20 ++++- src/logic/GameEndLogic.java | 13 ++- src/logic/LoanSharkLogic.java | 24 ++++++ src/logic/RandomEventLogic.java | 8 +- src/logic/ShipWarfareLogic.java | 1 - src/logic/StartLogic.java | 7 +- src/logic/TaipanShopLogic.java | 6 +- src/logic/TravelLogic.java | 7 ++ src/logic/WarehouseLogic.java | 6 +- src/text/BankText.java | 115 ++++++++++++++++--------- src/text/GameEndText.java | 24 ++++++ src/text/LoanSharkText.java | 72 ++++++++++++++++ src/text/RandomEventText.java | 15 +++- src/text/ShipWarfareText.java | 4 +- src/text/StartText.java | 13 ++- src/text/TaipanShopText.java | 33 +++++-- src/text/TravelText.java | 24 +++++- src/text/WarehouseText.java | 5 ++ 28 files changed, 508 insertions(+), 218 deletions(-) create mode 100644 src/logic/LoanSharkLogic.java diff --git a/src/gui/BankGUI.java b/src/gui/BankGUI.java index fce1a95..e3fba87 100644 --- a/src/gui/BankGUI.java +++ b/src/gui/BankGUI.java @@ -12,18 +12,18 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; +import logic.BankLogic; import logic.Player; +/** + * 2019-03-10 + * Authors: Siddhant Dewani + * BankGUI allows the user to store cash and gain interest off of the cash + */ public class BankGUI extends Player { - /** - * 2019-03-10 - * Authors: Siddhant Dewani - * BankGUI allows the user to store cash and gain interest off of the cash - */ /** * Class Constructor that takes in a type player as a parameter - * * @param player object of the class Player */ public BankGUI(Player player) { @@ -33,16 +33,14 @@ public class BankGUI extends Player { /** * Initializes the GUI for the Bank in our game. - * - * @param primaryStage - * @return + * @param primaryStage the stage in which everything in this class is shown + * @return Returns the stage in which can be used by other stages */ - public Stage initializeBank(Stage primaryStage) { + public void initializeBank(Stage primaryStage) { primaryStage.setTitle("Bank"); /** * Creating all the layouts, labels, buttons, and a textfield. - * */ BorderPane brdr1 = new BorderPane(); HBox hbx1 = new HBox(30); @@ -63,7 +61,6 @@ public class BankGUI extends Player { /** * Adds the buttons so that they are at the bottom of the screen. - * */ hbx1.setAlignment(Pos.CENTER); hbx1.getChildren().add(b1); @@ -83,7 +80,6 @@ public class BankGUI extends Player { /** * Adds the labels to the top of the screen. - * */ vbx1.setAlignment(Pos.CENTER); vbx1.getChildren().add(l1); @@ -95,7 +91,6 @@ public class BankGUI extends Player { /** * 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() { @Override @@ -135,22 +130,25 @@ public class BankGUI extends Player { /** * Sets the window size to a width of 600 and height of 480 and displays the screen. - * */ Scene scene = new Scene(brdr1, 600, 480); scene.getStylesheets().add("styleguide.css"); primaryStage.setScene(scene); - return primaryStage; } + /** + * The deposit button within the scene above. Runs the deposit logic class when run + * @param txtField1,l5,l2,l4 assigned from the original element inside of the JavaFX scene + */ private void deposits(TextField txtField1, Label l5, Label l2, Label l4) { try { int deposit = Integer.parseInt(txtField1.getText()); if (deposit < 0) { l5.setText("Nice try! You can not enter negative numbers."); } else if (deposit <= getMoney()) { - setBank(deposit + getBank()); - setMoney(getMoney() - deposit); + BankLogic bankLogic = new BankLogic(getPlayer()); + bankLogic.depositing(deposit); + setPlayer(bankLogic.getPlayer()); } else { l5.setText("Sorry, you can not deposit that much."); } @@ -162,14 +160,19 @@ public class BankGUI extends Player { } } + /** + * The withdraw button within the scene above. Runs the withdraw logic class when run + * @param txtField1,l5,l2,l4 assigned from the original element inside of the JavaFX scene + */ private void withdraw(TextField txtField1, Label l5, Label l2, Label l4) { try { int withdraw = Integer.parseInt(txtField1.getText()); if (withdraw < 0) { l5.setText("Come on " + getName() + ", are you trying to fool me?\nNo negative numbers please!"); } else if (withdraw <= getBank()) { - setMoney(withdraw + getMoney()); - setBank(getBank() - withdraw); + BankLogic bankLogic = new BankLogic(getPlayer()); + bankLogic.withdrawing(withdraw); + setPlayer(bankLogic.getPlayer()); } else { l5.setText("Sorry, you can not withdraw that much."); } @@ -179,15 +182,4 @@ public class BankGUI extends Player { l5.setText("Please enter a valid response."); } } - - /** - * sets scene and runs stage - * - * @param primaryStage the stage in which the scene may be run and switched to - */ - public void start(Stage primaryStage) { - BankGUI bank = new BankGUI(getPlayer()); - bank.initializeBank(primaryStage); - primaryStage.show(); - } } diff --git a/src/gui/GameEndGUI.java b/src/gui/GameEndGUI.java index 7314c79..7d65df9 100644 --- a/src/gui/GameEndGUI.java +++ b/src/gui/GameEndGUI.java @@ -25,6 +25,11 @@ public class GameEndGUI extends Player { private Label netWorth; private BorderPane borderPane; + /** + * Class Constructor that takes in a type player as a parameter + * + * @param player object of the class Player + */ public GameEndGUI(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); @@ -36,7 +41,7 @@ public class GameEndGUI extends Player { * @param stage sets the stage to which we will execute the scene of the GameEndGUI class * @return stage so that another class can switch to the stage */ - public Stage initializeGameEndGUI(Stage stage) { + public void initializeGameEndGUI(Stage stage) { //Creating all the nodes title = new Label(); @@ -83,10 +88,11 @@ public class GameEndGUI extends Player { vBox.getChildren().add(netWorth); title.setText(gameEndLogic.endGameText()); + String[] strings = gameEndLogic.endGameStats(netWorthInt); //Updating the endgame stats of the player - firmName.setText("Firm Name: " + getName()); - gunsHeld.setText("Guns Held: " + getGuns()); - netWorth.setText("Net Worth: " + netWorthInt); + firmName.setText(strings[0]); + gunsHeld.setText(strings[1]); + netWorth.setText(strings[2]); Scene root = new Scene(borderPane, 600, 480); root.getStylesheets().add("styleguide.css"); @@ -94,18 +100,7 @@ public class GameEndGUI extends Player { stage.setTitle("End Game Stats"); stage.setResizable(false); stage.setScene(root); - - return stage; } - /** - * sets scene and runs stage - * - * @param primaryStage the stage in which the scene may be run and switched to - */ - public void start(Stage primaryStage) { - GameEndGUI gameEndGUI = new GameEndGUI(getPlayer()); - gameEndGUI.initializeGameEndGUI(primaryStage); - primaryStage.show(); - } + } diff --git a/src/gui/LoanSharkGUI.java b/src/gui/LoanSharkGUI.java index 47c1066..008bab6 100644 --- a/src/gui/LoanSharkGUI.java +++ b/src/gui/LoanSharkGUI.java @@ -1,7 +1,5 @@ package gui; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; @@ -12,6 +10,7 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; +import logic.LoanSharkLogic; import logic.Player; /** @@ -42,7 +41,7 @@ public class LoanSharkGUI extends Player { * * @param primaryStage the stage upon which the GUI will be imposed */ - public Stage initializeLoanShark(Stage primaryStage) { + public void initializeLoanShark(Stage primaryStage) { primaryStage.setTitle("Loan Shark"); //Declaring each Layout @@ -92,73 +91,20 @@ public class LoanSharkGUI extends Player { brdr1.setTop(vbx1); // Set the event handler when the deposit button is clicked - b1.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - try { - - int loanAsk = Integer.parseInt(txtField1.getText()); - if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) { - setDebt(getDebt() + loanAsk); - setMoney(getMoney() + loanAsk); - l4.setText("Cash: " + getMoney()); - } else if (loanAsk < 0) { - l5.setText("Sorry you cannot enter negative numbers"); - } - else{ - l5.setText("Sorry you cannot get the loan requested"); - } - - - l2.setText("Debt: " + getDebt()); - } catch (Exception e) { - l5.setText("Please enter a valid value"); - } - - } - } - - ); + b1.setOnAction(event -> { + depositButton(l2, l4, l5, txtField1); + }); // Set the event handler when the withdraw button is clicked - b2.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - try { + b2.setOnAction(event -> { + withdrawButton(l2, l4, l5, txtField1); + }); - - int returnAsk = Integer.parseInt(txtField1.getText()); - if (returnAsk > getDebt()) { - l5.setText("You do not need to return that much."); - } - else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) { - setDebt(getDebt() - returnAsk); - setMoney(getMoney() - returnAsk); - l4.setText("Cash: " + getMoney()); - } - else if(getMoney() < returnAsk) { - l5.setText("Look " + getName() + ", you are being cheap!"); - } - else { - l5.setText("Sorry, you can not return a negative amount!"); - } - l2.setText("Debt: " + getDebt()); - } - catch (Exception e) { - l5.setText("Please enter a valid value"); - } - } - } - ); - - b3.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer()); - shopGUI.initializeShop(primaryStage); - primaryStage.show(); - } - } + b3.setOnAction(event -> { + TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer()); + shopGUI.initializeShop(primaryStage); + primaryStage.show(); + } ); @@ -166,8 +112,71 @@ public class LoanSharkGUI extends Player { Scene scene = new Scene(brdr1, 600, 480); scene.getStylesheets().add("styleguide.css"); primaryStage.setScene(scene); - //primaryStage.show(); - return primaryStage; + primaryStage.show(); + } + + /** + * The withdraw button within the scene above. Runs the withdraw logic class when run + * @param txtField1,l2,l4,l5 assigned from the original element inside of the JavaFX scene + */ + public void withdrawButton(Label l2, Label l4, Label l5, TextField txtField1) { + try { + int returnAsk = Integer.parseInt(txtField1.getText()); + //If the player enters a invalid number + if (returnAsk > getDebt()) { + l5.setText("You do not need to return that much."); + } + //If the player enters a valid number + else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) { + LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer()); + loanSharkLogic.changeLoan(getDebt() - returnAsk, getMoney() - returnAsk); + setPlayer(loanSharkLogic.getPlayer()); + l4.setText("Cash: " + getMoney()); + } + //If the player enters a invalid number + else if(getMoney() < returnAsk) { + l5.setText("Look " + getName() + ", you are being cheap!"); + } + //If the player enters a negative number + else { + l5.setText("Sorry, you can not return a negative amount!"); + } + l2.setText("Debt: " + getDebt()); + } + //Only runs if the user gives an invalid input + catch (Exception e) { + l5.setText("Please enter a valid value"); + } + } + + /** + * The deposit button within the scene above. Runs the deposit logic class when run + * @param txtField1,l5,l2,l4 assigned from the original element inside of the JavaFX scene + */ + public void depositButton(Label l2, Label l4, Label l5, TextField txtField1) { + try { + int loanAsk = Integer.parseInt(txtField1.getText()); + //If the player enters a valid number + if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) { + LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer()); + loanSharkLogic.changeLoan(getDebt() + loanAsk, getMoney() + loanAsk); + setPlayer(loanSharkLogic.getPlayer()); + l4.setText("Cash: " + getMoney()); + } + //If the player enters a negative number + else if (loanAsk < 0) { + l5.setText("Sorry you cannot enter negative numbers"); + } + //If the player enters a invalid number + else{ + l5.setText("Sorry you cannot get the loan requested"); + } + l2.setText("Debt: " + getDebt()); + } + //Only runs if the user gives an invalid input + catch (Exception e) { + l5.setText("Please enter a valid value"); + } } } diff --git a/src/gui/MainGUI.java b/src/gui/MainGUI.java index a4757a5..debc817 100644 --- a/src/gui/MainGUI.java +++ b/src/gui/MainGUI.java @@ -8,9 +8,7 @@ import logic.Player; * 2019-03-10 * Authors: Harkamal, Vikram, Haris, Siddhant, Nathan * MainGUI class, Initializes the entire game and runs the game for user to play -* */ - public class MainGUI extends Application { /** diff --git a/src/gui/RandomEventGUI.java b/src/gui/RandomEventGUI.java index e080a3b..d2674d2 100644 --- a/src/gui/RandomEventGUI.java +++ b/src/gui/RandomEventGUI.java @@ -48,11 +48,11 @@ public class RandomEventGUI extends Player { } /** - * Initializes randomEvent on the given stage as a parameter. + * Sets up the graphical part of RandomEventGUI and includes all logic for the class * - * @param stage + * @param stage sets the stage to which we will execute the scene of the RandomEventGUI class */ - public Stage initializeRandomEventGUI(Stage stage) { + public void initializeRandomEventGUI(Stage stage) { //Creating the nodes within the event screen hBox = new HBox(); yesButton = new Button(); @@ -146,11 +146,13 @@ public class RandomEventGUI extends Player { sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived,\n would be willing to repair your ship for $" + itemPrice); } + //Only runs if the player doesn't have enough space and is given a gun if((eventNumber == 1 && getCargoSpace() < 10)){ TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer()); taipanShopGUI.initializeShop(stage); stage.show(); } + //Only runs if the player has 100 or greater HP and they got the ship repair man if((eventNumber == 3 && getPlayer().getHP() >= 100)){ TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer()); taipanShopGUI.initializeShop(stage); @@ -210,10 +212,9 @@ public class RandomEventGUI extends Player { Scene root = new Scene(borderPane, 600, 480); root.getStylesheets().add("styleguide.css"); - stage.setTitle("Travel"); + stage.setTitle("Random Event"); stage.setResizable(false); stage.setScene(root); - return stage; } diff --git a/src/gui/ShipWarfareGUI.java b/src/gui/ShipWarfareGUI.java index 4f84250..082f7a0 100644 --- a/src/gui/ShipWarfareGUI.java +++ b/src/gui/ShipWarfareGUI.java @@ -1,8 +1,6 @@ package gui; import javafx.animation.*; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; @@ -29,8 +27,6 @@ import logic.ShipWarfareLogic; * Author: Haris Muhammad * ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from */ - - public class ShipWarfareGUI extends Player { ShipWarfareLogic logic = new ShipWarfareLogic(getPlayer()); diff --git a/src/gui/StartGUI.java b/src/gui/StartGUI.java index e5c3698..2251b9d 100644 --- a/src/gui/StartGUI.java +++ b/src/gui/StartGUI.java @@ -1,7 +1,5 @@ package gui; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; @@ -18,7 +16,6 @@ import logic.StartLogic; * 2019-03-10 * Authors: Harkamal, Vikram, Haris, Siddhant, Nathan * StartGUI class, Initializes and displays the start menu for Taipan - * */ @@ -61,12 +58,10 @@ public class StartGUI extends Player { } /** - * Initializes the Start GUI the game. - * - * @param stage object of type Stage - * @return returns the stage of GUI + * Sets up the graphical part of StartGUI and includes all logic for the class + * @param stage sets the stage to which we will execute the scene of the StartGUI class */ - public Stage initializeStart(Stage stage) { + public void initializeStart(Stage stage) { /** * Creates an HBox at the center of the borderpane with a width of 200, height of 100 and spacing of 10. @@ -234,6 +229,5 @@ public class StartGUI extends Player { stage.setScene(root); stage.setHeight(510); stage.setWidth(600); - return stage; } } diff --git a/src/gui/TaipanShopGUI.java b/src/gui/TaipanShopGUI.java index 0e44c32..9cf6aac 100644 --- a/src/gui/TaipanShopGUI.java +++ b/src/gui/TaipanShopGUI.java @@ -237,9 +237,9 @@ public class TaipanShopGUI extends Player { } /** - * Initializes the shop on the given stage as a parameter. + * Sets up the graphical part of TaipanGUI and includes all logic for the class * - * @param stage + * @param stage sets the stage to which we will execute the scene of the TaipanGUI class */ public void initializeShop(Stage stage) { FileSaving saving = new FileSaving(); @@ -549,6 +549,12 @@ public class TaipanShopGUI extends Player { } + /** + * The anchor pane shown to the user, used to display the current stats of the player + * @param flowPane,firm,wItemsText,wItemSpaceText,locationText, gunsText, inventoryText, inventoryHeldText, shipStatusText, cashText, bankText assigned from the original element inside of the JavaFX scene + * @param textOut the output so that the player can see all of the text given + * @return The AnchorPane with all the elements already declared + */ public AnchorPane declareStage(FlowPane flowPane,Label firm, Label wItemsText, Label wItemSpaceText, Label locationText, Label gunsText, Label inventoryText, Label inventoryHeldText, Label shipStatusText, Label cashText, Label bankText, Label textOut) { //Declaring all the elements required for the information on screen Rectangle dialogueRectangle = new Rectangle(); @@ -723,7 +729,8 @@ public class TaipanShopGUI extends Player { } /** - * updates the text associated with the user's inventory. + * Updates the current stage shown to the player with all the brand new information + * @param firm,wItemsText,wItemSpaceText,locationText, gunsText, inventoryText, inventoryHeldText, shipStatusText, cashText, bankText assigned from the original element inside of the JavaFX scene */ public void updateStage(Label firm, Label wItemsText, Label wItemSpaceText, Label locationText, Label gunsText, Label inventoryText, Label inventoryHeldText, Label shipStatusText, Label cashText, Label bankText) { TaipanShopLogic logic = new TaipanShopLogic(super.getPlayer()); @@ -733,9 +740,12 @@ public class TaipanShopGUI extends Player { 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", logic.getStringLocation())); int itemsInInventory = getCargoSpace() - getSilkHeld() - getOpiumHeld() - getGeneralHeld() - getArmsHeld() - 10 * getGuns(); + //If the inventory is too full if (itemsInInventory < 0) { inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General"); - } else { + } + //If the inventory isn't too full + else { inventoryText.setText(String.format(" Hold %d\n\t Opium\n\t Silk\n\t Arms\n\t General", itemsInInventory)); } gunsText.setText(String.format("Guns %d\n\n\n\n ", getGuns())); diff --git a/src/gui/TravelGUI.java b/src/gui/TravelGUI.java index 7ed1a7e..53730d9 100644 --- a/src/gui/TravelGUI.java +++ b/src/gui/TravelGUI.java @@ -57,7 +57,7 @@ public class TravelGUI extends Player { * @param stage sets the stage to which we will execute the scene of the TravelGUI class * @return stage so that another class can switch to the stage */ - public Stage initializeTravel(Stage stage) { + public void initializeTravel(Stage stage) { //Creating the continue and quit buttons @@ -105,10 +105,14 @@ public class TravelGUI extends Player { stage.setTitle("Travel"); stage.setResizable(false); stage.setScene(root); - return stage; } + /** + * Runs if the continue button is pressed. Used to leave the Travel Screen + * @param stage the stage in which the JavaFX class is brought into + */ public void continueButton(Stage stage) { + //If there are ships attacking, move to the ShipWarfare method if(peasantShipScene && getAttackingShips()){ ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer()); try { @@ -118,14 +122,17 @@ public class TravelGUI extends Player { } stage.show(); } + //If nothing is happening either create a random event or force the player into the shop else if(shopScene){ Random rand = new Random(); int randGenNum = rand.nextInt(3) + 1; + //Forces the player into the shop if(randGenNum >= 2) { TaipanShopGUI shop = new TaipanShopGUI(getPlayer()); shop.initializeShop(stage); stage.show(); } + //Creates a random event for the player else { RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer()); randomEventGUI.initializeRandomEventGUI(stage); @@ -134,7 +141,12 @@ public class TravelGUI extends Player { } } + /** + * Runs if the numberInput is given and input and the Player has pressed Enter or Z + * @param event the input which will be processed and given a proper response afterwars + */ public void numberInput(KeyEvent event) { + //Run the player has pressed Enter or Z if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) { int response; try { @@ -149,11 +161,16 @@ public class TravelGUI extends Player { traveling(event, response, hasTraveled); } } + //Run if the player cargo is too much else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){ textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!"); } } + /** + * Runs if the numberInput is given and input and the Player has pressed Enter or Z + * @param event the input which will be processed and given a proper response afterwards + */ public void traveling(KeyEvent event, int response, boolean hasTraveled) { //Just in case the player types something that was not intended. It will refresh the question and ask it again try { @@ -181,6 +198,10 @@ public class TravelGUI extends Player { } } + /** + * Takes the User's response to the location they want to travel to and returns a output + * @param response Based on the number either asks for the player's input again or stops. + */ public void responseTravel(int response) { if(response == getLocation()){ textOut.setText("\tYou're already here " + getName() + "\n"); @@ -188,7 +209,6 @@ public class TravelGUI extends Player { else{ textOut.setText("\t" + getName() + "; Sorry but could you say that again?"); } - textOut.setText(textOut.getText() + "\n\n\t\t1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n\t\t5) Manila, 6) Singapore, or 7) Batavia?"); } @@ -260,5 +280,4 @@ public class TravelGUI extends Player { } } - } diff --git a/src/logic/BankLogic.java b/src/logic/BankLogic.java index 3d78cef..8737784 100644 --- a/src/logic/BankLogic.java +++ b/src/logic/BankLogic.java @@ -1,4 +1,31 @@ package logic; public class BankLogic extends Player { + + /** + * 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 BankLogic(Player player) { + Player playerDummy = new Player(player); + setPlayer(playerDummy); + } + + /** + * Withdraws a set amount of money from the player's bank account and gives it to the player + * @param withdraw the amount of money which the player is withdrawing + */ + public void withdrawing(int withdraw) { + setMoney(withdraw + getMoney()); + setBank(getBank() - withdraw); + } + + /** + * Deposits a set amount of money from the player to the player's bank account + * @param deposit the amount of money which the player is depositing + */ + public void depositing(int deposit) { + setBank(deposit + getBank()); + setMoney(getMoney() - deposit); + } } diff --git a/src/logic/FileSaving.java b/src/logic/FileSaving.java index f087207..8a449f8 100644 --- a/src/logic/FileSaving.java +++ b/src/logic/FileSaving.java @@ -9,28 +9,36 @@ import java.io.*; public class FileSaving extends Player implements Serializable { - /** - *loads the file of type player which contains all the player instances + * loads the file of type player which contains all the player instances * @return player */ public Player loadFile() { - try { + //Load the previous save file InputStream in = new FileInputStream(new File("src/saves/playerSave.txt")); return getPlayer(in); } catch (Exception e) { try { + //Loads the player save in a alternate location if the original location isn't available InputStream in = new FileInputStream(new File("saves/playerSave.txt")); return getPlayer(in); } catch(Exception e2){ + //Only it's impossible for the player to load a file return null; } } } + /** + * Only run inside this class, returns save files. Throws exceptions if it fails + * @param in The input stream from the previous save(If there is one) + * @return Returns the player object from the previous save file + * @throws IOException Only if the file cannot be read + * @throws ClassNotFoundException Only if there is no file available for the player to load + */ private Player getPlayer(InputStream in) throws IOException, ClassNotFoundException { ObjectInputStream inObject = new ObjectInputStream(in); Player player = (Player) inObject.readObject(); @@ -45,6 +53,7 @@ public class FileSaving extends Player implements Serializable { */ public boolean saveFile(Player player){ try{ + //Saves the object to a file FileOutputStream out = new FileOutputStream(new File("src/saves/playerSave.txt")); ObjectOutputStream outObject = new ObjectOutputStream(out); outObject.writeObject(player); @@ -52,20 +61,23 @@ public class FileSaving extends Player implements Serializable { out.close(); outObject.close(); - //returns true if program can save file + //returns true if program can save the file return true; } catch (Exception e) { try { + //If the player is running from the terminal it changes the files location, this catch statement fixes that FileOutputStream out = new FileOutputStream(new File("saves/playerSave.txt")); ObjectOutputStream outObject = new ObjectOutputStream(out); outObject.writeObject(player); out.close(); outObject.close(); + //returns true if the program can save the file return true; } catch(Exception e2){ + //returns false if it's impossible for the player to save the file return false; } } diff --git a/src/logic/GameEndLogic.java b/src/logic/GameEndLogic.java index 1e203b3..e948c11 100644 --- a/src/logic/GameEndLogic.java +++ b/src/logic/GameEndLogic.java @@ -1,8 +1,10 @@ package logic; public class GameEndLogic extends Player{ + /** - * Calculates the networth of the player by the end of the game + * Calculates the networth of the player by the end of the game. + * Calculation is based off the total guns and items bought throughout the game * @return the total networth of the player */ public int getNetWorth() { @@ -24,4 +26,13 @@ public class GameEndLogic extends Player{ return "Congratulations!"; } } + + /** + * A method that creates an array filled will all the user's stats + * @param netWorthInt the total net worth of the user + * @return Returns the firm name of the user, the guns they held and their total net worth + */ + public String[] endGameStats(int netWorthInt) { + return new String[]{"Firm Name: " + getName(), "Guns Held: " + getGuns(), "Net Worth: " + netWorthInt}; + } } diff --git a/src/logic/LoanSharkLogic.java b/src/logic/LoanSharkLogic.java new file mode 100644 index 0000000..bd87b14 --- /dev/null +++ b/src/logic/LoanSharkLogic.java @@ -0,0 +1,24 @@ +package logic; + +public class LoanSharkLogic extends Player{ + + /** + * 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 LoanSharkLogic(Player player) { + Player playerDummy = new Player(player); + setPlayer(playerDummy); + } + + /** + * Used to set and change loans for the Player + * @param debt the amount of money the loan is for + * @param money How much money is either taken or give to the Player + */ + public void changeLoan(int debt, int money) { + setDebt(debt); + setMoney(money); + } +} diff --git a/src/logic/RandomEventLogic.java b/src/logic/RandomEventLogic.java index 0e8d65a..67ee84e 100644 --- a/src/logic/RandomEventLogic.java +++ b/src/logic/RandomEventLogic.java @@ -6,7 +6,6 @@ public class RandomEventLogic extends Player{ /** * 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 RandomEventLogic(Player player) { @@ -15,9 +14,9 @@ public class RandomEventLogic extends Player{ } /** - * Method that generates a random number and based on that number, a random event happens. - * - */ + * Method that generates a random number and based on that number, a random event happens. + * @return randGenNum and itemPrice, randGen number is the number which dictates the event, the item price is how much it will cost + */ public int[] randEvent() { Random rand = new Random(); int itemPrice; @@ -39,6 +38,7 @@ public class RandomEventLogic extends Player{ itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10); break; } + //Forces random event to be gun related if nothing else is avaliable else { randGenNum = 2; } diff --git a/src/logic/ShipWarfareLogic.java b/src/logic/ShipWarfareLogic.java index 5289e12..273c1fb 100644 --- a/src/logic/ShipWarfareLogic.java +++ b/src/logic/ShipWarfareLogic.java @@ -16,7 +16,6 @@ public class ShipWarfareLogic extends Player { /** * 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. */ diff --git a/src/logic/StartLogic.java b/src/logic/StartLogic.java index 9175ac1..4d09623 100644 --- a/src/logic/StartLogic.java +++ b/src/logic/StartLogic.java @@ -4,7 +4,6 @@ public class StartLogic extends Player { /** * 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 StartLogic(Player player) { @@ -13,9 +12,9 @@ public class StartLogic extends Player { } /** + * Used in the Start Class * method that sets the player's money and debt to 400 and 5000 respectively. * also sets the player's guns to 0. - * */ public void money_and_debt() { setMoney(400); @@ -24,17 +23,17 @@ public class StartLogic extends Player { } /** + * Used in the Start Class * method that sets the player's guns to 5. - * */ public void guns() { setGuns(5); } /** + * Used in the Start Class * for testing purposes * sets the player's money, bank, guns, hp, ad cargo space to max values. - * */ public void cheat() { setMoney(999999999); diff --git a/src/logic/TaipanShopLogic.java b/src/logic/TaipanShopLogic.java index 2dcf213..d9ef277 100644 --- a/src/logic/TaipanShopLogic.java +++ b/src/logic/TaipanShopLogic.java @@ -10,7 +10,6 @@ public class TaipanShopLogic extends Player { /** * 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 TaipanShopLogic(Player player) { @@ -19,7 +18,8 @@ public class TaipanShopLogic extends Player { } /** - * this method is when the shop is accessed, randomizing the prices of all the items. + * This method is used when the shop is accessed, randomizing the prices of all the items. + * @return Returns the string which will be said to the player when they open the shop */ public String updatePrices() { String s = "\t" + getName() + ", the price of "; @@ -72,7 +72,6 @@ public class TaipanShopLogic extends Player { /** * returns the user's condition based upon their current HP. - * * @return shipStatus -- a representation of their ship's health in words. */ public String shipStatusString(){ @@ -96,7 +95,6 @@ public class TaipanShopLogic extends Player { /** * 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(){ diff --git a/src/logic/TravelLogic.java b/src/logic/TravelLogic.java index 7953c77..3eeae4f 100644 --- a/src/logic/TravelLogic.java +++ b/src/logic/TravelLogic.java @@ -4,6 +4,12 @@ import java.util.Random; public class TravelLogic extends Player { + + /** + * 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 TravelLogic(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); @@ -56,6 +62,7 @@ public class TravelLogic extends Player { * * @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed * by a typhoon. + * @return returns the string which is to be said to the player **/ public String disaster(int locationOfTravel) { //Tells player that there is a storm approaching. diff --git a/src/logic/WarehouseLogic.java b/src/logic/WarehouseLogic.java index d94b6c7..aebffab 100644 --- a/src/logic/WarehouseLogic.java +++ b/src/logic/WarehouseLogic.java @@ -13,9 +13,9 @@ public class WarehouseLogic extends Player { } /** - * Method that tranfers your cargo from your ship to your warehouse. + * Method that transfers your cargo from your ship to your warehouse. * Has error handling to prevent incorrect inputs - * + * @return returns the string which is to be said to the player */ public String deposit(String str, int goodsNum) { try { @@ -60,7 +60,7 @@ public class WarehouseLogic extends Player { /** * Method that transfers cargo from your warehouse onto your ship. * Has error handling to prevent incorrect inputs - * + * @return returns the string which is to be said to the player */ public String withdraw(String str, int goodsNum) { try { diff --git a/src/text/BankText.java b/src/text/BankText.java index a74b354..cbe2579 100644 --- a/src/text/BankText.java +++ b/src/text/BankText.java @@ -1,11 +1,16 @@ package text; +import logic.BankLogic; import logic.Player; import java.util.Scanner; public class BankText extends Player { + /** + * Class Constructor that takes in a type player as a parameter + * @param player object of the class Player + */ public BankText(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); @@ -28,52 +33,86 @@ public class BankText extends Player { String response = input.nextLine(); //If user chose withdraw then subtract the amount from bank account and add it to cash if(response.equalsIgnoreCase("W")){ - boolean notDone2 = true; - while(notDone2){ - System.out.println("How much do you wish to Withdraw?"); - int withdraw = input.nextInt(); - //Prompt the user for the amount and check if the bank has sufficient funds - if(withdraw <= getBank()){ - setMoney(withdraw + getMoney()); - setBank(getBank()-withdraw); - notDone2 = false; - check = 1; - } - } - + check = withdraw(input, check); } //If the user chooses to deposit the continue to this code else if(response.equalsIgnoreCase("D")){ - boolean notDone2 = true; - while(notDone2){ - //Prompt the user for the amount they would like to deposit and ensure suffiecent funds - System.out.println("How much do you wish to Deposit?"); - int deposit = input.nextInt(); - if(deposit <= getMoney()){ - setBank(deposit + getBank()); - setMoney(getMoney()-deposit); - notDone2 = false; - check = 1; - } - } + check = deposit(input, check); } if(check == 1){ - boolean notDone3 = true; - // Asks user if they would like to continue in bank or not - while(notDone3){ - System.out.println("Would you like to continue? Y/N"); - response = input.nextLine(); - response = input.nextLine(); - if(response.equalsIgnoreCase("Y")){ - notDone3 = false; - }else if(response.equalsIgnoreCase("N")){ - notDone = false; - notDone3 = false; - } - } + notDone = notContinue(input, notDone); } } + } + /** + * Asks the user if they want to continue staying in Bank + * @param input The Scanner object which is used for asking user questions + * @param notDone Boolean statement which if is false stops the loop in the Bank method + * @return a boolean value which can turn off the original while loop this method is inside + */ + public boolean notContinue(Scanner input, boolean notDone) { + String response; + boolean notDone3 = true; + // Asks user if they would like to continue in bank or not + while(notDone3){ + System.out.println("Would you like to continue? Y/N"); + response = input.nextLine(); + response = input.nextLine(); + if(response.equalsIgnoreCase("Y")){ + notDone3 = false; + }else if(response.equalsIgnoreCase("N")){ + notDone = false; + notDone3 = false; + } + } + return notDone; + } + + /** + * Asks the user how much they want to deposit + * @param input The Scanner object which is used for asking user questions + * @param check an integer value which changes depending on the stages of the bank class + * @return a boolean value which can turn off the original while loop this method is inside + */ + public int deposit(Scanner input, int check) { + boolean notDone2 = true; + while(notDone2){ + //Prompt the user for the amount they would like to deposit and ensure suffiecent funds + System.out.println("How much do you wish to Deposit?"); + int deposit = input.nextInt(); + if(deposit <= getMoney()){ + BankLogic bankLogic = new BankLogic(getPlayer()); + bankLogic.depositing(deposit); + setPlayer(bankLogic.getPlayer()); + notDone2 = false; + check = 1; + } + } + return check; + } + + /** + * Asks the user how much they want to withdrawe + * @param input The Scanner object which is used for asking user questions + * @param check an integer value which changes depending on the stages of the bank class + * @return a boolean value which can turn off the original while loop this method is inside + */ + public int withdraw(Scanner input, int check) { + boolean notDone2 = true; + while(notDone2){ + System.out.println("How much do you wish to Withdraw?"); + int withdraw = input.nextInt(); + //Prompt the user for the amount and check if the bank has sufficient funds + if(withdraw <= getBank()){ + BankLogic bankLogic = new BankLogic(getPlayer()); + bankLogic.withdrawing(withdraw); + setPlayer(bankLogic.getPlayer()); + notDone2 = false; + check = 1; + } + } + return check; } } diff --git a/src/text/GameEndText.java b/src/text/GameEndText.java index 402748d..3ca9fbf 100644 --- a/src/text/GameEndText.java +++ b/src/text/GameEndText.java @@ -1,12 +1,36 @@ package text; +import logic.GameEndLogic; import logic.Player; public class GameEndText extends Player { + /** + * Class Constructor that takes in a type player as a parameter + * + * @param player object of the class Player + */ public GameEndText(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); } + /** + * At the end of the game, the end game stats appear the Firm's name, the number of guns held by the player and the networth of the player + */ + public void gameEnd(){ + //Calculating the netWorth of the Player + GameEndLogic gameEndLogic = new GameEndLogic(); + int netWorthInt = gameEndLogic.getNetWorth(); + + //Adding the labels to the character's stats to the VBox which will show up on the screen + System.out.println(gameEndLogic.endGameText()); + + String[] strings = gameEndLogic.endGameStats(netWorthInt); + //Updating the endgame stats of the player + System.out.println(strings[0]); + System.out.println(strings[1]); + System.out.println(strings[2]); + } + } diff --git a/src/text/LoanSharkText.java b/src/text/LoanSharkText.java index fef0da4..e5f8e7f 100644 --- a/src/text/LoanSharkText.java +++ b/src/text/LoanSharkText.java @@ -1,13 +1,85 @@ package text; +import logic.LoanSharkLogic; import logic.Player; +import java.util.Scanner; + public class LoanSharkText extends Player { + + /** + * 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 LoanSharkText(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); } + /** + * Either give the player a loan or it allows the player to pay a debt + */ public void loanMoney() { + System.out.println("Debt: " + getDebt()); + System.out.println("Cash: " + getMoney()); + System.out.println("Would you like you get a (l)oan or (p)ay a debt?"); + + Scanner keyboard = new Scanner(System.in); + //Pay off loan + if (keyboard.nextLine().equalsIgnoreCase("p")) { + System.out.println("How much of your debt would you like to pay?"); + try { + int returnAsk = Integer.parseInt(keyboard.nextLine()); + //If the player enters a invalid number + if (returnAsk > getDebt()) { + System.out.println("You do not need to return that much."); + } + //If the player enters a valid number + else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) { + LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer()); + loanSharkLogic.changeLoan(getDebt() - returnAsk, getMoney() - returnAsk); + setPlayer(loanSharkLogic.getPlayer()); + } + //If the player enters a invalid number + else if (getMoney() < returnAsk) { + System.out.println("Look " + getName() + ", you are being cheap!"); + } + //If the player enters a negative number + else { + System.out.println("Sorry, you can not return a negative amount!"); + } + } + //Only runs if the user gives an invalid input + catch (Exception e) { + System.out.println("Please enter a valid value"); + } + } + //Ask for Loan + else if (keyboard.nextLine().equalsIgnoreCase("l")) { + System.out.println("How big of a loan would you like?"); + try { + int loanAsk = Integer.parseInt(keyboard.nextLine()); + //If the player enters a valid number + if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) { + LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer()); + loanSharkLogic.changeLoan(getDebt() + loanAsk, getMoney() + loanAsk); + setPlayer(loanSharkLogic.getPlayer()); + System.out.println("Cash: " + getMoney()); + } + //If the player enters a negative number + else if (loanAsk < 0) { + System.out.println("Sorry you cannot enter negative numbers"); + } + //If the player enters a invalid number + else { + System.out.println("Sorry you cannot get the loan requested"); + } + } + //Only runs if the user gives an invalid input + catch (Exception e) { + System.out.println("Please enter a valid value"); + } + } } } diff --git a/src/text/RandomEventText.java b/src/text/RandomEventText.java index acc1d89..ace022c 100644 --- a/src/text/RandomEventText.java +++ b/src/text/RandomEventText.java @@ -7,11 +7,21 @@ import logic.RandomEventLogic; import java.util.Scanner; public class RandomEventText extends Player { + + /** + * Class Constructor that takes in a type player as a parameter + * + * @param player object of the class Player + */ public RandomEventText(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); } + /** + * Picks a random number and based off that number the player is put into a random event + * The random event can be anything from ship repair to paying bribes to the enemy fleet + */ public void randomEvent(){ /*Pick a random number dictating the events that could happen. * 1: New gun for player @@ -33,16 +43,18 @@ public class RandomEventText extends Player { System.out.println("\nMc Henry from the Hong Kong shipyard has arrived,\nwould be willing to repair your ship for $" + itemPrice); } + //Only runs if the player doesn't have enough space and is given a gun if((eventNumber == 1 && getCargoSpace() < 10)){ TaipanShopText taipanShopText = new TaipanShopText(getPlayer()); taipanShopText.shop(); } + //Only runs if the player has 100 or greater HP and they got the ship repair man if((eventNumber == 3 && getPlayer().getHP() >= 100)){ TaipanShopText taipanShopText = new TaipanShopText(getPlayer()); taipanShopText.shop(); } - + //Runs for as long as the player doesn't decide if they want to pay while(true){ System.out.println("Would you like to pay? (Y)es or (N)o"); Scanner keyboard = new Scanner(System.in); @@ -80,6 +92,7 @@ public class RandomEventText extends Player { else { System.out.println("Sorry you don't have enough money"); } + //If the player decides to leave then it will send them back to TaipanShop if(input.equalsIgnoreCase("N")){ System.out.println("Aye aye Taipan, we'll send them off!\n"); TaipanShopText taipanShopText = new TaipanShopText(getPlayer()); diff --git a/src/text/ShipWarfareText.java b/src/text/ShipWarfareText.java index e249bd6..713a04b 100644 --- a/src/text/ShipWarfareText.java +++ b/src/text/ShipWarfareText.java @@ -158,9 +158,11 @@ public class ShipWarfareText extends Player { } } else { + GameEndText gameEndText = new GameEndText(getPlayer()); + gameEndText.gameEnd(); + setPlayer(gameEndText.getPlayer()); exitValue = 2; } - return exitValue; } diff --git a/src/text/StartText.java b/src/text/StartText.java index 36d6032..dbf4917 100644 --- a/src/text/StartText.java +++ b/src/text/StartText.java @@ -8,6 +8,11 @@ import java.util.Scanner; public class StartText extends Player { + /** + * Class Constructor that takes in a type player as a parameter + * + * @param player object of the class Player + */ public StartText(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); @@ -20,9 +25,11 @@ public class StartText extends Player { public void start() { Scanner userInput = new Scanner(System.in); + //See if the player wants to load up a previous save System.out.println("Taipan, do you want to...\n\t1) load a save file?\n\t\t\t>> or <<\n\t2) make a new save file?"); while (true) { int input = userInput.nextInt(); + //Will attempt to load the save if it's not empty if(input == 1){ FileSaving saving = new FileSaving(); if(saving.loadFile() != null){ @@ -34,6 +41,7 @@ public class StartText extends Player { } break; } + //Just makes a new save else if(input == 2){ break; } @@ -42,18 +50,19 @@ public class StartText extends Player { } } - - + //Asks the player about their firm name and what kind of start they want System.out.println("Taipan, \nWhat will you name your firm:"); setName(userInput.nextLine()); System.out.println("Do you want to start . . .\n\t1) With cash (and a debt)\n\t\t\t>> or <<\n\t" + "2) With five guns and no cash (But no debt!)?\n "); while (true) { int input = userInput.nextInt(); StartLogic startLogic = new StartLogic(getPlayer()); + //If the player wants the money and debt starting if (input == 1) { startLogic.money_and_debt(); break; } + //If the player wants the gun start else if (input == 2) { startLogic.guns(); break; diff --git a/src/text/TaipanShopText.java b/src/text/TaipanShopText.java index 20185d7..7689764 100644 --- a/src/text/TaipanShopText.java +++ b/src/text/TaipanShopText.java @@ -13,14 +13,6 @@ import logic.TaipanShopLogic; * Author: Vikram Bawa */ public class TaipanShopText extends Player { - /** - * This method is evoked if the user is eligible to win, and chooses to end the game (by winning). - */ - public void retire(){ - setRetire(true); - System.out.println("You win!"); - System.exit(0); - } /** * constructor; only runs when a Player object is provided. The constructor is fully encapsulated. @@ -32,6 +24,15 @@ public class TaipanShopText extends Player { setPlayer(playerDummy); } + /** + * This method is evoked if the user is eligible to win, and chooses to end the game (by winning). + */ + public void retire(){ + setRetire(true); + System.out.println("You win!"); + System.exit(0); + } + /** * this method is evoked if the user has decided to travel elsewhere. */ @@ -133,6 +134,12 @@ public class TaipanShopText extends Player { } + /** + * Actually runs the shop program so that the user can both buy and sell things. + * @param notDone,caseNum both parameters govern the inner logic of the class and whether it allows for the player to run the shop + * @param optionText Text which is printed along with the rest of the shop + * @param input The scanner object that allows the program to respond to they user's inputs + */ public void runShop(boolean notDone, int caseNum, String optionText, Scanner input) { // as long as the user does not enter a valid input, the code will run in a loop forever. while(notDone){ @@ -171,6 +178,11 @@ public class TaipanShopText extends Player { } } + /** + * For all the buying inside the text-based shop + * @param input Takes the input Scanner and uses it to respond the user's inputs + * @param notDone2 Boolean which rules each while loop, if it turns false then the while loops stop + */ public void buying(Scanner input, boolean notDone2) { String response; while (notDone2) { @@ -235,6 +247,11 @@ public class TaipanShopText extends Player { } } + /** + * For all the selling inside the text-based shop + * @param input Takes the input Scanner and uses it to respond the user's inputs + * @param notDone2 Boolean which rules each while loop, if it turns false then the while loops stop + */ public void selling(Scanner input, boolean notDone2) { String response; while (notDone2) { diff --git a/src/text/TravelText.java b/src/text/TravelText.java index 16f5145..7947738 100644 --- a/src/text/TravelText.java +++ b/src/text/TravelText.java @@ -1,7 +1,5 @@ package text; -import gui.RandomEventGUI; -import gui.TaipanShopGUI; import logic.Player; import logic.TravelLogic; @@ -10,6 +8,11 @@ import java.util.Scanner; public class TravelText extends Player { + /** + * 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 TravelText(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy); @@ -54,14 +57,25 @@ public class TravelText extends Player { } } + /** + * The traveling method, it changes the location of the player and increments their interest and debt everytime the player travels + * Also allows for the player to be attacked by enemy ships and to be hit by random encounters. + * @param keyboard The Scanner object which allows for the program to respond to the user + * @param hasTraveled Checks whether the user has traveled or not + */ public void traveling(Scanner keyboard, boolean hasTraveled) { String response; int tempInt; while (true) { System.out.println("\n" + getName() + ", do you wish to go to:\n"); - System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?"); + System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia? or (Q)uit"); response = keyboard.nextLine(); + //Sends the player back to shop if they want to quit + if(response.equalsIgnoreCase("Q")){ + TaipanShopText taipanShopText = new TaipanShopText(getPlayer()); + taipanShopText.shop(); + } //Just in case the player types something that was not intended. It will refresh the question and ask it again try { tempInt = Integer.parseInt(response); @@ -69,6 +83,7 @@ public class TravelText extends Player { if (tempInt != getLocation()) { randomEventSea(tempInt); + //Checks the seaAtlas to see if the player can go to their location TravelLogic travelLogic = new TravelLogic(getPlayer()); travelLogic.seaAtlas(tempInt); setPlayer(travelLogic.getPlayer()); @@ -82,14 +97,17 @@ public class TravelText extends Player { } catch (Exception e) { System.out.print("\nSorry, " + getName() + " could you say that again?"); } + //If they've traveled then it randomly selects whether the player should go to the shop or a random event if (hasTraveled) { Random rand = new Random(); int randGenNum = rand.nextInt(3) + 1; + //Chance of going to shop if(randGenNum >= 2) { TaipanShopText taipanShopText = new TaipanShopText(getPlayer()); taipanShopText.shop(); } + //Chance of reaching a random event else { RandomEventText randomEventText = new RandomEventText(getPlayer()); randomEventText.randomEvent(); diff --git a/src/text/WarehouseText.java b/src/text/WarehouseText.java index d885151..c028352 100644 --- a/src/text/WarehouseText.java +++ b/src/text/WarehouseText.java @@ -7,6 +7,11 @@ import java.util.Scanner; public class WarehouseText extends Player { + /** + * Class Constructor that takes in a type player as a parameter + * + * @param player object of the class Player + */ public WarehouseText(Player player) { Player playerDummy = new Player(player); setPlayer(playerDummy);