- 1.8.0_201
+ 1.8
diff --git a/src/BankGUI.java b/src/BankGUI.java
index d3ff206..8ef58f1 100644
--- a/src/BankGUI.java
+++ b/src/BankGUI.java
@@ -10,37 +10,16 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
-public class BankGUI {
- private Player player;
-
- /**
- * setter method that takes in a Player object as an argument.
- *
- * @param player object of the class Player
- */
- public void setPlayer(Player player) {
- Player playerDummy = new Player(player);
- this.player = playerDummy;
- }
-
- /**
- * getter method for obtaining a player object.
- *
- * @return returns player object
- */
- public Player getPlayer() {
- Player playerDummy = new Player(player);
- return playerDummy;
- }
+public class BankGUI extends Player{
/**
* 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) {
Player playerDummy = new Player(player);
- this.player = playerDummy;
+ setPlayer(playerDummy);
}
/**
@@ -61,10 +40,10 @@ public class BankGUI {
HBox hbx2 = new HBox(30);
VBox vbx1 = new VBox(30);
- Label l1 = new Label("Player: " + player.getName());
- Label l2 = new Label("Current Balance: " + player.getBank());
+ Label l1 = new Label("Player: " + getName());
+ Label l2 = new Label("Current Balance: " + getBank());
Label l3 = new Label("Enter Amount: ");
- Label l4 = new Label("Current cash: " + player.getMoney());
+ Label l4 = new Label("Current cash: " + getMoney());
Label l5 = new Label(" ");
Button b1 = new Button("Withdraw");
@@ -114,17 +93,17 @@ public class BankGUI {
try {
int withdraw = Integer.parseInt(txtField1.getText());
if(withdraw < 0){
- l5.setText("Come on " + player.getName() + " are you trying to fool me??? \n No negative Numbers Please");
+ l5.setText("Come on " + getName() + " are you trying to fool me??? \n No negative Numbers Please");
}
- else if (withdraw <= player.getBank()) {
- player.setMoney(withdraw + player.getMoney());
- player.setBank(player.getBank() - withdraw);
+ else if (withdraw <= getBank()) {
+ setMoney(withdraw + getMoney());
+ setBank(getBank() - withdraw);
}
else {
l5.setText("Sorry you cannot withdraw that much");
}
- l2.setText("Current Balance: " + player.getBank());
- l4.setText("Current cash: " + player.getMoney());
+ l2.setText("Current Balance: " + getBank());
+ l4.setText("Current cash: " + getMoney());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
@@ -146,14 +125,14 @@ public class BankGUI {
if(deposit < 0){
l5.setText("Nice Try!!! No negative Numbers Please");
}
- else if (deposit <= player.getMoney()) {
- player.setBank(deposit + player.getBank());
- player.setMoney(player.getMoney() - deposit);
+ else if (deposit <= getMoney()) {
+ setBank(deposit + getBank());
+ setMoney(getMoney() - deposit);
} else {
l5.setText("Sorry you cannot deposit that much.$");
}
- l2.setText("Current Balance: " + player.getBank());
- l4.setText("Current cash: " + player.getMoney());
+ l2.setText("Current Balance: " + getBank());
+ l4.setText("Current cash: " + getMoney());
}
catch (Exception e) {
@@ -170,7 +149,7 @@ public class BankGUI {
b3.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- TaipanShopGUI shopGUI = new TaipanShopGUI(player);
+ TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
@@ -193,7 +172,7 @@ public class BankGUI {
* @param primaryStage the stage in which the scene may be run and switched to
*/
public void start(Stage primaryStage) {
- BankGUI bank = new BankGUI(player);
+ BankGUI bank = new BankGUI(getPlayer());
bank.initializeBank(primaryStage);
primaryStage.show();
}
diff --git a/src/GameEndGUI.java b/src/GameEndGUI.java
index 8940de9..ea2703a 100644
--- a/src/GameEndGUI.java
+++ b/src/GameEndGUI.java
@@ -12,7 +12,7 @@ import javafx.stage.Stage;
* GameEndGUI class, Initializes and displays the graphical interface for when you lose
*
*/
-public class GameEndGUI {
+public class GameEndGUI extends Player{
private Label title;
private VBox vBox;
@@ -20,11 +20,10 @@ public class GameEndGUI {
private Label gunsHeld;
private Label netWorth;
private BorderPane borderPane;
- private Player player;
public GameEndGUI(Player player) {
Player playerDummy = new Player(player);
- this.player = playerDummy;
+ setPlayer(playerDummy);
}
/**
@@ -79,7 +78,7 @@ public class GameEndGUI {
/**
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
* */
- if (player.getHP() <= 0) {
+ if (getHP() <= 0) {
title.setText("Game Over!");
} else {
title.setText("Congratulations!");
@@ -88,14 +87,14 @@ public class GameEndGUI {
/**
* Calculates the networth of the player by the end of the game
* */
- netWorthInt = player.getMoney() + (player.getOpiumHeld() * 16000) + (player.getSilkHeld() * 160) + (player.getArmsHeld() * 160) + (player.getGeneralHeld() * 8);
- netWorthInt += (player.getwOpium() * 16000) + (player.getwSilk() * 160) + (player.getwArms() * 160) + (player.getwGeneral() * 8);
- netWorthInt -= player.getDebt();
+ netWorthInt = getMoney() + (getOpiumHeld() * 16000) + (getSilkHeld() * 160) + (getArmsHeld() * 160) + (getGeneralHeld() * 8);
+ netWorthInt += (getwOpium() * 16000) + (getwSilk() * 160) + (getwArms() * 160) + (getwGeneral() * 8);
+ netWorthInt -= getDebt();
//Updating the endgame stats of the player
- firmName.setText("Firm Name: " + player.getName());
- gunsHeld.setText("Guns Held: " + player.getGuns());
+ firmName.setText("Firm Name: " + getName());
+ gunsHeld.setText("Guns Held: " + getGuns());
netWorth.setText("Net Worth: " + netWorthInt);
Scene root = new Scene(borderPane, 600, 480);
@@ -113,7 +112,7 @@ public class GameEndGUI {
* @param primaryStage the stage in which the scene may be run and switched to
*/
public void start(Stage primaryStage) {
- GameEndGUI gameEndGUI = new GameEndGUI(player);
+ GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(primaryStage);
primaryStage.show();
}
diff --git a/src/LoanSharkGUI.java b/src/LoanSharkGUI.java
index 9647518..cbadb9e 100644
--- a/src/LoanSharkGUI.java
+++ b/src/LoanSharkGUI.java
@@ -10,39 +10,28 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
-public class LoanSharkGUI {
- private Player player;
-
- /**
- * setter method that takes in a Player object as an argument.
- *
- * @param player object of the class Player
- */
- public void setPlayer(Player player) {
- Player playerDummy = new Player(player);
- this.player = playerDummy;
- }
-
- /**
- * getter method for obtaining a player object.
- *
- * @return returns player object
- */
- public Player getPlayer() {
- Player playerDummy = new Player(player);
- return playerDummy;
- }
+public class LoanSharkGUI extends Player {
/**
* 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 LoanSharkGUI(Player player) {
Player playerDummy = new Player(player);
- this.player = playerDummy;
+ setPlayer(playerDummy);
}
+ /**
+ * This methods purpose is to loan the player the funds it wants
+ * or pay its outstanding debts. The method prompts the user if they
+ * would like to borrow money or repay. depending on what the player chooses
+ * the corresponding loop is evoked. The player can only be loaned 2 times the
+ * money they have minus the debt if their debt exceeds the cash balance, the loan
+ * cannot be given.
+ *
+ * @param primaryStage the stage upon which the GUI will be imposed
+ */
public Stage initializeLoanShark(Stage primaryStage) {
primaryStage.setTitle("Loan Shark");
@@ -53,9 +42,9 @@ public class LoanSharkGUI {
VBox vbx1 = new VBox(10);
//Declaring all Variables
- Label l1 = new Label("Player: " + player.getName());
- Label l2 = new Label("Current Debt " + player.getDebt());
- Label l4 = new Label("Current cash: " + player.getMoney());
+ Label l1 = new Label("Player: " + getName());
+ Label l2 = new Label("Current Debt " + getDebt());
+ Label l4 = new Label("Current cash: " + getMoney());
Label l3 = new Label("Enter Amount: ");
Label l5 = new Label(" ");
@@ -96,10 +85,10 @@ public class LoanSharkGUI {
try {
int loanAsk = Integer.parseInt(txtField1.getText());
- if (loanAsk <= 2 * (player.getMoney() - player.getDebt()) && loanAsk >= 0) {
- player.setDebt(player.getDebt() + loanAsk);
- player.setMoney(player.getMoney() + loanAsk);
- l4.setText("Current cash: " + player.getMoney());
+ if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) {
+ setDebt(getDebt() + loanAsk);
+ setMoney(getMoney() + loanAsk);
+ l4.setText("Current cash: " + getMoney());
} else if (loanAsk < 0) {
l5.setText("Sorry you cannot enter negative numbers");
}
@@ -108,7 +97,7 @@ public class LoanSharkGUI {
}
- l2.setText("Debt: " + player.getDebt());
+ l2.setText("Debt: " + getDebt());
} catch (Exception e) {
l5.setText("Please enter a valid value");
}
@@ -121,26 +110,26 @@ public class LoanSharkGUI {
// Set the event handler when the withdraw button is clicked
b2.setOnAction(new EventHandler() {
@Override
- public void handle(ActionEvent event) {
+ public void handle(ActionEvent event) {
try {
int returnAsk = Integer.parseInt(txtField1.getText());
- if (returnAsk > player.getDebt()) {
+ if (returnAsk > getDebt()) {
l5.setText("You dont need to return that much");
}
- else if (returnAsk <= player.getDebt() && returnAsk >= 0 && player.getMoney() >= returnAsk) {
- player.setDebt(player.getDebt() - returnAsk);
- player.setMoney(player.getMoney() - returnAsk);
- l4.setText("Current cash: " + player.getMoney());
+ else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) {
+ setDebt(getDebt() - returnAsk);
+ setMoney(getMoney() - returnAsk);
+ l4.setText("Current cash: " + getMoney());
}
- else if(player.getMoney() < returnAsk) {
- l5.setText("Look " + player.getName() + ", you are being cheap!");
+ else if(getMoney() < returnAsk) {
+ l5.setText("Look " + getName() + ", you are being cheap!");
}
else {
l5.setText("Sorry you cannot return a negative amount");
}
- l2.setText("Debt: " + player.getDebt());
+ l2.setText("Debt: " + getDebt());
}
catch (Exception e) {
l5.setText("Please enter a valid value");
@@ -152,7 +141,7 @@ public class LoanSharkGUI {
b3.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
- TaipanShopGUI shopGUI = new TaipanShopGUI(player);
+ TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
@@ -169,20 +158,10 @@ public class LoanSharkGUI {
public void start(Stage primaryStage) {
- LoanSharkGUI loan = new LoanSharkGUI(player);
+ LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
loan.initializeLoanShark(primaryStage);
primaryStage.show();
}
-
-
- /**
- * This methods purpose is to loan the player the funds it wants
- * or pay its outstanding debts. The method prompts the user if they
- * would like to borrow money or repay. depending on what the player chooses
- * the corresponding loop is evoked. The player can only be loaned 2 times the
- * money they have minus the debt id their debt exceeds the cash balance, the loan
- * cannot be given.
- */
}
diff --git a/src/MainGUI.java b/src/MainGUI.java
index 2e1889c..277f0e1 100644
--- a/src/MainGUI.java
+++ b/src/MainGUI.java
@@ -9,30 +9,6 @@ import javafx.stage.Stage;
*/
public class MainGUI extends Application {
- private Player player = new Player();
-
- /**
- * getter method for the Player object player.
- *
- * @return returns a copy of the object player
- */
-
- public Player getPlayer() {
- Player copy = new Player(player);
- return copy;
- }
-
- /**
- * Initializes the Taipan shop with the players stats after the player finishes shopping, it updates the player object and returns it.
- *
- * @param shop player object from the main class used to update the shop class
- */
-
- public void shop(TaipanShopGUI shop) {
- shop.setPlayer(player);
- shop.shop();
- player = shop.getPlayer();
- }
/**
* Updates main class with player data and starts the game.
@@ -45,7 +21,7 @@ public class MainGUI extends Application {
}
public void start(Stage primaryStage) throws Exception {
- StartGUI start = new StartGUI(player);
+ StartGUI start = new StartGUI(new Player());
start.initializeStart(primaryStage);
primaryStage.show();
}
diff --git a/src/Player.java b/src/Player.java
index d511a8b..f6e771d 100644
--- a/src/Player.java
+++ b/src/Player.java
@@ -5,8 +5,6 @@
*
*/
-import java.util.Random;
-
public class Player {
private String name = "Taipan";
@@ -33,28 +31,7 @@ public class Player {
private int isPriceChanged = 0;
public Player() {
- this.name = "Taipan";
- this.bank = 0;
- this.money = 0;
- this.opiumHeld = 0;
- this.silkHeld = 0;
- this.generalHeld = 0;
- this.armsHeld = 0;
- this.location = 1;
- this.guns = 0;
- this.HP = 100;
- this.debt = 0;
- this.wOpium = 0;
- this.wSilk = 0;
- this.wGeneral = 0;
- this.wArms = 0;
- this.retire = false;
- this.opiumPrice = 1600;
- this.silkPrice = 1600;
- this.armsPrice = 160;
- this.generalPrice = 8;
- this.cargoSpace = 60;
- this.isPriceChanged = 0;
+
}
/**
@@ -63,6 +40,14 @@ public class Player {
* @param player object of the class Player
*/
public Player(Player player) {
+ setPlayer(player);
+ }
+
+ public Player getPlayer(){
+ return new Player(this);
+ }
+
+ public void setPlayer(Player player){
this.name = player.name;
this.bank = player.bank;
this.money = player.money;
@@ -84,6 +69,7 @@ public class Player {
this.generalPrice = player.generalPrice;
this.cargoSpace = player.cargoSpace;
this.isPriceChanged = player.isPriceChanged;
+ this.retire = player.retire;
}
/**
diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java
index 7cad043..c941b3a 100644
--- a/src/ShipWarfareGUI.java
+++ b/src/ShipWarfareGUI.java
@@ -19,10 +19,8 @@ import javafx.stage.Stage;
import java.util.Random;
-public class ShipWarfareGUI {
+public class ShipWarfareGUI extends Player{
-
- private Player player = new Player();
private HBox hBox;
private Button fightButton;
private Button runButton;
@@ -39,17 +37,6 @@ public class ShipWarfareGUI {
private Button continueButton;
- /**
- * 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 ShipWarfareGUI(Player player) {
- Player playerDummy = new Player(player);
- this.player = playerDummy;
- }
-
-
private int numOfPeasantShips = 0;
private int numOfLittyShips = 0;
private boolean userAttacks = true;
@@ -59,24 +46,15 @@ public class ShipWarfareGUI {
private int counter = 0;
private String pirateName = "Liu Yen";
- /**
- * setter method for player
- *
- * @param player object of the class Player
- */
- public void setPlayer(Player player) {
- Player playerDummy = new Player(player);
- this.player = playerDummy;
- }
/**
- * getter method for obtaining a player object.
+ * constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
- * @return returns player object
+ * @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
- public Player getPlayer() {
+ public ShipWarfareGUI(Player player) {
Player playerDummy = new Player(player);
- return playerDummy;
+ setPlayer(playerDummy);
}
/**
@@ -103,16 +81,16 @@ public class ShipWarfareGUI {
int numOfShipsAttacking = 0;
Random randomValue = new Random();
- if (player.getMoney() <= 100000) {
+ if (getMoney() <= 100000) {
//Minimum one ship will attack, maximum 20
numOfShipsAttacking = randomValue.nextInt(20) + 1;
- } else if (player.getMoney() <= 200000) {
+ } else if (getMoney() <= 200000) {
//Minimum 30 Ships will attack, maximum 70
numOfShipsAttacking = randomValue.nextInt(40) + 31;
- } else if (player.getMoney() <= 500000) {
+ } else if (getMoney() <= 500000) {
//Minimum 50 ships will attack, maximum 140
numOfShipsAttacking = randomValue.nextInt(90) + 51;
- } else if (player.getMoney() >= 1000000) {
+ } else if (getMoney() >= 1000000) {
//Minimum 100 ships will attack, maximum 300 ships
numOfShipsAttacking = randomValue.nextInt(200) + 101;
}
@@ -196,9 +174,9 @@ public class ShipWarfareGUI {
//Player volley
//while (exitValue == 0) {
- if (player.getGuns() > 0) {
+ if (getGuns() > 0) {
- for (int j = 0; j < player.getGuns(); j++) {
+ for (int j = 0; j < getGuns(); j++) {
if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(2) + 1;
if (hitOrMiss == 2) {
@@ -230,7 +208,7 @@ public class ShipWarfareGUI {
exitValue = 1;
//break;
}
- if (player.getGuns() > 0) {
+ if (getGuns() > 0) {
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) {
howMuchRun = randomValue.nextInt(15) + 1;
@@ -240,12 +218,12 @@ public class ShipWarfareGUI {
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
if (userAttacks == true) {
if (howMuchRun > 0) {
- runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, player.getName()));
+ runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, getName()));
//runAwayOrLeft.setVisible(true);
}
} else {
- report.setText((String.format("Escaped %d of them %s!", howMuchRun, player.getName())));
+ report.setText((String.format("Escaped %d of them %s!", howMuchRun, getName())));
}
}
@@ -255,47 +233,47 @@ public class ShipWarfareGUI {
shipsRemaining.setText(String.format("%d ships remaining and they look angry!", numOfPeasantShips));
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
- if (takeGunChance == 1 && player.getGuns() > 0) {
- player.setGuns(player.getGuns() - 1);
+ if (takeGunChance == 1 && getGuns() > 0) {
+ setGuns(getGuns() - 1);
gunFrustration = true;
} else {
if (numOfPeasantShips > 0) {
- player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
+ setHP(getHP() - (1 + randomValue.nextInt(10)));
}
}
- if (player.getHP() <= 0) {
+ if (getHP() <= 0) {
exitValue = 2;
//break;
}
if (gunFrustration == true) {
- gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
+ gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", getGuns()));
} else {
- gunsLeftOrTaken.setText(String.format("We still have %d guns left", player.getGuns()));
+ gunsLeftOrTaken.setText(String.format("We still have %d guns left", getGuns()));
}
- HPLeft.setText(String.format("EEK, our current ship status is %d%% ", player.getHP()));
+ HPLeft.setText(String.format("EEK, our current ship status is %d%% ", getHP()));
if (userAttacks == false) {
userAttacks = true;
}
- continueToFight.setText(String.format("Captain, what are your orders? (Click the fight button or the run button)", player.getGuns()));
+ continueToFight.setText(String.format("Captain, what are your orders? (Click the fight button or the run button)", getGuns()));
if (exitValue == 1) {
wipe();
- chooseFightOrRun.setText(String.format("Ayy! We won and survived at %d%% ship status!", player.getHP()));
+ chooseFightOrRun.setText(String.format("Ayy! We won and survived at %d%% ship status!", getHP()));
calculateLoot = (startingPeasantShips * 100) + randomValue.nextInt(startingPeasantShips) * 200;
- player.setMoney(player.getMoney() + calculateLoot);
+ setMoney(getMoney() + calculateLoot);
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
continueButton.setVisible(true);
return true;
} else if (exitValue == 2) {
- GameEndGUI gameEndGUI = new GameEndGUI(player);
+ GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(stage);
stage.show();
return true;
} else if (exitValue == 3) {
- System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
+ System.out.printf("We made it out at %d%% ship status!\n", getHP());
continueButton.setVisible(true);
return true;
}
@@ -414,7 +392,7 @@ public class ShipWarfareGUI {
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
- TaipanShopGUI shop = new TaipanShopGUI(player);
+ TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
@@ -460,7 +438,7 @@ public class ShipWarfareGUI {
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
- TaipanShopGUI shop = new TaipanShopGUI(player);
+ TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
@@ -472,7 +450,7 @@ public class ShipWarfareGUI {
} else {
completeWipe();
report.setText("Phew! Got away safely");
- TaipanShopGUI shop = new TaipanShopGUI(player);
+ TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
diff --git a/src/StartGUI.java b/src/StartGUI.java
index 0c83580..256c339 100644
--- a/src/StartGUI.java
+++ b/src/StartGUI.java
@@ -9,16 +9,15 @@ import javafx.scene.text.Font;
import javafx.stage.Stage;
/**
-* 2019-03-10
-* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
-* StartGUI class, Initializes and displays the start menu for Taipan
-*
-*/
+ * 2019-03-10
+ * Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
+ * StartGUI class, Initializes and displays the start menu for Taipan
+ *
+ */
-public class StartGUI {
+public class StartGUI extends Player{
- private Player player;
private BorderPane borderPane = new BorderPane();
private HBox hBox = new HBox();
private TextField nameField = new TextField();
@@ -33,23 +32,12 @@ public class StartGUI {
private Label authors = new Label();
/**
- * gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
- *
- * @return playerDummy -- playerDummy is a copy of the player instance variable.
+ * Copy constructor.
+ * @param player object of the class Player
*/
- public Player getPlayer() {
+ public StartGUI(Player player) {
Player playerTemp = new Player(player);
- return playerTemp;
- }
-
- /**
- * sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
- *
- * @param player is a Player object that will replace the current instance of the player instance variable.
- */
- public void setPlayer(Player player) {
- Player playerTemp = new Player(player);
- this.player = playerTemp;
+ setPlayer(playerTemp);
}
/**
@@ -59,22 +47,12 @@ public class StartGUI {
*/
public void setFirm(String name) {
if (name.length() <= 22) {
- player.setName(name);
+ super.setName(name);
} else {
- player.setName("Taipan");
+ super.setName("Taipan");
}
}
- /*
- **
- * Copy constructor.
- * @param player object of the class Player
- */
- public StartGUI(Player player) {
- Player playerTemp = new Player(player);
- this.player = playerTemp;
- }
-
/**
* Initializes the Start GUI the game.
*
@@ -199,26 +177,26 @@ public class StartGUI {
@Override
public void handle(ActionEvent event) {
if (Start.getSelectedToggle() == cashChoice) {
- player.setMoney(400);
- player.setDebt(5000);
+ setMoney(400);
+ setDebt(5000);
}
if (Start.getSelectedToggle() == gunChoice) {
- player.setGuns(5);
+ setGuns(5);
}
String response = nameField.getText();
// purely for testing purposes.
if (response.equalsIgnoreCase("Vikram")) {
- player.setMoney(999999999);
- player.setBank(999999999);
- player.setGuns(999);
- player.setHP(99999999);
- player.setCargoSpace(Integer.MAX_VALUE);
+ setMoney(999999999);
+ setBank(999999999);
+ setGuns(999);
+ setHP(99999999);
+ setCargoSpace(Integer.MAX_VALUE);
}
setFirm(response);
- TaipanShopGUI shop = new TaipanShopGUI(player);
+ TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
//title.setText("SHOP PLACEHOLDER");
diff --git a/src/TaipanShopGUI.java b/src/TaipanShopGUI.java
index f5a8562..aaa86e2 100644
--- a/src/TaipanShopGUI.java
+++ b/src/TaipanShopGUI.java
@@ -20,8 +20,7 @@ import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.util.Random;
-public class TaipanShopGUI {
- private Player player;
+public class TaipanShopGUI extends Player{
private Label firm = new Label();
private Label wItemsText = new Label();
private Label wItemSpaceText = new Label();
@@ -53,86 +52,64 @@ public class TaipanShopGUI {
*/
public TaipanShopGUI(Player player) {
Player playerDummy = new Player(player);
- this.player = 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(Stage stage) {
- player.setRetire(true);
- GameEndGUI gameEndGUI = new GameEndGUI(player);
+ setRetire(true);
+ GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
gameEndGUI.initializeGameEndGUI(stage);
stage.show();
}
- /**
- * sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
- *
- * @param player is a Player object that will replace the current instance of the player instance variable.
- */
- public void setPlayer(Player player) {
- Player playerDummy = new Player(player);
- this.player = playerDummy;
- }
-
- /**
- * gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
- *
- * @return playerDummy -- playerDummy is a copy of the player instance variable.
- */
- public Player getPlayer() {
- Player playerDummy = new Player(player);
- return playerDummy;
- }
-
-
-
/**
* this method is when the shop is accessed, randomizing the prices of all the items.
*/
public void updatePrices() {
- String s = "\t" + player.getName() + ", the price of ";
+ String s = "\t" + getName() + ", the price of ";
double value = 80 * Math.random();
Random rand = new Random();
- player.setOpiumPrice((rand.nextInt(201) + 60) * 100);
- player.setSilkPrice((rand.nextInt(201) + 60) * 10);
- player.setArmsPrice((rand.nextInt(21) + 6) * 10);
- player.setGeneralPrice((rand.nextInt(17) + 4));
+ setOpiumPrice((rand.nextInt(201) + 60) * 100);
+ setSilkPrice((rand.nextInt(201) + 60) * 10);
+ setArmsPrice((rand.nextInt(21) + 6) * 10);
+ setGeneralPrice((rand.nextInt(17) + 4));
// there is a 10% chance that the price of an item is increased/decreased beyond its regular range.
if (value < 8) {
if (value < 2) {
if (value < 1) {
- player.setOpiumPrice(player.getOpiumPrice() / 5);
- textOut.setText(s + "Opium has dropped to " + player.getOpiumPrice() + "!!!\n" + textOut.getText());
+ setOpiumPrice(getOpiumPrice() / 5);
+ textOut.setText(s + "Opium has dropped to " + getOpiumPrice() + "!!!\n" + textOut.getText());
} else {
- player.setOpiumPrice(player.getOpiumPrice() * 5);
- textOut.setText(s + "Opium has risen to " + player.getOpiumPrice() + "!!!\n" + textOut.getText());
+ setOpiumPrice(getOpiumPrice() * 5);
+ textOut.setText(s + "Opium has risen to " + getOpiumPrice() + "!!!\n" + textOut.getText());
}
} else if (value < 4) {
if (value < 3) {
- player.setSilkPrice(player.getSilkPrice() / 5);
- textOut.setText(s + "Silk has dropped to " + player.getSilkPrice() + "!!!\n" + textOut.getText());
+ setSilkPrice(getSilkPrice() / 5);
+ textOut.setText(s + "Silk has dropped to " + getSilkPrice() + "!!!\n" + textOut.getText());
} else {
- player.setSilkPrice(player.getSilkPrice() * 5);
- textOut.setText(s + "Silk has risen to " + player.getSilkPrice() + "!!!\n" + textOut.getText());
+ setSilkPrice(getSilkPrice() * 5);
+ textOut.setText(s + "Silk has risen to " + getSilkPrice() + "!!!\n" + textOut.getText());
}
} else if (value < 6) {
if (value < 3) {
- player.setArmsPrice(player.getArmsPrice() / 5);
- textOut.setText(s + "Arms has dropped to " + player.getArmsPrice() + "!!!\n" + textOut.getText());
+ setArmsPrice(getArmsPrice() / 5);
+ textOut.setText(s + "Arms has dropped to " + getArmsPrice() + "!!!\n" + textOut.getText());
} else {
- player.setArmsPrice(player.getArmsPrice() * 5);
- textOut.setText(s + "Arms has risen to " + player.getArmsPrice() + "!!!\n" + textOut.getText());
+ setArmsPrice(getArmsPrice() * 5);
+ textOut.setText(s + "Arms has risen to " + getArmsPrice() + "!!!\n" + textOut.getText());
}
} else {
if (value < 7) {
- player.setGeneralPrice(1);
+ setGeneralPrice(1);
textOut.setText(s + "General Cargo has dropped to 1!!!\n" + textOut.getText());
} else {
- player.setGeneralPrice(player.getGeneralPrice() * 5);
- textOut.setText(s + "General Cargo has risen to " + player.getGeneralPrice() + "!!!\n" + textOut.getText());
+ setGeneralPrice(getGeneralPrice() * 5);
+ textOut.setText(s + "General Cargo has risen to " + getGeneralPrice() + "!!!\n" + textOut.getText());
}
}
}
@@ -142,7 +119,7 @@ public class TaipanShopGUI {
* Sets the default dialogue of simply stating the prices of the items.
*/
public void defaultTextOut() {
- textOut.setText(String.format("\t%s, present prices per unit here are:\n\n\t\tOpium: %d\t\t\tSilk: %d\n\t\tArms: %d\t\t\tGeneral: %d", player.getName(), player.getOpiumPrice(), player.getSilkPrice(), player.getArmsPrice(), player.getGeneralPrice()));
+ textOut.setText(String.format("\t%s, present prices per unit here are:\n\n\t\tOpium: %d\t\t\tSilk: %d\n\t\tArms: %d\t\t\tGeneral: %d", getName(), getOpiumPrice(), getSilkPrice(), getArmsPrice(), getGeneralPrice()));
}
@@ -176,7 +153,7 @@ public class TaipanShopGUI {
silkButton.setText("Silk");
armsButton.setText("Arms");
generalButton.setText("General");
- if (player.getLocation() != 1) {
+ if (getLocation() != 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(false);
@@ -190,7 +167,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false);
retireButton.setVisible(false);
}
- if (player.getBank() + player.getMoney() - player.getDebt() < 1000000 && player.getLocation() == 1) {
+ if (getBank() + getMoney() - getDebt() < 1000000 && getLocation() == 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -203,7 +180,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false);
armsButton.setVisible(false);
retireButton.setVisible(false);
- } else if (player.getLocation() == 1) {
+ } else if (getLocation() == 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -240,64 +217,64 @@ public class TaipanShopGUI {
String originalDialogue = textOut.getText();
int num = Integer.parseInt(numberInput.getText().replace(" ", ""));
if (buyButton.getText().contains(".")) {
- if (opiumButton.getText().contains(".") && num <= player.getMoney() / player.getOpiumPrice() && num >= 0) {
- player.setMoney(player.getMoney() - num * player.getOpiumPrice());
- player.setOpiumHeld(player.getOpiumHeld() + num);
+ if (opiumButton.getText().contains(".") && num <= getMoney() / getOpiumPrice() && num >= 0) {
+ setMoney(getMoney() - num * getOpiumPrice());
+ setOpiumHeld(getOpiumHeld() + num);
} else if (num >= 0 && opiumButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (opiumButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
- } else if (silkButton.getText().contains(".") && num <= player.getMoney() / player.getOpiumPrice() && num >= 0) {
- player.setSilkHeld(player.getSilkHeld() + num);
- player.setMoney(player.getMoney() - num * player.getOpiumPrice());
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
+ } else if (silkButton.getText().contains(".") && num <= getMoney() / getOpiumPrice() && num >= 0) {
+ setSilkHeld(getSilkHeld() + num);
+ setMoney(getMoney() - num * getOpiumPrice());
} else if (num >= 0 && silkButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (silkButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
- } else if (armsButton.getText().contains(".") && num <= player.getMoney() / player.getArmsPrice() && num >= 0) {
- player.setArmsHeld(player.getArmsHeld() + num);
- player.setMoney(player.getMoney() - num * player.getArmsPrice());
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
+ } else if (armsButton.getText().contains(".") && num <= getMoney() / getArmsPrice() && num >= 0) {
+ setArmsHeld(getArmsHeld() + num);
+ setMoney(getMoney() - num * getArmsPrice());
} else if (num >= 0 && armsButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (armsButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
- } else if (generalButton.getText().contains(".") && num <= player.getMoney() / player.getGeneralPrice() && num >= 0) {
- player.setGeneralHeld(player.getGeneralHeld()+num);
- player.setMoney(player.getMoney() - num * player.getGeneralPrice());
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
+ } else if (generalButton.getText().contains(".") && num <= getMoney() / getGeneralPrice() && num >= 0) {
+ setGeneralHeld(getGeneralHeld()+num);
+ setMoney(getMoney() - num * getGeneralPrice());
} else if (num >= 0 && generalButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you can't afford that!");
} else if (generalButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
} else if (sellButton.getText().contains(".")) {
- if (opiumButton.getText().contains(".") && num <= player.getOpiumHeld() && num >= 0) {
- player.setOpiumHeld(player.getOpiumHeld() - num);
- player.setMoney(player.getMoney() + num * player.getOpiumPrice());
+ if (opiumButton.getText().contains(".") && num <= getOpiumHeld() && num >= 0) {
+ setOpiumHeld(getOpiumHeld() - num);
+ setMoney(getMoney() + num * getOpiumPrice());
} else if (num >= 0 && opiumButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (opiumButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
- } else if (silkButton.getText().contains(".") && num <= player.getSilkHeld() && num >= 0) {
- player.setSilkHeld(player.getSilkHeld() - num);
- player.setMoney(player.getMoney() + num * player.getOpiumPrice());
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
+ } else if (silkButton.getText().contains(".") && num <= getSilkHeld() && num >= 0) {
+ setSilkHeld(getSilkHeld() - num);
+ setMoney(getMoney() + num * getOpiumPrice());
} else if (num >= 0 && silkButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (silkButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
- } else if (armsButton.getText().contains(".") && num <= player.getArmsHeld() && num >= 0) {
- player.setArmsHeld(player.getArmsHeld() - num);
- player.setMoney(player.getMoney() + num * player.getArmsPrice());
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
+ } else if (armsButton.getText().contains(".") && num <= getArmsHeld() && num >= 0) {
+ setArmsHeld(getArmsHeld() - num);
+ setMoney(getMoney() + num * getArmsPrice());
} else if (num >= 0 && armsButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else if (armsButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
- } else if (generalButton.getText().contains(".") && num <= player.getGeneralHeld() && num >= 0) {
- player.setGeneralHeld(player.getGeneralHeld() - num);
- player.setMoney(player.getMoney() + num * player.getGeneralPrice());
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
+ } else if (generalButton.getText().contains(".") && num <= getGeneralHeld() && num >= 0) {
+ setGeneralHeld(getGeneralHeld() - num);
+ setMoney(getMoney() + num * getGeneralPrice());
} else if (num >= 0 && generalButton.getText().contains(".")) {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", you don't have that many to sell!");
} else {
- textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
+ textOut.setText(originalDialogue + "\n\t" + getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
@@ -470,7 +447,7 @@ public class TaipanShopGUI {
*/
@Override
public void handle(ActionEvent event) {
- WarehouseGUI warehouseGUI = new WarehouseGUI(player);
+ WarehouseGUI warehouseGUI = new WarehouseGUI(getPlayer());
warehouseGUI.initializeWarehouse(stage);
stage.show();
}
@@ -509,8 +486,8 @@ public class TaipanShopGUI {
*/
@Override
public void handle(ActionEvent event) {
- player.setIsPriceChanged(1);
- TravelGUI travelGUI = new TravelGUI(player);
+ setIsPriceChanged(1);
+ TravelGUI travelGUI = new TravelGUI(getPlayer());
travelGUI.initializeTravel(stage);
stage.show();
//System.out.println("PLACEHOLDER FOR TRAVEL");
@@ -554,9 +531,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
- extraText = String.format(" (You can afford %d)", player.getMoney() / player.getOpiumPrice());
+ extraText = String.format(" (You can afford %d)", getMoney() / getOpiumPrice());
} else {
- extraText = String.format(" (You have %d)", player.getOpiumHeld());
+ extraText = String.format(" (You have %d)", getOpiumHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Opium?" + extraText);
}
@@ -581,9 +558,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
- extraText = String.format(" (You can afford %d)", player.getMoney() / player.getSilkPrice());
+ extraText = String.format(" (You can afford %d)", getMoney() / getSilkPrice());
} else {
- extraText = String.format(" (You have %d)", player.getSilkHeld());
+ extraText = String.format(" (You have %d)", getSilkHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Silk?" + extraText);
}
@@ -606,9 +583,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
- extraText = String.format(" (You can afford %d)", player.getMoney() / player.getArmsPrice());
+ extraText = String.format(" (You can afford %d)", getMoney() / getArmsPrice());
} else {
- extraText = String.format(" (You have %d)", player.getArmsHeld());
+ extraText = String.format(" (You have %d)", getArmsHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of Arms?" + extraText);
}
@@ -635,9 +612,9 @@ public class TaipanShopGUI {
defaultTextOut();
String extraText;
if (buyButton.getText().contains(".")) {
- extraText = String.format(" (You can afford %d)", player.getMoney() / player.getGeneralPrice());
+ extraText = String.format(" (You can afford %d)", getMoney() / getGeneralPrice());
} else {
- extraText = String.format(" (You have %d)", player.getGeneralHeld());
+ extraText = String.format(" (You have %d)", getGeneralHeld());
}
textOut.setText(textOut.getText() + "\n\tWhat quantity of General Cargo?" + extraText);
}
@@ -769,7 +746,7 @@ public class TaipanShopGUI {
// general updates to the buttons, user stats/inventory, and text.
buttonSetup("reset");
- if(player.getIsPriceChanged() == 0 || player.getIsPriceChanged() == 2){
+ if(getIsPriceChanged() == 0 || getIsPriceChanged() == 2){
updatePrices();
}
defaultTextOut();
@@ -783,7 +760,7 @@ public class TaipanShopGUI {
*/
public String getStringLocation() {
String location;
- switch (player.getLocation()) {
+ switch (getLocation()) {
case 1:
location = "Hong Kong";
break;
@@ -819,7 +796,7 @@ public class TaipanShopGUI {
*/
public String shipStatusString() {
String shipStatus;
- switch (player.getHP() / 10) {
+ switch (getHP() / 10) {
case 10:
shipStatus = "Mint Condition";
break;
@@ -864,22 +841,22 @@ public class TaipanShopGUI {
* updates the text associated with the user's inventory.
*/
public void updateStage() {
- firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation()));
- wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));
- int itemsInWarehouse = player.getwOpium() + player.getwGeneral() + player.getwArms() + player.getwSilk();
+ firm.setText(String.format("Firm: %s, %s", getName(), getStringLocation()));
+ wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", getwOpium(), getwSilk(), getwArms(), getwGeneral()));
+ int itemsInWarehouse = getwOpium() + getwGeneral() + getwArms() + getwSilk();
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", getStringLocation()));
- int itemsInInventory = player.getCargoSpace() - player.getSilkHeld() - player.getOpiumHeld() - player.getGeneralHeld() - player.getArmsHeld() - 10 * player.getGuns();
+ int itemsInInventory = getCargoSpace() - getSilkHeld() - getOpiumHeld() - getGeneralHeld() - getArmsHeld() - 10 * getGuns();
if (itemsInInventory < 0) {
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
} 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 ", player.getGuns()));
- inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", player.getOpiumHeld(), player.getSilkHeld(), player.getArmsHeld(), player.getGeneralHeld()));
- shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", player.getDebt(), shipStatusString(), player.getHP()));
- cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
- bankText.setText(String.format("Bank: $%,d", player.getBank()));
+ gunsText.setText(String.format("Guns %d\n\n\n\n ", getGuns()));
+ inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", getOpiumHeld(), getSilkHeld(), getArmsHeld(), getGeneralHeld()));
+ shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", getDebt(), shipStatusString(), getHP()));
+ cashText.setText(String.format(" Cash: $%,d", getMoney()));
+ bankText.setText(String.format("Bank: $%,d", getBank()));
}
}
diff --git a/src/TravelGUI.java b/src/TravelGUI.java
index 8522ceb..463d891 100644
--- a/src/TravelGUI.java
+++ b/src/TravelGUI.java
@@ -1,8 +1,8 @@
/**
-* TravelGUI is the class in which takes the player from location to location
-*
-* Author: Harkamal Randhawa
-*/
+ * TravelGUI is the class in which takes the player from location to location
+ *
+ * Author: Harkamal Randhawa
+ */
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
@@ -16,8 +16,7 @@ import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import java.util.Random;
-public class TravelGUI{
- private Player player;
+public class TravelGUI extends Player{
private TaipanShopGUI shop;
private Label firm = new Label();
private Label wItemsText = new Label();
@@ -41,7 +40,6 @@ public class TravelGUI{
private Boolean stormScene = false;
private Boolean sceneContinue = false;
-
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
@@ -50,7 +48,7 @@ public class TravelGUI{
public TravelGUI(Player player) {
Player playerDummy = new Player(player);
this.shop = new TaipanShopGUI(player);
- this.player = playerDummy;
+ setPlayer(playerDummy);
}
/**
@@ -166,7 +164,7 @@ public class TravelGUI{
//Goes back to shop
quitButton.setOnAction(event -> {
- TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player);
+ TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
taipanShopGUI.initializeShop(stage);
stage.show();
});
@@ -174,12 +172,12 @@ public class TravelGUI{
//Continues on to either shop or shipwarfare
continueButton.setOnAction(event -> {
if(peasantShipScene){
- ShipWarfareGUI ship = new ShipWarfareGUI(player);
+ ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
ship.initializeShip(stage);
stage.show();
}
else if(shopScene){
- TaipanShopGUI shop = new TaipanShopGUI(player);
+ TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
@@ -199,43 +197,43 @@ public class TravelGUI{
}
boolean hasTraveled = false;
//Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory.
- if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
- //Just in case the player types something that was not intended. It will refresh the question and ask it again
- try {
- //Makes sure you can't travel to your own location.
- if (response != player.getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
- hasTraveled = seaAtlas(response);
- randomEventSea(response,stage);
- player.setBank((int) (player.getBank() * 1.01));
- player.setDebt((int) (player.getDebt() * 1.01));
- player.setIsPriceChanged(2);
- //shopScene = false;
- //stormScene = false;
+ if(getCargoSpace() >= (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
+ //Just in case the player types something that was not intended. It will refresh the question and ask it again
+ try {
+ //Makes sure you can't travel to your own location.
+ if (response != getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
+ hasTraveled = seaAtlas(response);
+ randomEventSea(response,stage);
+ setBank((int) (getBank() * 1.01));
+ setDebt((int) (getDebt() * 1.01));
+ setIsPriceChanged(2);
+ //shopScene = false;
+ //stormScene = false;
- } else{
- if(response == player.getLocation()){
- textOut.setText(" " + "You're already here " + player.getName() + "\n");
- }
- else{
- textOut.setText(" " + player.getName() + "; Sorry but could you say that again?");
- }
-
- textOut.setText(textOut.getText() + "\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?");
+ } else{
+ if(response == getLocation()){
+ textOut.setText(" " + "You're already here " + getName() + "\n");
}
- } catch (Exception e) {
- textOut.setText(" " + "Sorry, " + player.getName() + " could you say that again?");
- }
- if (hasTraveled) {
- continueButton.setVisible(true);
- quitButton.setVisible(false);
- numberInput.setVisible(false);
- shopScene = true;
+ else{
+ textOut.setText(" " + getName() + "; Sorry but could you say that again?");
+ }
+
+ textOut.setText(textOut.getText() + "\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?");
}
+ } catch (Exception e) {
+ textOut.setText(" " + "Sorry, " + getName() + " could you say that again?");
+ }
+ if (hasTraveled) {
+ continueButton.setVisible(true);
+ quitButton.setVisible(false);
+ numberInput.setVisible(false);
+ shopScene = true;
}
}
- else if (player.getCargoSpace() < (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
- textOut.setText(" "+player.getName() + " the cargo is too heavy! We can't set sail!");
- }
+ }
+ else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
+ textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!");
+ }
});
firm.setAlignment(Pos.CENTER);
@@ -338,34 +336,34 @@ public class TravelGUI{
switch (locationOfTravel) {
case 1:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong");
- player.setLocation(1);
+ setLocation(1);
return true;
case 2:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai");
- player.setLocation(2);
+ setLocation(2);
return true;
case 3:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki");
- player.setLocation(3);
+ setLocation(3);
return true;
case 4:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon");
- player.setLocation(4);
+ setLocation(4);
return true;
case 5:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila");
- player.setLocation(5);
+ setLocation(5);
return true;
case 6:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore");
- player.setLocation(6);
+ setLocation(6);
return true;
case 7:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia");
- player.setLocation(7);
+ setLocation(7);
return true;
default:
- textOut.setText(" " + "Sorry but could you say that again " + player.getName() + "?");
+ textOut.setText(" " + "Sorry but could you say that again " + getName() + "?");
return false;
}
}
@@ -383,7 +381,7 @@ public class TravelGUI{
continueButton.setVisible(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
- textOut.setText(" We see a ship on the horizon " + player.getName() + "; Prepare for combat!");
+ textOut.setText(" We see a ship on the horizon " + getName() + "; Prepare for combat!");
peasantShipScene = true;
}else if (randGenNum == 2) {
disaster(locationOfTravel);
@@ -400,14 +398,14 @@ public class TravelGUI{
**/
private void disaster(int locationOfTravel) {
//Tells player that there is a storm approaching.
- textOut.setText(" " + "Storm " + player.getName() + "! ");
+ textOut.setText(" " + "Storm " + getName() + "! ");
Random rand = new Random();
int randGenNum = rand.nextInt(5) + 1;
//If the player lands within this range, nothing happens to them
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
if (randGenNum <= 2) {
- textOut.setText(textOut.getText() + "\n " + "We got through the storm " + player.getName() + "!");
+ textOut.setText(textOut.getText() + "\n " + "We got through the storm " + getName() + "!");
}else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
@@ -426,7 +424,7 @@ public class TravelGUI{
*/
public String getStringLocation(){
String location;
- switch(player.getLocation()){
+ switch(getLocation()){
case 1: location = "Hong Kong"; break;
case 2: location = "Shanghai"; break;
case 3: location = "Nagasaki"; break;
@@ -446,7 +444,7 @@ public class TravelGUI{
*/
public String shipStatusString(){
String shipStatus;
- switch(player.getHP()/10){
+ switch(getHP()/10){
case 10: shipStatus = "Mint Condition"; break;
case 9: shipStatus = "Near Perfect"; break;
case 8: shipStatus = "Great"; break;
@@ -467,21 +465,21 @@ public class TravelGUI{
* updates the text associated with the user's inventory.
*/
public void updateStage(){
- firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation()));
- wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));
- int itemsInWarehouse = player.getwOpium()+player.getwGeneral()+player.getwArms()+player.getwSilk();
+ firm.setText(String.format("Firm: %s, %s", getName(), getStringLocation()));
+ wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", getwOpium(), getwSilk(), getwArms(), getwGeneral()));
+ int itemsInWarehouse = getwOpium()+getwGeneral()+getwArms()+getwSilk();
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", getStringLocation()));
- int itemsInInventory = player.getCargoSpace()-player.getSilkHeld()-player.getOpiumHeld()-player.getGeneralHeld()-player.getArmsHeld()-10*player.getGuns();
+ int itemsInInventory = getCargoSpace()-getSilkHeld()-getOpiumHeld()-getGeneralHeld()-getArmsHeld()-10*getGuns();
if(itemsInInventory < 0){
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
}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 ", player.getGuns()));
- inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", player.getOpiumHeld(), player.getSilkHeld(), player.getArmsHeld(), player.getGeneralHeld()));
- shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", player.getDebt(), shipStatusString(), player.getHP()));
- cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
- bankText.setText(String.format("Bank: %d", player.getBank()));
+ gunsText.setText(String.format("Guns %d\n\n\n\n ", getGuns()));
+ inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", getOpiumHeld(), getSilkHeld(), getArmsHeld(), getGeneralHeld()));
+ shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", getDebt(), shipStatusString(), getHP()));
+ cashText.setText(String.format(" Cash: $%,d", getMoney()));
+ bankText.setText(String.format("Bank: %d", getBank()));
}
}
diff --git a/src/WarehouseGUI.java b/src/WarehouseGUI.java
index f47a001..cff2c1d 100644
--- a/src/WarehouseGUI.java
+++ b/src/WarehouseGUI.java
@@ -10,14 +10,12 @@ import javafx.scene.text.Text;
import javafx.stage.Stage;
/**
-* 2019-03-10
-* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
-* WarehouseGUI class, Initializes and displays the graphical interface for the warehouse in Taipan
-*
-*/
-public class WarehouseGUI {
-
- private Player player;
+ * 2019-03-10
+ * Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
+ * WarehouseGUI class, Initializes and displays the graphical interface for the warehouse in Taipan
+ *
+ */
+public class WarehouseGUI extends Player{
private Text title;
private HBox hBox;
@@ -56,27 +54,7 @@ public class WarehouseGUI {
*/
public WarehouseGUI(Player player) {
Player playerDummy = new Player(player);
- this.player = playerDummy;
- }
-
- /**
- * Setter method for the Player object, player
- *
- * @param player an object of type Player
- */
- public void setPlayer(Player player) {
- Player playerDummy = new Player(player);
- this.player = playerDummy;
- }
-
- /**
- * Getter method for the Player object, player.
- *
- * @return returns a copy of the Player object, player
- */
- public Player getPlayer() {
- Player playerDummy = new Player(player);
- return playerDummy;
+ setPlayer(playerDummy);
}
/**
@@ -179,33 +157,33 @@ public class WarehouseGUI {
int withdraw = Integer.parseInt(textIn.getText());
updateLabels();
if (opium.isSelected()) {
- if (player.getwOpium() >= withdraw) {
- player.setwOpium(player.getwOpium() - withdraw);
- player.setOpiumHeld(player.getOpiumHeld() + withdraw);
+ if (getwOpium() >= withdraw) {
+ setwOpium(getwOpium() - withdraw);
+ setOpiumHeld(getOpiumHeld() + withdraw);
} else {
title.setText("You don't have that much opium stored in the warehouse!");
}
}
if (silk.isSelected()) {
- if (player.getwSilk() >= withdraw) {
- player.setwSilk(player.getwSilk() - withdraw);
- player.setSilkHeld(player.getSilkHeld() + withdraw);
+ if (getwSilk() >= withdraw) {
+ setwSilk(getwSilk() - withdraw);
+ setSilkHeld(getSilkHeld() + withdraw);
} else {
title.setText("You don't have that much silk stored in the warehouse!");
}
}
if (arms.isSelected()) {
- if (player.getwArms() >= withdraw) {
- player.setwArms(player.getwArms() - withdraw);
- player.setArmsHeld(player.getArmsHeld() + withdraw);
+ if (getwArms() >= withdraw) {
+ setwArms(getwArms() - withdraw);
+ setArmsHeld(getArmsHeld() + withdraw);
} else {
title.setText("You don't have that much arms stored in the warehouse!");
}
}
if (general.isSelected()) {
- if (player.getwGeneral() >= withdraw) {
- player.setwGeneral(player.getwGeneral() - withdraw);
- player.setGeneralHeld(player.getGeneralHeld() + withdraw);
+ if (getwGeneral() >= withdraw) {
+ setwGeneral(getwGeneral() - withdraw);
+ setGeneralHeld(getGeneralHeld() + withdraw);
} else {
title.setText("You don't have that much general stored in the warehouse!");
}
@@ -225,33 +203,33 @@ public class WarehouseGUI {
updateLabels();
int deposit = Integer.parseInt(textIn.getText());
if (opium.isSelected()) {
- if (player.getOpiumHeld() >= deposit) {
- player.setwOpium(player.getwOpium() + deposit);
- player.setOpiumHeld(player.getOpiumHeld() - deposit);
+ if (getOpiumHeld() >= deposit) {
+ setwOpium(getwOpium() + deposit);
+ setOpiumHeld(getOpiumHeld() - deposit);
} else {
title.setText("You don't have that much opium stored in the ship!");
}
}
if (silk.isSelected()) {
- if (player.getwSilk() >= deposit) {
- player.setwSilk(player.getwSilk() + deposit);
- player.setSilkHeld(player.getSilkHeld() - deposit);
+ if (getwSilk() >= deposit) {
+ setwSilk(getwSilk() + deposit);
+ setSilkHeld(getSilkHeld() - deposit);
} else {
title.setText("You don't have that much silk stored in the ship!");
}
}
if (arms.isSelected()) {
- if (player.getwArms() >= deposit) {
- player.setwArms(player.getwArms() + deposit);
- player.setArmsHeld(player.getArmsHeld() - deposit);
+ if (getwArms() >= deposit) {
+ setwArms(getwArms() + deposit);
+ setArmsHeld(getArmsHeld() - deposit);
} else {
title.setText("You don't have that much arms stored in the ship!");
}
}
if (general.isSelected()) {
- if (player.getwGeneral() >= deposit) {
- player.setwGeneral(player.getwGeneral() + deposit);
- player.setGeneralHeld(player.getGeneralHeld() - deposit);
+ if (getwGeneral() >= deposit) {
+ setwGeneral(getwGeneral() + deposit);
+ setGeneralHeld(getGeneralHeld() - deposit);
} else {
title.setText("You don't have that much general stored in the ship!");
}
@@ -618,7 +596,7 @@ public class WarehouseGUI {
* @param primaryStage object of type Stage
*/
public void start(Stage primaryStage) {
- WarehouseGUI warehouseGUI = new WarehouseGUI(player);
+ WarehouseGUI warehouseGUI = new WarehouseGUI(getPlayer());
warehouseGUI.initializeWarehouse(primaryStage);
primaryStage.show();
}
@@ -628,14 +606,14 @@ public class WarehouseGUI {
* can be safely stored without holing space on the ship!
*/
public void updateLabels() {
- generalPlayer.setText("General: " + player.getGeneralHeld());
- armsPlayer.setText("Arms: " + player.getArmsHeld());
- silkPlayer.setText("Silk: " + player.getSilkHeld());
- opiumPlayer.setText("Opium: " + player.getOpiumHeld());
+ generalPlayer.setText("General: " + getGeneralHeld());
+ armsPlayer.setText("Arms: " + getArmsHeld());
+ silkPlayer.setText("Silk: " + getSilkHeld());
+ opiumPlayer.setText("Opium: " + getOpiumHeld());
- generalWarehouse.setText("General: " + player.getwGeneral());
- armsWarehouse.setText("Arms: " + player.getwArms());
- silkWarehouse.setText("Silk: " + player.getwSilk());
- opiumWarehouse.setText("Opium: " + player.getwOpium());
+ generalWarehouse.setText("General: " + getwGeneral());
+ armsWarehouse.setText("Arms: " + getwArms());
+ silkWarehouse.setText("Silk: " + getwSilk());
+ opiumWarehouse.setText("Opium: " + getwOpium());
}
}