Redid a bunch of commenting making sure that every method was commented.
This commit is contained in:
@@ -12,18 +12,18 @@ import javafx.scene.layout.BorderPane;
|
|||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import logic.BankLogic;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
public class BankGUI extends Player {
|
/**
|
||||||
/**
|
|
||||||
* 2019-03-10
|
* 2019-03-10
|
||||||
* Authors: Siddhant Dewani
|
* Authors: Siddhant Dewani
|
||||||
* BankGUI allows the user to store cash and gain interest off of the cash
|
* BankGUI allows the user to store cash and gain interest off of the cash
|
||||||
*/
|
*/
|
||||||
|
public class BankGUI extends Player {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor that takes in a type player as a parameter
|
* Class Constructor that takes in a type player as a parameter
|
||||||
*
|
|
||||||
* @param player object of the class Player
|
* @param player object of the class Player
|
||||||
*/
|
*/
|
||||||
public BankGUI(Player player) {
|
public BankGUI(Player player) {
|
||||||
@@ -33,16 +33,14 @@ public class BankGUI extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the GUI for the Bank in our game.
|
* Initializes the GUI for the Bank in our game.
|
||||||
*
|
* @param primaryStage the stage in which everything in this class is shown
|
||||||
* @param primaryStage
|
* @return Returns the stage in which can be used by other stages
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Stage initializeBank(Stage primaryStage) {
|
public void initializeBank(Stage primaryStage) {
|
||||||
primaryStage.setTitle("Bank");
|
primaryStage.setTitle("Bank");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creating all the layouts, labels, buttons, and a textfield.
|
* Creating all the layouts, labels, buttons, and a textfield.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
BorderPane brdr1 = new BorderPane();
|
BorderPane brdr1 = new BorderPane();
|
||||||
HBox hbx1 = new HBox(30);
|
HBox hbx1 = new HBox(30);
|
||||||
@@ -63,7 +61,6 @@ public class BankGUI extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the buttons so that they are at the bottom of the screen.
|
* Adds the buttons so that they are at the bottom of the screen.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
hbx1.setAlignment(Pos.CENTER);
|
hbx1.setAlignment(Pos.CENTER);
|
||||||
hbx1.getChildren().add(b1);
|
hbx1.getChildren().add(b1);
|
||||||
@@ -83,7 +80,6 @@ public class BankGUI extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the labels to the top of the screen.
|
* Adds the labels to the top of the screen.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
vbx1.setAlignment(Pos.CENTER);
|
vbx1.setAlignment(Pos.CENTER);
|
||||||
vbx1.getChildren().add(l1);
|
vbx1.getChildren().add(l1);
|
||||||
@@ -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.
|
* Adds function to button 1 which, when clicked, withdraws money from your bank to your person but, will not let you overdraw.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
b1.setOnAction(new EventHandler<ActionEvent>() {
|
b1.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -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.
|
* Sets the window size to a width of 600 and height of 480 and displays the screen.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
Scene scene = new Scene(brdr1, 600, 480);
|
Scene scene = new Scene(brdr1, 600, 480);
|
||||||
scene.getStylesheets().add("styleguide.css");
|
scene.getStylesheets().add("styleguide.css");
|
||||||
primaryStage.setScene(scene);
|
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) {
|
private void deposits(TextField txtField1, Label l5, Label l2, Label l4) {
|
||||||
try {
|
try {
|
||||||
int deposit = Integer.parseInt(txtField1.getText());
|
int deposit = Integer.parseInt(txtField1.getText());
|
||||||
if (deposit < 0) {
|
if (deposit < 0) {
|
||||||
l5.setText("Nice try! You can not enter negative numbers.");
|
l5.setText("Nice try! You can not enter negative numbers.");
|
||||||
} else if (deposit <= getMoney()) {
|
} else if (deposit <= getMoney()) {
|
||||||
setBank(deposit + getBank());
|
BankLogic bankLogic = new BankLogic(getPlayer());
|
||||||
setMoney(getMoney() - deposit);
|
bankLogic.depositing(deposit);
|
||||||
|
setPlayer(bankLogic.getPlayer());
|
||||||
} else {
|
} else {
|
||||||
l5.setText("Sorry, you can not deposit that much.");
|
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) {
|
private void withdraw(TextField txtField1, Label l5, Label l2, Label l4) {
|
||||||
try {
|
try {
|
||||||
int withdraw = Integer.parseInt(txtField1.getText());
|
int withdraw = Integer.parseInt(txtField1.getText());
|
||||||
if (withdraw < 0) {
|
if (withdraw < 0) {
|
||||||
l5.setText("Come on " + getName() + ", are you trying to fool me?\nNo negative numbers please!");
|
l5.setText("Come on " + getName() + ", are you trying to fool me?\nNo negative numbers please!");
|
||||||
} else if (withdraw <= getBank()) {
|
} else if (withdraw <= getBank()) {
|
||||||
setMoney(withdraw + getMoney());
|
BankLogic bankLogic = new BankLogic(getPlayer());
|
||||||
setBank(getBank() - withdraw);
|
bankLogic.withdrawing(withdraw);
|
||||||
|
setPlayer(bankLogic.getPlayer());
|
||||||
} else {
|
} else {
|
||||||
l5.setText("Sorry, you can not withdraw that much.");
|
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.");
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ public class GameEndGUI extends Player {
|
|||||||
private Label netWorth;
|
private Label netWorth;
|
||||||
private BorderPane borderPane;
|
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) {
|
public GameEndGUI(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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
|
* @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
|
* @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
|
//Creating all the nodes
|
||||||
title = new Label();
|
title = new Label();
|
||||||
@@ -83,10 +88,11 @@ public class GameEndGUI extends Player {
|
|||||||
vBox.getChildren().add(netWorth);
|
vBox.getChildren().add(netWorth);
|
||||||
title.setText(gameEndLogic.endGameText());
|
title.setText(gameEndLogic.endGameText());
|
||||||
|
|
||||||
|
String[] strings = gameEndLogic.endGameStats(netWorthInt);
|
||||||
//Updating the endgame stats of the player
|
//Updating the endgame stats of the player
|
||||||
firmName.setText("Firm Name: " + getName());
|
firmName.setText(strings[0]);
|
||||||
gunsHeld.setText("Guns Held: " + getGuns());
|
gunsHeld.setText(strings[1]);
|
||||||
netWorth.setText("Net Worth: " + netWorthInt);
|
netWorth.setText(strings[2]);
|
||||||
|
|
||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
root.getStylesheets().add("styleguide.css");
|
root.getStylesheets().add("styleguide.css");
|
||||||
@@ -94,18 +100,7 @@ public class GameEndGUI extends Player {
|
|||||||
stage.setTitle("End Game Stats");
|
stage.setTitle("End Game Stats");
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
stage.setScene(root);
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@@ -12,6 +10,7 @@ import javafx.scene.layout.BorderPane;
|
|||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import logic.LoanSharkLogic;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +41,7 @@ public class LoanSharkGUI extends Player {
|
|||||||
*
|
*
|
||||||
* @param primaryStage the stage upon which the GUI will be imposed
|
* @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");
|
primaryStage.setTitle("Loan Shark");
|
||||||
|
|
||||||
//Declaring each Layout
|
//Declaring each Layout
|
||||||
@@ -92,73 +91,20 @@ public class LoanSharkGUI extends Player {
|
|||||||
brdr1.setTop(vbx1);
|
brdr1.setTop(vbx1);
|
||||||
|
|
||||||
// Set the event handler when the deposit button is clicked
|
// Set the event handler when the deposit button is clicked
|
||||||
b1.setOnAction(new EventHandler<ActionEvent>() {
|
b1.setOnAction(event -> {
|
||||||
@Override
|
depositButton(l2, l4, l5, txtField1);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set the event handler when the withdraw button is clicked
|
// Set the event handler when the withdraw button is clicked
|
||||||
b2.setOnAction(new EventHandler<ActionEvent>() {
|
b2.setOnAction(event -> {
|
||||||
@Override
|
withdrawButton(l2, l4, l5, txtField1);
|
||||||
public void handle(ActionEvent event) {
|
});
|
||||||
try {
|
|
||||||
|
|
||||||
|
b3.setOnAction(event -> {
|
||||||
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());
|
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
|
||||||
shopGUI.initializeShop(primaryStage);
|
shopGUI.initializeShop(primaryStage);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -166,8 +112,71 @@ public class LoanSharkGUI extends Player {
|
|||||||
Scene scene = new Scene(brdr1, 600, 480);
|
Scene scene = new Scene(brdr1, 600, 480);
|
||||||
scene.getStylesheets().add("styleguide.css");
|
scene.getStylesheets().add("styleguide.css");
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
//primaryStage.show();
|
primaryStage.show();
|
||||||
return primaryStage;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import logic.Player;
|
|||||||
* 2019-03-10
|
* 2019-03-10
|
||||||
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
||||||
* MainGUI class, Initializes the entire game and runs the game for user to play
|
* MainGUI class, Initializes the entire game and runs the game for user to play
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MainGUI extends Application {
|
public class MainGUI extends Application {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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
|
//Creating the nodes within the event screen
|
||||||
hBox = new HBox();
|
hBox = new HBox();
|
||||||
yesButton = new Button();
|
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);
|
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)){
|
if((eventNumber == 1 && getCargoSpace() < 10)){
|
||||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
||||||
taipanShopGUI.initializeShop(stage);
|
taipanShopGUI.initializeShop(stage);
|
||||||
stage.show();
|
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)){
|
if((eventNumber == 3 && getPlayer().getHP() >= 100)){
|
||||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
||||||
taipanShopGUI.initializeShop(stage);
|
taipanShopGUI.initializeShop(stage);
|
||||||
@@ -210,10 +212,9 @@ public class RandomEventGUI extends Player {
|
|||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
root.getStylesheets().add("styleguide.css");
|
root.getStylesheets().add("styleguide.css");
|
||||||
|
|
||||||
stage.setTitle("Travel");
|
stage.setTitle("Random Event");
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
stage.setScene(root);
|
stage.setScene(root);
|
||||||
return stage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import javafx.animation.*;
|
import javafx.animation.*;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
@@ -29,8 +27,6 @@ import logic.ShipWarfareLogic;
|
|||||||
* Author: Haris Muhammad
|
* Author: Haris Muhammad
|
||||||
* ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from
|
* ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class ShipWarfareGUI extends Player {
|
public class ShipWarfareGUI extends Player {
|
||||||
|
|
||||||
ShipWarfareLogic logic = new ShipWarfareLogic(getPlayer());
|
ShipWarfareLogic logic = new ShipWarfareLogic(getPlayer());
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
@@ -18,7 +16,6 @@ import logic.StartLogic;
|
|||||||
* 2019-03-10
|
* 2019-03-10
|
||||||
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
||||||
* StartGUI class, Initializes and displays the start menu for Taipan
|
* 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.
|
* 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
|
||||||
* @param stage object of type Stage
|
|
||||||
* @return returns the stage of GUI
|
|
||||||
*/
|
*/
|
||||||
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.
|
* 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.setScene(root);
|
||||||
stage.setHeight(510);
|
stage.setHeight(510);
|
||||||
stage.setWidth(600);
|
stage.setWidth(600);
|
||||||
return stage;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
public void initializeShop(Stage stage) {
|
||||||
FileSaving saving = new FileSaving();
|
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) {
|
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
|
//Declaring all the elements required for the information on screen
|
||||||
Rectangle dialogueRectangle = new Rectangle();
|
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) {
|
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());
|
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)));
|
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()));
|
locationText.setText(String.format("Location\n%s", logic.getStringLocation()));
|
||||||
int itemsInInventory = getCargoSpace() - getSilkHeld() - getOpiumHeld() - getGeneralHeld() - getArmsHeld() - 10 * getGuns();
|
int itemsInInventory = getCargoSpace() - getSilkHeld() - getOpiumHeld() - getGeneralHeld() - getArmsHeld() - 10 * getGuns();
|
||||||
|
//If the inventory is too full
|
||||||
if (itemsInInventory < 0) {
|
if (itemsInInventory < 0) {
|
||||||
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
|
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));
|
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()));
|
gunsText.setText(String.format("Guns %d\n\n\n\n ", getGuns()));
|
||||||
|
|||||||
@@ -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
|
* @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
|
* @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
|
//Creating the continue and quit buttons
|
||||||
@@ -105,10 +105,14 @@ public class TravelGUI extends Player {
|
|||||||
stage.setTitle("Travel");
|
stage.setTitle("Travel");
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
stage.setScene(root);
|
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) {
|
public void continueButton(Stage stage) {
|
||||||
|
//If there are ships attacking, move to the ShipWarfare method
|
||||||
if(peasantShipScene && getAttackingShips()){
|
if(peasantShipScene && getAttackingShips()){
|
||||||
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
|
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
|
||||||
try {
|
try {
|
||||||
@@ -118,14 +122,17 @@ public class TravelGUI extends Player {
|
|||||||
}
|
}
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
//If nothing is happening either create a random event or force the player into the shop
|
||||||
else if(shopScene){
|
else if(shopScene){
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
//Forces the player into the shop
|
||||||
if(randGenNum >= 2) {
|
if(randGenNum >= 2) {
|
||||||
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
||||||
shop.initializeShop(stage);
|
shop.initializeShop(stage);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
//Creates a random event for the player
|
||||||
else {
|
else {
|
||||||
RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer());
|
RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer());
|
||||||
randomEventGUI.initializeRandomEventGUI(stage);
|
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) {
|
public void numberInput(KeyEvent event) {
|
||||||
|
//Run the player has pressed Enter or Z
|
||||||
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
|
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
|
||||||
int response;
|
int response;
|
||||||
try {
|
try {
|
||||||
@@ -149,11 +161,16 @@ public class TravelGUI extends Player {
|
|||||||
traveling(event, response, hasTraveled);
|
traveling(event, response, hasTraveled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Run if the player cargo is too much
|
||||||
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
|
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
|
||||||
textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!");
|
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) {
|
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
|
//Just in case the player types something that was not intended. It will refresh the question and ask it again
|
||||||
try {
|
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) {
|
public void responseTravel(int response) {
|
||||||
if(response == getLocation()){
|
if(response == getLocation()){
|
||||||
textOut.setText("\tYou're already here " + getName() + "\n");
|
textOut.setText("\tYou're already here " + getName() + "\n");
|
||||||
@@ -188,7 +209,6 @@ public class TravelGUI extends Player {
|
|||||||
else{
|
else{
|
||||||
textOut.setText("\t" + getName() + "; Sorry but could you say that again?");
|
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?");
|
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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,31 @@
|
|||||||
package logic;
|
package logic;
|
||||||
|
|
||||||
public class BankLogic extends Player {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,28 +9,36 @@ import java.io.*;
|
|||||||
|
|
||||||
public class FileSaving extends Player implements Serializable {
|
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
|
* @return player
|
||||||
*/
|
*/
|
||||||
public Player loadFile() {
|
public Player loadFile() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
//Load the previous save file
|
||||||
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
|
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
|
||||||
return getPlayer(in);
|
return getPlayer(in);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
try {
|
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"));
|
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
|
||||||
return getPlayer(in);
|
return getPlayer(in);
|
||||||
}
|
}
|
||||||
catch(Exception e2){
|
catch(Exception e2){
|
||||||
|
//Only it's impossible for the player to load a file
|
||||||
return null;
|
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 {
|
private Player getPlayer(InputStream in) throws IOException, ClassNotFoundException {
|
||||||
ObjectInputStream inObject = new ObjectInputStream(in);
|
ObjectInputStream inObject = new ObjectInputStream(in);
|
||||||
Player player = (Player) inObject.readObject();
|
Player player = (Player) inObject.readObject();
|
||||||
@@ -45,6 +53,7 @@ public class FileSaving extends Player implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public boolean saveFile(Player player){
|
public boolean saveFile(Player player){
|
||||||
try{
|
try{
|
||||||
|
//Saves the object to a file
|
||||||
FileOutputStream out = new FileOutputStream(new File("src/saves/playerSave.txt"));
|
FileOutputStream out = new FileOutputStream(new File("src/saves/playerSave.txt"));
|
||||||
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
||||||
outObject.writeObject(player);
|
outObject.writeObject(player);
|
||||||
@@ -52,20 +61,23 @@ public class FileSaving extends Player implements Serializable {
|
|||||||
out.close();
|
out.close();
|
||||||
outObject.close();
|
outObject.close();
|
||||||
|
|
||||||
//returns true if program can save file
|
//returns true if program can save the file
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
try {
|
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"));
|
FileOutputStream out = new FileOutputStream(new File("saves/playerSave.txt"));
|
||||||
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
||||||
outObject.writeObject(player);
|
outObject.writeObject(player);
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
outObject.close();
|
outObject.close();
|
||||||
|
//returns true if the program can save the file
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(Exception e2){
|
catch(Exception e2){
|
||||||
|
//returns false if it's impossible for the player to save the file
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package logic;
|
package logic;
|
||||||
|
|
||||||
public class GameEndLogic extends Player{
|
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
|
* @return the total networth of the player
|
||||||
*/
|
*/
|
||||||
public int getNetWorth() {
|
public int getNetWorth() {
|
||||||
@@ -24,4 +26,13 @@ public class GameEndLogic extends Player{
|
|||||||
return "Congratulations!";
|
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};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/logic/LoanSharkLogic.java
Normal file
24
src/logic/LoanSharkLogic.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ public class RandomEventLogic extends Player{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
*
|
|
||||||
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
*/
|
*/
|
||||||
public RandomEventLogic(Player player) {
|
public RandomEventLogic(Player player) {
|
||||||
@@ -16,7 +15,7 @@ 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() {
|
public int[] randEvent() {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
@@ -39,6 +38,7 @@ public class RandomEventLogic extends Player{
|
|||||||
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//Forces random event to be gun related if nothing else is avaliable
|
||||||
else {
|
else {
|
||||||
randGenNum = 2;
|
randGenNum = 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public class ShipWarfareLogic extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
*
|
|
||||||
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ public class StartLogic extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
*
|
|
||||||
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
*/
|
*/
|
||||||
public StartLogic(Player player) {
|
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.
|
* method that sets the player's money and debt to 400 and 5000 respectively.
|
||||||
* also sets the player's guns to 0.
|
* also sets the player's guns to 0.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public void money_and_debt() {
|
public void money_and_debt() {
|
||||||
setMoney(400);
|
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.
|
* method that sets the player's guns to 5.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public void guns() {
|
public void guns() {
|
||||||
setGuns(5);
|
setGuns(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used in the Start Class
|
||||||
* for testing purposes
|
* for testing purposes
|
||||||
* sets the player's money, bank, guns, hp, ad cargo space to max values.
|
* sets the player's money, bank, guns, hp, ad cargo space to max values.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public void cheat() {
|
public void cheat() {
|
||||||
setMoney(999999999);
|
setMoney(999999999);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ public class TaipanShopLogic extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
*
|
|
||||||
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
*/
|
*/
|
||||||
public TaipanShopLogic(Player player) {
|
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() {
|
public String updatePrices() {
|
||||||
String s = "\t" + getName() + ", the price of ";
|
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.
|
* returns the user's condition based upon their current HP.
|
||||||
*
|
|
||||||
* @return shipStatus -- a representation of their ship's health in words.
|
* @return shipStatus -- a representation of their ship's health in words.
|
||||||
*/
|
*/
|
||||||
public String shipStatusString(){
|
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.
|
* 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.
|
* @return location -- the user's location as a string; the actual name of the location.
|
||||||
*/
|
*/
|
||||||
public String getStringLocation(){
|
public String getStringLocation(){
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class TravelLogic extends Player {
|
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) {
|
public TravelLogic(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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
|
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
||||||
* by a typhoon.
|
* by a typhoon.
|
||||||
|
* @return returns the string which is to be said to the player
|
||||||
**/
|
**/
|
||||||
public String disaster(int locationOfTravel) {
|
public String disaster(int locationOfTravel) {
|
||||||
//Tells player that there is a storm approaching.
|
//Tells player that there is a storm approaching.
|
||||||
|
|||||||
@@ -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
|
* 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) {
|
public String deposit(String str, int goodsNum) {
|
||||||
try {
|
try {
|
||||||
@@ -60,7 +60,7 @@ public class WarehouseLogic extends Player {
|
|||||||
/**
|
/**
|
||||||
* Method that transfers cargo from your warehouse onto your ship.
|
* Method that transfers cargo from your warehouse onto your ship.
|
||||||
* Has error handling to prevent incorrect inputs
|
* 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) {
|
public String withdraw(String str, int goodsNum) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
|
import logic.BankLogic;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class BankText extends Player {
|
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) {
|
public BankText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
@@ -28,36 +33,26 @@ public class BankText extends Player {
|
|||||||
String response = input.nextLine();
|
String response = input.nextLine();
|
||||||
//If user chose withdraw then subtract the amount from bank account and add it to cash
|
//If user chose withdraw then subtract the amount from bank account and add it to cash
|
||||||
if(response.equalsIgnoreCase("W")){
|
if(response.equalsIgnoreCase("W")){
|
||||||
boolean notDone2 = true;
|
check = withdraw(input, check);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//If the user chooses to deposit the continue to this code
|
//If the user chooses to deposit the continue to this code
|
||||||
else if(response.equalsIgnoreCase("D")){
|
else if(response.equalsIgnoreCase("D")){
|
||||||
boolean notDone2 = true;
|
check = deposit(input, check);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(check == 1){
|
if(check == 1){
|
||||||
|
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;
|
boolean notDone3 = true;
|
||||||
// Asks user if they would like to continue in bank or not
|
// Asks user if they would like to continue in bank or not
|
||||||
while(notDone3){
|
while(notDone3){
|
||||||
@@ -71,9 +66,53 @@ public class BankText extends Player {
|
|||||||
notDone3 = 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,36 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
|
import logic.GameEndLogic;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
public class GameEndText extends 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) {
|
public GameEndText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,85 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
|
import logic.LoanSharkLogic;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class LoanSharkText extends Player {
|
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) {
|
public LoanSharkText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Either give the player a loan or it allows the player to pay a debt
|
||||||
|
*/
|
||||||
public void loanMoney() {
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,21 @@ import logic.RandomEventLogic;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class RandomEventText extends Player {
|
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) {
|
public RandomEventText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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(){
|
public void randomEvent(){
|
||||||
/*Pick a random number dictating the events that could happen.
|
/*Pick a random number dictating the events that could happen.
|
||||||
* 1: New gun for player
|
* 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);
|
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)){
|
if((eventNumber == 1 && getCargoSpace() < 10)){
|
||||||
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
taipanShopText.shop();
|
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)){
|
if((eventNumber == 3 && getPlayer().getHP() >= 100)){
|
||||||
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
taipanShopText.shop();
|
taipanShopText.shop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Runs for as long as the player doesn't decide if they want to pay
|
||||||
while(true){
|
while(true){
|
||||||
System.out.println("Would you like to pay? (Y)es or (N)o");
|
System.out.println("Would you like to pay? (Y)es or (N)o");
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
@@ -80,6 +92,7 @@ public class RandomEventText extends Player {
|
|||||||
else {
|
else {
|
||||||
System.out.println("Sorry you don't have enough money");
|
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")){
|
if(input.equalsIgnoreCase("N")){
|
||||||
System.out.println("Aye aye Taipan, we'll send them off!\n");
|
System.out.println("Aye aye Taipan, we'll send them off!\n");
|
||||||
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
|||||||
@@ -158,9 +158,11 @@ public class ShipWarfareText extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
GameEndText gameEndText = new GameEndText(getPlayer());
|
||||||
|
gameEndText.gameEnd();
|
||||||
|
setPlayer(gameEndText.getPlayer());
|
||||||
exitValue = 2;
|
exitValue = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitValue;
|
return exitValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class StartText extends Player {
|
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) {
|
public StartText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
@@ -20,9 +25,11 @@ public class StartText extends Player {
|
|||||||
public void start() {
|
public void start() {
|
||||||
Scanner userInput = new Scanner(System.in);
|
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?");
|
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) {
|
while (true) {
|
||||||
int input = userInput.nextInt();
|
int input = userInput.nextInt();
|
||||||
|
//Will attempt to load the save if it's not empty
|
||||||
if(input == 1){
|
if(input == 1){
|
||||||
FileSaving saving = new FileSaving();
|
FileSaving saving = new FileSaving();
|
||||||
if(saving.loadFile() != null){
|
if(saving.loadFile() != null){
|
||||||
@@ -34,6 +41,7 @@ public class StartText extends Player {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//Just makes a new save
|
||||||
else if(input == 2){
|
else if(input == 2){
|
||||||
break;
|
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:");
|
System.out.println("Taipan, \nWhat will you name your firm:");
|
||||||
setName(userInput.nextLine());
|
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 ");
|
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) {
|
while (true) {
|
||||||
int input = userInput.nextInt();
|
int input = userInput.nextInt();
|
||||||
StartLogic startLogic = new StartLogic(getPlayer());
|
StartLogic startLogic = new StartLogic(getPlayer());
|
||||||
|
//If the player wants the money and debt starting
|
||||||
if (input == 1) {
|
if (input == 1) {
|
||||||
startLogic.money_and_debt();
|
startLogic.money_and_debt();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//If the player wants the gun start
|
||||||
else if (input == 2) {
|
else if (input == 2) {
|
||||||
startLogic.guns();
|
startLogic.guns();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -13,14 +13,6 @@ import logic.TaipanShopLogic;
|
|||||||
* Author: Vikram Bawa
|
* Author: Vikram Bawa
|
||||||
*/
|
*/
|
||||||
public class TaipanShopText extends Player {
|
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.
|
* 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);
|
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.
|
* 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) {
|
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.
|
// as long as the user does not enter a valid input, the code will run in a loop forever.
|
||||||
while(notDone){
|
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) {
|
public void buying(Scanner input, boolean notDone2) {
|
||||||
String response;
|
String response;
|
||||||
while (notDone2) {
|
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) {
|
public void selling(Scanner input, boolean notDone2) {
|
||||||
String response;
|
String response;
|
||||||
while (notDone2) {
|
while (notDone2) {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
import gui.RandomEventGUI;
|
|
||||||
import gui.TaipanShopGUI;
|
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
import logic.TravelLogic;
|
import logic.TravelLogic;
|
||||||
|
|
||||||
@@ -10,6 +8,11 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class TravelText extends Player {
|
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) {
|
public TravelText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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) {
|
public void traveling(Scanner keyboard, boolean hasTraveled) {
|
||||||
String response;
|
String response;
|
||||||
int tempInt;
|
int tempInt;
|
||||||
while (true) {
|
while (true) {
|
||||||
System.out.println("\n" + getName() + ", do you wish to go to:\n");
|
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();
|
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
|
//Just in case the player types something that was not intended. It will refresh the question and ask it again
|
||||||
try {
|
try {
|
||||||
tempInt = Integer.parseInt(response);
|
tempInt = Integer.parseInt(response);
|
||||||
@@ -69,6 +83,7 @@ public class TravelText extends Player {
|
|||||||
if (tempInt != getLocation()) {
|
if (tempInt != getLocation()) {
|
||||||
randomEventSea(tempInt);
|
randomEventSea(tempInt);
|
||||||
|
|
||||||
|
//Checks the seaAtlas to see if the player can go to their location
|
||||||
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
||||||
travelLogic.seaAtlas(tempInt);
|
travelLogic.seaAtlas(tempInt);
|
||||||
setPlayer(travelLogic.getPlayer());
|
setPlayer(travelLogic.getPlayer());
|
||||||
@@ -82,14 +97,17 @@ public class TravelText extends Player {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.print("\nSorry, " + getName() + " could you say that again?");
|
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) {
|
if (hasTraveled) {
|
||||||
|
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
//Chance of going to shop
|
||||||
if(randGenNum >= 2) {
|
if(randGenNum >= 2) {
|
||||||
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
taipanShopText.shop();
|
taipanShopText.shop();
|
||||||
}
|
}
|
||||||
|
//Chance of reaching a random event
|
||||||
else {
|
else {
|
||||||
RandomEventText randomEventText = new RandomEventText(getPlayer());
|
RandomEventText randomEventText = new RandomEventText(getPlayer());
|
||||||
randomEventText.randomEvent();
|
randomEventText.randomEvent();
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class WarehouseText extends Player {
|
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) {
|
public WarehouseText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
|
|||||||
Reference in New Issue
Block a user