Redid a bunch of commenting making sure that every method was commented.

This commit is contained in:
2019-04-12 03:54:20 -06:00
parent 03ff12b832
commit f89c1aa209
28 changed files with 508 additions and 218 deletions

View File

@@ -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<ActionEvent>() {
@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();
}
}

View File

@@ -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();
}
}

View File

@@ -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<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
int loanAsk = Integer.parseInt(txtField1.getText());
if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) {
setDebt(getDebt() + loanAsk);
setMoney(getMoney() + loanAsk);
l4.setText("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<ActionEvent>() {
@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<ActionEvent>() {
@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");
}
}
}

View File

@@ -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 {
/**

View File

@@ -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;
}

View File

@@ -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());

View File

@@ -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;
}
}

View File

@@ -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()));

View File

@@ -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 {
}
}
}