Finished cleaning up the code. Ready for Demo 2

This commit is contained in:
2019-03-11 02:05:26 -06:00
parent 076ba12ef1
commit 11b16b4e40
10 changed files with 615 additions and 567 deletions

View File

@@ -1,4 +1,3 @@
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@@ -22,19 +21,15 @@ public class GameEndGUI {
this.player = playerDummy; this.player = playerDummy;
} }
public void setPlayer(Player player) { /**
Player playerDummy = new Player(player); * Sets up the graphical part of GameEndGUI and includes all logic for the class
this.player = playerDummy; *
} * @param stage sets the stage to which we will execute the scene of the GameEndGUI class
* @return stage so that another class can switch to the stage
public Player getPlayer(){ */
Player playerDummy = new Player(player); public Stage initializeGameEndGUI(Stage stage) {
return playerDummy;
}
public Stage initializeGameEndGUI(Stage stage){
//Creating all the nodes
title = new Label(); title = new Label();
vBox = new VBox(); vBox = new VBox();
firmName = new Label(); firmName = new Label();
@@ -46,6 +41,7 @@ public class GameEndGUI {
borderPane.setPrefHeight(480.0); borderPane.setPrefHeight(480.0);
borderPane.setPrefWidth(600.0); borderPane.setPrefWidth(600.0);
//Setting positions and names of all the nodes
BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
title.setText("Game Over!"); title.setText("Game Over!");
title.setFont(new Font(43.0)); title.setFont(new Font(43.0));
@@ -69,21 +65,29 @@ public class GameEndGUI {
borderPane.setCenter(vBox); borderPane.setCenter(vBox);
//Adding the labels to the character's stats to the VBox which will show up on the screen
vBox.getChildren().add(firmName); vBox.getChildren().add(firmName);
vBox.getChildren().add(gunsHeld); vBox.getChildren().add(gunsHeld);
vBox.getChildren().add(netWorth); vBox.getChildren().add(netWorth);
if(player.getHP() <= 0){ /**
* 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) {
title.setText("Game Over!"); title.setText("Game Over!");
} } else {
else{
title.setText("Congratulations!"); title.setText("Congratulations!");
} }
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); * 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 -= player.getDebt();
//Updating the endgame stats of the player
firmName.setText("Firm Name: " + player.getName()); firmName.setText("Firm Name: " + player.getName());
gunsHeld.setText("Guns Held: " + player.getGuns()); gunsHeld.setText("Guns Held: " + player.getGuns());
netWorth.setText("Net Worth: " + netWorthInt); netWorth.setText("Net Worth: " + netWorthInt);
@@ -97,7 +101,11 @@ public class GameEndGUI {
return stage; 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) { public void start(Stage primaryStage) {
GameEndGUI gameEndGUI = new GameEndGUI(player); GameEndGUI gameEndGUI = new GameEndGUI(player);
gameEndGUI.initializeGameEndGUI(primaryStage); gameEndGUI.initializeGameEndGUI(primaryStage);

View File

@@ -1,4 +1,3 @@
import javafx.application.Application; import javafx.application.Application;
import javafx.stage.Stage; import javafx.stage.Stage;
@@ -11,7 +10,7 @@ public class MainGUI extends Application {
* @return returns a copy of the object player * @return returns a copy of the object player
*/ */
public Player getPlayer(){ public Player getPlayer() {
Player copy = new Player(player); Player copy = new Player(player);
return copy; return copy;
} }
@@ -22,7 +21,7 @@ public class MainGUI extends Application {
* @param shop player object from the main class used to update the shop class * @param shop player object from the main class used to update the shop class
*/ */
public void shop(TaipanShopGUI shop){ public void shop(TaipanShopGUI shop) {
shop.setPlayer(player); shop.setPlayer(player);
shop.shop(); shop.shop();
player = shop.getPlayer(); player = shop.getPlayer();
@@ -31,6 +30,7 @@ public class MainGUI extends Application {
/** /**
* Updates main class with player data and starts the game. * Updates main class with player data and starts the game.
* The game will only run as long as the player has not retired or has been destroyed. * The game will only run as long as the player has not retired or has been destroyed.
*
* @param args Just the console for the player to look at. * @param args Just the console for the player to look at.
*/ */
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -18,7 +18,7 @@ public class Player {
private boolean retire = false; private boolean retire = false;
private int cargoSpace = 60; private int cargoSpace = 60;
public Player(){ public Player() {
this.name = "Taipan"; this.name = "Taipan";
this.bank = 0; this.bank = 0;
this.money = 0; this.money = 0;
@@ -39,11 +39,11 @@ public class Player {
} }
/** /**
* Copy constructor * Copy constructor
* *
* @param player object of the class Player * @param player object of the class Player
*/ */
public Player(Player player){ public Player(Player player) {
this.name = player.name; this.name = player.name;
this.bank = player.bank; this.bank = player.bank;
this.money = player.money; this.money = player.money;
@@ -63,84 +63,84 @@ public class Player {
} }
/** /**
* getter method for the instance variable cargoSpace. * getter method for the instance variable cargoSpace.
* *
* @return returns the instance variable cargoSpace * @return returns the instance variable cargoSpace
*/ */
public int getCargoSpace() { public int getCargoSpace() {
return cargoSpace; return cargoSpace;
} }
/** /**
* setter method for the instance variable cargoSpace. * setter method for the instance variable cargoSpace.
* *
* @param cargoSpace takes an int that is greater than 0 as an argument * @param cargoSpace takes an int that is greater than 0 as an argument
*/ */
public void setCargoSpace(int cargoSpace) { public void setCargoSpace(int cargoSpace) {
if(cargoSpace > 0){ if (cargoSpace > 0) {
this.cargoSpace = cargoSpace; this.cargoSpace = cargoSpace;
} }
} }
/** /**
* getter method for the instance variable retire. * getter method for the instance variable retire.
* *
* @return returns the instance variable retire * @return returns the instance variable retire
*/ */
public boolean getRetire(){ public boolean getRetire() {
return retire; return retire;
} }
/** /**
* setter method for the instance variable retire. * setter method for the instance variable retire.
* *
* @param retire takes a boolean as an argument * @param retire takes a boolean as an argument
*/ */
public void setRetire(boolean retire){ public void setRetire(boolean retire) {
if(retire){ if (retire) {
this.retire = retire; this.retire = retire;
} }
} }
/** /**
* getter method for the instance variable name. * getter method for the instance variable name.
* *
* @return returns the instance variable name * @return returns the instance variable name
*/ */
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* setter method for the instance variable name. * setter method for the instance variable name.
* *
* @param name takes a string as an argument * @param name takes a string as an argument
*/ */
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /**
* getter method for the instance variable HP. * getter method for the instance variable HP.
* *
* @return returns the instance variable HP * @return returns the instance variable HP
*/ */
public int getHP() { public int getHP() {
return HP; return HP;
} }
/** /**
* setter method for the instance variable HP. * setter method for the instance variable HP.
* *
* @param HP takes an int as an argument * @param HP takes an int as an argument
*/ */
public void setHP(int HP) { public void setHP(int HP) {
@@ -148,21 +148,21 @@ public class Player {
} }
/** /**
* getter method for the instance variable bank. * getter method for the instance variable bank.
* *
* @return returns the instance variable bank * @return returns the instance variable bank
*/ */
public int getBank() { public int getBank() {
return bank; return bank;
} }
/** /**
* setter method for the instance variable bank. * setter method for the instance variable bank.
* *
* @param bank takes an int that is greater than or equal to 0 as an argument * @param bank takes an int that is greater than or equal to 0 as an argument
*/ */
public void setBank(int bank) { public void setBank(int bank) {
if (bank >= 0) { if (bank >= 0) {
this.bank = bank; this.bank = bank;
@@ -170,21 +170,21 @@ public class Player {
} }
/** /**
* getter method for the instance variable money. * getter method for the instance variable money.
* *
* @return returns the instance variable money * @return returns the instance variable money
*/ */
public int getMoney() { public int getMoney() {
return money; return money;
} }
/** /**
* setter method for the instance variable money. * setter method for the instance variable money.
* *
* @param money takes an int that is greater than or equal to 0 as an argument * @param money takes an int that is greater than or equal to 0 as an argument
*/ */
public void setMoney(int money) { public void setMoney(int money) {
if (money >= 0) { if (money >= 0) {
this.money = money; this.money = money;
@@ -192,21 +192,21 @@ public class Player {
} }
/** /**
* getter method for the instance variable opiumHeld. * getter method for the instance variable opiumHeld.
* *
* @return returns the instance variable opiumHeld * @return returns the instance variable opiumHeld
*/ */
public int getOpiumHeld() { public int getOpiumHeld() {
return opiumHeld; return opiumHeld;
} }
/** /**
* setter method for the instance variable opiumHeld. * setter method for the instance variable opiumHeld.
* *
* @param opiumHeld takes an int that is greater than or equal to 0 as an argument * @param opiumHeld takes an int that is greater than or equal to 0 as an argument
*/ */
public void setOpiumHeld(int opiumHeld) { public void setOpiumHeld(int opiumHeld) {
if (opiumHeld >= 0) { if (opiumHeld >= 0) {
this.opiumHeld = opiumHeld; this.opiumHeld = opiumHeld;
@@ -214,42 +214,42 @@ public class Player {
} }
/** /**
* getter method for the instance variable silkHeld. * getter method for the instance variable silkHeld.
* *
* @return returns the instance variable silkHeld * @return returns the instance variable silkHeld
*/ */
public int getSilkHeld() { public int getSilkHeld() {
return silkHeld; return silkHeld;
} }
/** /**
* setter method for the instance variable silkHeld. * setter method for the instance variable silkHeld.
* *
* @param silkHeld takes an int that is greater than or equal to 0 as an argument * @param silkHeld takes an int that is greater than or equal to 0 as an argument
*/ */
public void setSilkHeld(int silkHeld) { public void setSilkHeld(int silkHeld) {
if (silkHeld >= 0) { if (silkHeld >= 0) {
this.silkHeld = silkHeld; this.silkHeld = silkHeld;
} }
} }
/** /**
* getter method for the instance variable generalHeld. * getter method for the instance variable generalHeld.
* *
* @return returns the instance variable generalHeld * @return returns the instance variable generalHeld
*/ */
public int getGeneralHeld() { public int getGeneralHeld() {
return generalHeld; return generalHeld;
} }
/** /**
* setter method for the instance variable generalHeld. * setter method for the instance variable generalHeld.
* *
* @param generalHeld takes an int that is greater than or equal to 0 as an argument * @param generalHeld takes an int that is greater than or equal to 0 as an argument
*/ */
public void setGeneralHeld(int generalHeld) { public void setGeneralHeld(int generalHeld) {
if (generalHeld >= 0) { if (generalHeld >= 0) {
@@ -258,21 +258,21 @@ public class Player {
} }
/** /**
* getter method for the instance variable armsHeld. * getter method for the instance variable armsHeld.
* *
* @return returns the instance variable armsHeld * @return returns the instance variable armsHeld
*/ */
public int getArmsHeld() { public int getArmsHeld() {
return armsHeld; return armsHeld;
} }
/** /**
* setter method for the instance variable armsHeld. * setter method for the instance variable armsHeld.
* *
* @param armsHeld takes an int that is greater than or equal to 0 as an argument * @param armsHeld takes an int that is greater than or equal to 0 as an argument
*/ */
public void setArmsHeld(int armsHeld) { public void setArmsHeld(int armsHeld) {
if (armsHeld >= 0) { if (armsHeld >= 0) {
this.armsHeld = armsHeld; this.armsHeld = armsHeld;
@@ -280,21 +280,21 @@ public class Player {
} }
/** /**
* getter method for the instance variable location. * getter method for the instance variable location.
* *
* @return returns the instance variable location * @return returns the instance variable location
*/ */
public int getLocation() { public int getLocation() {
return location; return location;
} }
/** /**
* setter method for the instance variable location. * setter method for the instance variable location.
* *
* @param location takes an int that is greater than or equal to 0 as an argument * @param location takes an int that is greater than or equal to 0 as an argument
*/ */
public void setLocation(int location) { public void setLocation(int location) {
if (location >= 0) { if (location >= 0) {
this.location = location; this.location = location;
@@ -302,44 +302,44 @@ public class Player {
} }
/** /**
* getter method for the instance variable guns. * getter method for the instance variable guns.
* *
* @return returns the instance variable guns * @return returns the instance variable guns
*/ */
public int getGuns() { public int getGuns() {
return guns; return guns;
} }
/** /**
* setter method for the instance variable guns. * setter method for the instance variable guns.
* *
* @param guns takes an int that is greater than or equal to 0 as an argument * @param guns takes an int that is greater than or equal to 0 as an argument
*/ */
public void setGuns(int guns) { public void setGuns(int guns) {
if (guns >= 0) { if (guns >= 0) {
this.guns = guns; this.guns = guns;
} }
} }
/** /**
* getter method for the instance variable debt. * getter method for the instance variable debt.
* *
* @return returns the instance variable debt * @return returns the instance variable debt
*/ */
public int getDebt() { public int getDebt() {
return debt; return debt;
} }
/** /**
* setter method for the instance variable debt. * setter method for the instance variable debt.
* *
* @param debt takes an int that is greater than or equal to 0 as an argument * @param debt takes an int that is greater than or equal to 0 as an argument
*/ */
public void setDebt(int debt) { public void setDebt(int debt) {
if (debt >= 0) { if (debt >= 0) {
this.debt = debt; this.debt = debt;
@@ -347,89 +347,89 @@ public class Player {
} }
/** /**
* getter method for the instance variable wOpium. * getter method for the instance variable wOpium.
* *
* @return returns the instance variable wOpium * @return returns the instance variable wOpium
*/ */
public int getwOpium() { public int getwOpium() {
return wOpium; return wOpium;
} }
/** /**
* setter method for the instance variable wOpium. * setter method for the instance variable wOpium.
* *
* @param wOpium takes an int that is greater than or equal to 0 as an argument * @param wOpium takes an int that is greater than or equal to 0 as an argument
*/ */
public void setwOpium(int wOpium) { public void setwOpium(int wOpium) {
if (wOpium >= 0){ if (wOpium >= 0) {
this.wOpium = wOpium; this.wOpium = wOpium;
} }
} }
/** /**
* getter method for the instance variable wSilk. * getter method for the instance variable wSilk.
* *
* @return returns the instance variable wSilk * @return returns the instance variable wSilk
*/ */
public int getwSilk() { public int getwSilk() {
return wSilk; return wSilk;
} }
/** /**
* setter method for the instance variable wSilk. * setter method for the instance variable wSilk.
* *
* @param wSilk takes an int that is greater than or equal to 0 as an argument * @param wSilk takes an int that is greater than or equal to 0 as an argument
*/ */
public void setwSilk(int wSilk) { public void setwSilk(int wSilk) {
if (wSilk >= 0){ if (wSilk >= 0) {
this.wSilk = wSilk; this.wSilk = wSilk;
} }
} }
/** /**
* getter method for the instance variable wGeneral. * getter method for the instance variable wGeneral.
* *
* @return returns the instance variable wGeneral * @return returns the instance variable wGeneral
*/ */
public int getwGeneral() { public int getwGeneral() {
return wGeneral; return wGeneral;
} }
/** /**
* setter method for the instance variable wGeneral. * setter method for the instance variable wGeneral.
* *
* @param wGeneral takes an int that is greater than or equal to 0 as an argument * @param wGeneral takes an int that is greater than or equal to 0 as an argument
*/ */
public void setwGeneral(int wGeneral) { public void setwGeneral(int wGeneral) {
if (wGeneral >= 0){ if (wGeneral >= 0) {
this.wGeneral = wGeneral; this.wGeneral = wGeneral;
} }
} }
/** /**
* getter method for the instance variable wArms. * getter method for the instance variable wArms.
* *
* @return returns the instance variable wArms * @return returns the instance variable wArms
*/ */
public int getwArms() { public int getwArms() {
return wArms; return wArms;
} }
/** /**
* setter method for the instance variable wArms. * setter method for the instance variable wArms.
* *
* @param wArms takes an int that is greater than or equal to 0 as an argument * @param wArms takes an int that is greater than or equal to 0 as an argument
*/ */
public void setwArms(int wArms) { public void setwArms(int wArms) {
if (wArms >= 0){ if (wArms >= 0) {
this.wArms = wArms; this.wArms = wArms;
} }
} }
@@ -437,10 +437,9 @@ public class Player {
/** /**
* Method to indicate that you have lost the game. If the player has lost, console will be cleared and will only * Method to indicate that you have lost the game. If the player has lost, console will be cleared and will only
* show the statement "Game Over". After showing the message the game closes. * show the statement "Game Over". After showing the message the game closes.
*
**/ **/
public void gameOver(){ public void gameOver() {
System.out.flush(); System.out.flush();
System.out.println("Game over"); System.out.println("Game over");
System.exit(0); System.exit(0);

View File

@@ -357,7 +357,7 @@ public class ShipWarfareGUI {
BorderPane.setBottom(hBox); BorderPane.setBottom(hBox);
runButton.setText("Run"); runButton.setText("Run");
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER); javafx.scene.layout.BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER); vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
vBox.setPrefHeight(200.0); vBox.setPrefHeight(200.0);
vBox.setPrefWidth(100.0); vBox.setPrefWidth(100.0);

View File

@@ -49,22 +49,20 @@ public class StartGUI {
* *
* @param name the name that you would like to be called in the game * @param name the name that you would like to be called in the game
*/ */
public void setFirm (String name) { public void setFirm(String name) {
if (name.length() <= 22) { if (name.length() <= 22) {
player.setName(name); player.setName(name);
} } else {
else{
player.setName("Taipan"); player.setName("Taipan");
} }
} }
/* /*
** **
* Copy constructor. * Copy constructor.
* @param player object of the class Player * @param player object of the class Player
*/ */
public StartGUI(Player player) public StartGUI(Player player) {
{
Player playerTemp = new Player(player); Player playerTemp = new Player(player);
this.player = playerTemp; this.player = playerTemp;
} }
@@ -75,13 +73,13 @@ public class StartGUI {
* @param stage object of type Stage * @param stage object of type Stage
* @return returns the stage of GUI * @return returns the stage of GUI
*/ */
public Stage initializeStart(Stage stage){ public Stage 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.
* *
*/ */
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER); hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0); hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0); hBox.setPrefWidth(200.0);

View File

@@ -1,17 +1,18 @@
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.util.Random; import java.util.Random;
public class TaipanShopGUI { public class TaipanShopGUI {
@@ -36,7 +37,7 @@ public class TaipanShopGUI {
private Button cargoButton = new Button(); private Button cargoButton = new Button();
private Button opiumButton = new Button(); private Button opiumButton = new Button();
private Button silkButton = new Button(); private Button silkButton = new Button();
private Button armsButton = new Button(); private Button armsButton = new Button();
private Button generalButton = new Button(); private Button generalButton = new Button();
private TextField numberInput = new TextField(); private TextField numberInput = new TextField();
private int opiumPrice = 16000; private int opiumPrice = 16000;
@@ -49,7 +50,7 @@ public class TaipanShopGUI {
* *
* @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 TaipanShopGUI(Player player){ public TaipanShopGUI(Player player) {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
@@ -57,7 +58,7 @@ public class TaipanShopGUI {
/** /**
* This method is evoked if the user is eligible to win, and chooses to end the game (by winning). * This method is evoked if the user is eligible to win, and chooses to end the game (by winning).
*/ */
public void retire(Stage stage){ public void retire(Stage stage) {
player.setRetire(true); player.setRetire(true);
GameEndGUI gameEndGUI = new GameEndGUI(player); GameEndGUI gameEndGUI = new GameEndGUI(player);
gameEndGUI.initializeGameEndGUI(stage); gameEndGUI.initializeGameEndGUI(stage);
@@ -79,7 +80,7 @@ public class TaipanShopGUI {
* *
* @return playerDummy -- playerDummy is a copy of the player instance variable. * @return playerDummy -- playerDummy is a copy of the player instance variable.
*/ */
public Player getPlayer(){ public Player getPlayer() {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
return playerDummy; return playerDummy;
} }
@@ -99,7 +100,7 @@ public class TaipanShopGUI {
* @param opiumPrice -- what the instance variable opiumPrice should be changed to. * @param opiumPrice -- what the instance variable opiumPrice should be changed to.
*/ */
public void setOpiumPrice(int opiumPrice) { public void setOpiumPrice(int opiumPrice) {
if(opiumPrice > 0){ if (opiumPrice > 0) {
this.opiumPrice = opiumPrice; this.opiumPrice = opiumPrice;
} }
} }
@@ -119,7 +120,7 @@ public class TaipanShopGUI {
* @param silkPrice -- what the instance variable silkPrice should be changed to. * @param silkPrice -- what the instance variable silkPrice should be changed to.
*/ */
public void setSilkPrice(int silkPrice) { public void setSilkPrice(int silkPrice) {
if(silkPrice > 0){ if (silkPrice > 0) {
this.silkPrice = silkPrice; this.silkPrice = silkPrice;
} }
} }
@@ -139,7 +140,7 @@ public class TaipanShopGUI {
* @param armsPrice -- what the instance variable armsPrice should be changed to. * @param armsPrice -- what the instance variable armsPrice should be changed to.
*/ */
public void setArmsPrice(int armsPrice) { public void setArmsPrice(int armsPrice) {
if(armsPrice > 0){ if (armsPrice > 0) {
this.armsPrice = armsPrice; this.armsPrice = armsPrice;
} }
} }
@@ -159,7 +160,7 @@ public class TaipanShopGUI {
* @param generalPrice -- what the instance variable generalPrice should be changed to. * @param generalPrice -- what the instance variable generalPrice should be changed to.
*/ */
public void setGeneralPrice(int generalPrice) { public void setGeneralPrice(int generalPrice) {
if(generalPrice > 0){ if (generalPrice > 0) {
this.generalPrice = generalPrice; this.generalPrice = generalPrice;
} }
} }
@@ -167,48 +168,48 @@ public class TaipanShopGUI {
/** /**
* this method is when the shop is accessed, randomizing the prices of all the items. * this method is when the shop is accessed, randomizing the prices of all the items.
*/ */
public void updatePrices(){ public void updatePrices() {
String s = "\t" + player.getName() + ", the price of "; String s = "\t" + player.getName() + ", the price of ";
double value = 80*Math.random(); double value = 80 * Math.random();
Random rand = new Random(); Random rand = new Random();
opiumPrice = (rand.nextInt(201) + 60)*100; opiumPrice = (rand.nextInt(201) + 60) * 100;
silkPrice = (rand.nextInt(201) + 60)*10; silkPrice = (rand.nextInt(201) + 60) * 10;
armsPrice = (rand.nextInt(21) + 6)*10; armsPrice = (rand.nextInt(21) + 6) * 10;
generalPrice = rand.nextInt(17) + 4; generalPrice = rand.nextInt(17) + 4;
// there is a 10% chance that the price of an item is increased/decreased beyond its regular range. // there is a 10% chance that the price of an item is increased/decreased beyond its regular range.
if(value < 8){ if (value < 8) {
if(value < 2){ if (value < 2) {
if(value < 1){ if (value < 1) {
opiumPrice /= 5; opiumPrice /= 5;
textOut.setText(s + "Opium has dropped to " + opiumPrice +"!!!\n"+textOut.getText()); textOut.setText(s + "Opium has dropped to " + opiumPrice + "!!!\n" + textOut.getText());
}else{ } else {
opiumPrice *= 5; opiumPrice *= 5;
textOut.setText(s + "Opium has risen to " + opiumPrice +"!!!\n"+textOut.getText()); textOut.setText(s + "Opium has risen to " + opiumPrice + "!!!\n" + textOut.getText());
} }
}else if(value < 4){ } else if (value < 4) {
if(value < 3){ if (value < 3) {
silkPrice /= 5; silkPrice /= 5;
textOut.setText(s + "Silk has dropped to " + silkPrice +"!!!\n"+textOut.getText()); textOut.setText(s + "Silk has dropped to " + silkPrice + "!!!\n" + textOut.getText());
}else{ } else {
silkPrice *= 5; silkPrice *= 5;
textOut.setText(s + "Silk has risen to " + silkPrice +"!!!\n"+textOut.getText()); textOut.setText(s + "Silk has risen to " + silkPrice + "!!!\n" + textOut.getText());
} }
}else if(value < 6){ } else if (value < 6) {
if(value < 3){ if (value < 3) {
armsPrice /= 5; armsPrice /= 5;
textOut.setText(s + "Arms has dropped to " + armsPrice +"!!!\n"+textOut.getText()); textOut.setText(s + "Arms has dropped to " + armsPrice + "!!!\n" + textOut.getText());
}else{ } else {
armsPrice *= 5; armsPrice *= 5;
textOut.setText(s + "Arms has risen to " + armsPrice +"!!!\n"+textOut.getText()); textOut.setText(s + "Arms has risen to " + armsPrice + "!!!\n" + textOut.getText());
} }
}else{ } else {
if(value < 7){ if (value < 7) {
generalPrice = 1; generalPrice = 1;
textOut.setText(s + "General Cargo has dropped to 1!!!\n"+textOut.getText()); textOut.setText(s + "General Cargo has dropped to 1!!!\n" + textOut.getText());
}else{ } else {
generalPrice *= 5; generalPrice *= 5;
textOut.setText(s + "General Cargo has risen to " + generalPrice + "!!!\n"+textOut.getText()); textOut.setText(s + "General Cargo has risen to " + generalPrice + "!!!\n" + textOut.getText());
} }
} }
} }
@@ -217,7 +218,7 @@ public class TaipanShopGUI {
/** /**
* Sets the default dialogue of simply stating the prices of the items. * Sets the default dialogue of simply stating the prices of the items.
*/ */
public void defaultTextOut(){ public void defaultTextOut() {
textOut.setText(String.format("\t%s, present prices per unit here are:\n\n\t\tOpium: %d\t\t\tSilk: %d\n\t\tArms: %d\t\t\tGeneral: %d", player.getName(), getOpiumPrice(), getSilkPrice(), getArmsPrice(), getGeneralPrice())); textOut.setText(String.format("\t%s, present prices per unit here are:\n\n\t\tOpium: %d\t\t\tSilk: %d\n\t\tArms: %d\t\t\tGeneral: %d", player.getName(), getOpiumPrice(), getSilkPrice(), getArmsPrice(), getGeneralPrice()));
} }
@@ -266,7 +267,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false); generalButton.setVisible(false);
retireButton.setVisible(false); retireButton.setVisible(false);
} }
if(player.getBank() + player.getMoney() - player.getDebt() < 1000000 && player.getLocation() == 1){ if (player.getBank() + player.getMoney() - player.getDebt() < 1000000 && player.getLocation() == 1) {
buyButton.setVisible(true); buyButton.setVisible(true);
sellButton.setVisible(true); sellButton.setVisible(true);
bankButton.setVisible(true); bankButton.setVisible(true);
@@ -279,7 +280,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false); generalButton.setVisible(false);
armsButton.setVisible(false); armsButton.setVisible(false);
retireButton.setVisible(false); retireButton.setVisible(false);
}else if(player.getLocation() == 1){ } else if (player.getLocation() == 1) {
buyButton.setVisible(true); buyButton.setVisible(true);
sellButton.setVisible(true); sellButton.setVisible(true);
bankButton.setVisible(true); bankButton.setVisible(true);
@@ -293,7 +294,7 @@ public class TaipanShopGUI {
armsButton.setVisible(false); armsButton.setVisible(false);
retireButton.setVisible(true); retireButton.setVisible(true);
} }
} else if(state.equals("input")){ } else if (state.equals("input")) {
buyButton.setVisible(false); buyButton.setVisible(false);
sellButton.setVisible(false); sellButton.setVisible(false);
bankButton.setVisible(false); bankButton.setVisible(false);
@@ -312,68 +313,68 @@ public class TaipanShopGUI {
/** /**
* this method is responsible for the actual purchasing/selling of items, and the text associated with the act. * this method is responsible for the actual purchasing/selling of items, and the text associated with the act.
*/ */
public void shop(){ public void shop() {
String originalDialogue = textOut.getText(); String originalDialogue = textOut.getText();
int num = Integer.parseInt(numberInput.getText().replace(" ", "")); int num = Integer.parseInt(numberInput.getText().replace(" ", ""));
if(buyButton.getText().contains(".")){ if (buyButton.getText().contains(".")) {
if(opiumButton.getText().contains(".") && num <= player.getMoney() / opiumPrice && num >= 0){ if (opiumButton.getText().contains(".") && num <= player.getMoney() / opiumPrice && num >= 0) {
player.setMoney(player.getMoney()-num*opiumPrice); player.setMoney(player.getMoney() - num * opiumPrice);
player.setOpiumHeld(player.getOpiumHeld()+num); player.setOpiumHeld(player.getOpiumHeld() + num);
}else if (num >= 0 && opiumButton.getText().contains(".")) { } else if (num >= 0 && opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() + ", you can't afford that!"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
}else if(opiumButton.getText().contains(".")) { } else if (opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() +", how am I supposed to buy " + "'" + num + "'" + " Opium?"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}else if(silkButton.getText().contains(".") && num <= player.getMoney() / silkPrice && num >= 0){ } else if (silkButton.getText().contains(".") && num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num); player.setSilkHeld(player.getSilkHeld() + num);
player.setMoney(player.getMoney()-num * silkPrice); player.setMoney(player.getMoney() - num * silkPrice);
}else if (num >= 0 && silkButton.getText().contains(".")) { } else if (num >= 0 && silkButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() + ", you can't afford that!"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
}else if(silkButton.getText().contains(".")) { } else if (silkButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() +", how am I supposed to buy " + "'" + num + "'" + " Silk?"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}else if(armsButton.getText().contains(".") && num <= player.getMoney() / armsPrice && num >= 0){ } else if (armsButton.getText().contains(".") && num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num); player.setArmsHeld(player.getArmsHeld() + num);
player.setMoney(player.getMoney() - num*armsPrice); player.setMoney(player.getMoney() - num * armsPrice);
}else if(num >= 0 && armsButton.getText().contains(".")){ } else if (num >= 0 && armsButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() + ", you can't afford that!"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
}else if(armsButton.getText().contains(".")){ } else if (armsButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() +", how am I supposed to buy " + "'" + num + "'" + " Arms?"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}else if(generalButton.getText().contains(".") && num <= player.getMoney() / generalPrice && num >= 0){ } else if (generalButton.getText().contains(".") && num <= player.getMoney() / generalPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num); player.setArmsHeld(player.getArmsHeld() + num);
player.setMoney(player.getMoney() - num*generalPrice); player.setMoney(player.getMoney() - num * generalPrice);
}else if(num >= 0 && generalButton.getText().contains(".")){ } else if (num >= 0 && generalButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() + ", you can't afford that!"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
}else if(generalButton.getText().contains(".")){ } 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" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
} }
}else if(sellButton.getText().contains(".")){ } else if (sellButton.getText().contains(".")) {
if(opiumButton.getText().contains(".") && num <= player.getOpiumHeld() && num >= 0){ if (opiumButton.getText().contains(".") && num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num); player.setOpiumHeld(player.getOpiumHeld() - num);
player.setMoney(player.getMoney() + num*opiumPrice); player.setMoney(player.getMoney() + num * opiumPrice);
}else if (num >= 0 && opiumButton.getText().contains(".")) { } 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" + player.getName() + ", you don't have that many to sell!");
}else if(opiumButton.getText().contains(".")) { } else if (opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() +", how am I supposed to sell " + "'" + num + "'" + " Opium?"); 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){ } else if (silkButton.getText().contains(".") && num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num); player.setSilkHeld(player.getSilkHeld() - num);
player.setMoney(player.getMoney() + num*silkPrice); player.setMoney(player.getMoney() + num * silkPrice);
}else if (num >= 0 && silkButton.getText().contains(".")) { } 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" + player.getName() + ", you don't have that many to sell!");
}else if(silkButton.getText().contains(".")) { } else if (silkButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() +", how am I supposed to sell " + "'" + num + "'" + " Silk?"); 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){ } else if (armsButton.getText().contains(".") && num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num); player.setArmsHeld(player.getArmsHeld() - num);
player.setMoney(player.getMoney() + num*armsPrice); player.setMoney(player.getMoney() + num * armsPrice);
}else if(num >= 0 && armsButton.getText().contains(".")){ } 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" + player.getName() + ", you don't have that many to sell!");
}else if(armsButton.getText().contains(".")){ } else if (armsButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.getName() +", how am I supposed to sell " + "'" + num + "'" + " Arms?"); 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){ } else if (generalButton.getText().contains(".") && num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num); player.setGeneralHeld(player.getGeneralHeld() - num);
player.setMoney(player.getMoney() + num*generalPrice); player.setMoney(player.getMoney() + num * generalPrice);
}else if(num >= 0 && generalButton.getText().contains(".")){ } 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" + player.getName() + ", you don't have that many to sell!");
}else{ } else {
textOut.setText(originalDialogue+"\n\t"+ player.getName() +", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
} }
} }
} }
@@ -383,7 +384,7 @@ public class TaipanShopGUI {
* *
* @param stage * @param stage
*/ */
public void initializeShop(Stage stage){ public void initializeShop(Stage stage) {
Font size14 = new Font(14.0); Font size14 = new Font(14.0);
Rectangle dialogueRectangle = new Rectangle(); Rectangle dialogueRectangle = new Rectangle();
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE); dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
@@ -484,7 +485,7 @@ public class TaipanShopGUI {
buttonSetup("shop"); buttonSetup("shop");
buyButton.setText("Buy."); buyButton.setText("Buy.");
defaultTextOut(); defaultTextOut();
textOut.setText(textOut.getText()+"\n\tWhich good would you like to purchase?"); textOut.setText(textOut.getText() + "\n\tWhich good would you like to purchase?");
} }
}); });
@@ -497,7 +498,7 @@ public class TaipanShopGUI {
buttonSetup("shop"); buttonSetup("shop");
sellButton.setText("Sell."); sellButton.setText("Sell.");
defaultTextOut(); defaultTextOut();
textOut.setText(textOut.getText()+"\n\tWhich good would you like to sell?"); textOut.setText(textOut.getText() + "\n\tWhich good would you like to sell?");
} }
}); });
sellButton.setPrefWidth(45.0); sellButton.setPrefWidth(45.0);
@@ -587,12 +588,12 @@ public class TaipanShopGUI {
opiumButton.setText("Opium."); opiumButton.setText("Opium.");
defaultTextOut(); defaultTextOut();
String extraText; String extraText;
if(buyButton.getText().contains(".")){ if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney()/opiumPrice); extraText = String.format(" (You can afford %d)", player.getMoney() / opiumPrice);
}else{ } else {
extraText = String.format(" (You have %d)", player.getOpiumHeld()); extraText = String.format(" (You have %d)", player.getOpiumHeld());
} }
textOut.setText(textOut.getText()+"\n\tWhat quantity of Opium?" + extraText); textOut.setText(textOut.getText() + "\n\tWhat quantity of Opium?" + extraText);
} }
}); });
@@ -609,12 +610,12 @@ public class TaipanShopGUI {
silkButton.setText("Silk."); silkButton.setText("Silk.");
defaultTextOut(); defaultTextOut();
String extraText; String extraText;
if(buyButton.getText().contains(".")){ if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney()/silkPrice); extraText = String.format(" (You can afford %d)", player.getMoney() / silkPrice);
}else{ } else {
extraText = String.format(" (You have %d)", player.getSilkHeld()); extraText = String.format(" (You have %d)", player.getSilkHeld());
} }
textOut.setText(textOut.getText()+"\n\tWhat quantity of Silk?" + extraText); textOut.setText(textOut.getText() + "\n\tWhat quantity of Silk?" + extraText);
} }
}); });
@@ -629,12 +630,12 @@ public class TaipanShopGUI {
armsButton.setText("Arms."); armsButton.setText("Arms.");
defaultTextOut(); defaultTextOut();
String extraText; String extraText;
if(buyButton.getText().contains(".")){ if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney()/armsPrice); extraText = String.format(" (You can afford %d)", player.getMoney() / armsPrice);
}else{ } else {
extraText = String.format(" (You have %d)", player.getArmsHeld()); extraText = String.format(" (You have %d)", player.getArmsHeld());
} }
textOut.setText(textOut.getText()+"\n\tWhat quantity of Arms?" + extraText); textOut.setText(textOut.getText() + "\n\tWhat quantity of Arms?" + extraText);
} }
}); });
armsButton.setText("Arms"); armsButton.setText("Arms");
@@ -653,12 +654,12 @@ public class TaipanShopGUI {
generalButton.setText("General."); generalButton.setText("General.");
defaultTextOut(); defaultTextOut();
String extraText; String extraText;
if(buyButton.getText().contains(".")){ if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney()/generalPrice); extraText = String.format(" (You can afford %d)", player.getMoney() / generalPrice);
}else{ } else {
extraText = String.format(" (You have %d)", player.getGeneralHeld()); extraText = String.format(" (You have %d)", player.getGeneralHeld());
} }
textOut.setText(textOut.getText()+"\n\tWhat quantity of General Cargo?" + extraText); textOut.setText(textOut.getText() + "\n\tWhat quantity of General Cargo?" + extraText);
} }
}); });
@@ -672,23 +673,23 @@ public class TaipanShopGUI {
public void handle(KeyEvent event) { public void handle(KeyEvent event) {
boolean exit = true; boolean exit = true;
defaultTextOut(); defaultTextOut();
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) { if (event.getCode().equals(KeyCode.ENTER) || event.getCode().equals(KeyCode.Z)) {
while(true){ while (true) {
if(!textOut.getText().contains("You entered an invalid input!")&& !exit){ if (!textOut.getText().contains("You entered an invalid input!") && !exit) {
textOut.setText(textOut.getText()+"\n\n\tYou entered an invalid input! Please try again."); textOut.setText(textOut.getText() + "\n\n\tYou entered an invalid input! Please try again.");
break; break;
} }
try{ try {
shop(); shop();
}catch(Exception e){ } catch (Exception e) {
exit = false; exit = false;
} }
if(exit){ if (exit) {
break; break;
} }
} }
updateStage(); updateStage();
buttonSetup("reset"); buttonSetup("reset");
} }
} }
@@ -714,13 +715,13 @@ public class TaipanShopGUI {
wItemSpaceText.setPrefHeight(108.0); wItemSpaceText.setPrefHeight(108.0);
wItemSpaceText.setPrefWidth(215.0); wItemSpaceText.setPrefWidth(215.0);
wItemSpaceText.setFont(size14); wItemSpaceText.setFont(size14);
locationText.setAlignment(Pos.BOTTOM_CENTER); locationText.setAlignment(Pos.BOTTOM_CENTER);
locationText.setPrefHeight(106.0); locationText.setPrefHeight(106.0);
locationText.setPrefWidth(175.0); locationText.setPrefWidth(175.0);
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
locationText.setFont(size14); locationText.setFont(size14);
inventoryText.setAlignment(Pos.CENTER); inventoryText.setAlignment(Pos.CENTER);
inventoryText.setFont(size14); inventoryText.setFont(size14);
@@ -733,14 +734,14 @@ public class TaipanShopGUI {
gunsText.setPrefWidth(212.0); gunsText.setPrefWidth(212.0);
gunsText.setAlignment(Pos.CENTER_LEFT); gunsText.setAlignment(Pos.CENTER_LEFT);
gunsText.setFont(size14); gunsText.setFont(size14);
shipStatusText.setAlignment(Pos.TOP_CENTER); shipStatusText.setAlignment(Pos.TOP_CENTER);
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER); shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
shipStatusText.setPrefHeight(110.0); shipStatusText.setPrefHeight(110.0);
shipStatusText.setPrefWidth(180.0); shipStatusText.setPrefWidth(180.0);
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
shipStatusText.setFont(size14); shipStatusText.setFont(size14);
GridPane.setRowIndex(cashText, 3); GridPane.setRowIndex(cashText, 3);
cashText.setPrefHeight(17.0); cashText.setPrefHeight(17.0);
cashText.setPrefWidth(209.0); cashText.setPrefWidth(209.0);
@@ -776,7 +777,7 @@ public class TaipanShopGUI {
anchorPane.getChildren().add(gridPane); anchorPane.getChildren().add(gridPane);
Scene root = new Scene(anchorPane, 600, 480); Scene root = new Scene(anchorPane, 600, 480);
stage.setTitle("Shop"); stage.setTitle("Shop");
stage.setResizable(false); stage.setResizable(false);
stage.setScene(root); stage.setScene(root);
@@ -793,17 +794,33 @@ public class TaipanShopGUI {
* *
* @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() {
String location; String location;
switch(player.getLocation()){ switch (player.getLocation()) {
case 1: location = "Hong Kong"; break; case 1:
case 2: location = "Shanghai"; break; location = "Hong Kong";
case 3: location = "Nagasaki"; break; break;
case 4: location = "Saigon"; break; case 2:
case 5: location = "Manila"; break; location = "Shanghai";
case 6: location = "Singapore"; break; break;
case 7: location = "Batavia"; break; case 3:
default: location = "Error"; break; location = "Nagasaki";
break;
case 4:
location = "Saigon";
break;
case 5:
location = "Manila";
break;
case 6:
location = "Singapore";
break;
case 7:
location = "Batavia";
break;
default:
location = "Error";
break;
} }
return location; return location;
} }
@@ -813,21 +830,45 @@ public class TaipanShopGUI {
* *
* @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() {
String shipStatus; String shipStatus;
switch(player.getHP()/10){ switch (player.getHP() / 10) {
case 10: shipStatus = "Mint Condition"; break; case 10:
case 9: shipStatus = "Near Perfect"; break; shipStatus = "Mint Condition";
case 8: shipStatus = "Great"; break; break;
case 7: shipStatus = "Good"; break; case 9:
case 6: shipStatus = "Acceptable"; break; shipStatus = "Near Perfect";
case 5: shipStatus = "Tolerable"; break; break;
case 4: shipStatus = "Needs Repair"; break; case 8:
case 3: shipStatus = "Damaged"; break; shipStatus = "Great";
case 2: shipStatus = "Indangered"; break; break;
case 1: shipStatus = "Near Sinking"; break; case 7:
case 0: shipStatus = "Sinking"; break; shipStatus = "Good";
default: shipStatus = "Invincible"; break; break;
case 6:
shipStatus = "Acceptable";
break;
case 5:
shipStatus = "Tolerable";
break;
case 4:
shipStatus = "Needs Repair";
break;
case 3:
shipStatus = "Damaged";
break;
case 2:
shipStatus = "Indangered";
break;
case 1:
shipStatus = "Near Sinking";
break;
case 0:
shipStatus = "Sinking";
break;
default:
shipStatus = "Invincible";
break;
} }
return shipStatus; return shipStatus;
} }
@@ -835,16 +876,16 @@ public class TaipanShopGUI {
/** /**
* updates the text associated with the user's inventory. * updates the text associated with the user's inventory.
*/ */
public void updateStage(){ public void updateStage() {
firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation())); 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())); 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(); int itemsInWarehouse = player.getwOpium() + player.getwGeneral() + player.getwArms() + player.getwSilk();
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", getStringLocation())); 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 = player.getCargoSpace() - player.getSilkHeld() - player.getOpiumHeld() - player.getGeneralHeld() - player.getArmsHeld() - 10 * player.getGuns();
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{ } 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 ", player.getGuns())); gunsText.setText(String.format("Guns %d\n\n\n\n ", player.getGuns()));
@@ -853,5 +894,5 @@ public class TaipanShopGUI {
cashText.setText(String.format(" Cash: $%,d", player.getMoney())); cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
bankText.setText(String.format("Bank: %d", player.getBank())); bankText.setText(String.format("Bank: %d", player.getBank()));
} }
} }

View File

@@ -1,19 +1,14 @@
import com.sun.org.apache.xpath.internal.operations.Bool; import javafx.geometry.Insets;
import javafx.application.Application;
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.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.util.Random; import java.util.Random;
@@ -41,22 +36,24 @@ public class TravelGUI{
private Boolean stormScene = false; private Boolean stormScene = false;
/**
* 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 TravelGUI(Player player) { public TravelGUI(Player player) {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
public void setPlayer(Player player) { /**
Player playerDummy = new Player(player); * Sets up the graphical part of TravelGUI and includes all logic for the class
this.player = playerDummy; *
} * @param stage sets the stage to which we will execute the scene of the TravelGUI class
* @return stage so that another class can switch to the stage
public Player getPlayer(){ */
Player playerDummy = new Player(player);
return playerDummy;
}
public Stage initializeTravel(Stage stage){ public Stage initializeTravel(Stage stage){
//Updates the stage for the first-time you read it
updateStage(); updateStage();
Font size14 = new Font(14.0); Font size14 = new Font(14.0);
@@ -148,6 +145,7 @@ public class TravelGUI{
flowPane.setPrefHeight(200.0); flowPane.setPrefHeight(200.0);
flowPane.setPrefWidth(200.0); flowPane.setPrefWidth(200.0);
//Creating the continue and quit buttons
quitButton.setPrefHeight(25.0); quitButton.setPrefHeight(25.0);
quitButton.setMnemonicParsing(false); quitButton.setMnemonicParsing(false);
quitButton.setPrefWidth(90.0); quitButton.setPrefWidth(90.0);
@@ -180,7 +178,7 @@ public class TravelGUI{
} }
}); });
//Text input for where the player needs to go. //Text input for where the player needs to go inside of the game world
numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT); numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT);
numberInput.setText("Enter preferred location."); numberInput.setText("Enter preferred location.");
numberInput.setOnKeyPressed(event -> { numberInput.setOnKeyPressed(event -> {
@@ -217,9 +215,6 @@ public class TravelGUI{
quitButton.setVisible(false); quitButton.setVisible(false);
numberInput.setVisible(false); numberInput.setVisible(false);
shopScene = true; shopScene = true;
//TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player);
//taipanShopGUI.initializeShop(stage);
//stage.show();
} }
} }
} }
@@ -295,6 +290,7 @@ public class TravelGUI{
textOut.setText(" Taipan, do you wish to go to:\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?\n After typing the number you want to go to press 'Enter' or 'Z'"); textOut.setText(" Taipan, do you wish to go to:\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?\n After typing the number you want to go to press 'Enter' or 'Z'");
textOut.setFont(size14); textOut.setFont(size14);
//Added all the nodes into a single scene
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle); anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
hBox.getChildren().addAll(warehouseText, wItemsText, wItemSpaceText, locationText); hBox.getChildren().addAll(warehouseText, wItemsText, wItemSpaceText, locationText);
@@ -410,6 +406,11 @@ public class TravelGUI{
} }
} }
/**
* converts the user's location (an integer) to a String, and returns it.
*
* @return location -- the user's location as a string; the actual name of the location.
*/
public String getStringLocation(){ public String getStringLocation(){
String location; String location;
switch(player.getLocation()){ switch(player.getLocation()){
@@ -425,6 +426,11 @@ public class TravelGUI{
return location; return location;
} }
/**
* returns the user's condition based upon their current HP.
*
* @return shipStatus -- a representation of their ship's health in words.
*/
public String shipStatusString(){ public String shipStatusString(){
String shipStatus; String shipStatus;
switch(player.getHP()/10){ switch(player.getHP()/10){
@@ -444,6 +450,9 @@ public class TravelGUI{
return shipStatus; return shipStatus;
} }
/**
* updates the text associated with the user's inventory.
*/
public void updateStage(){ public void updateStage(){
firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation())); 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())); wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));
@@ -462,10 +471,4 @@ public class TravelGUI{
cashText.setText(String.format(" Cash: $%,d", player.getMoney())); cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
bankText.setText(String.format("Bank: %d", player.getBank())); bankText.setText(String.format("Bank: %d", player.getBank()));
} }
public void start(Stage primaryStage) {
primaryStage = initializeTravel(primaryStage);
updateStage();
primaryStage.show();
}
} }

View File

@@ -1,5 +1,3 @@
import javafx.application.Application;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.Scene; import javafx.scene.Scene;
@@ -13,7 +11,6 @@ import javafx.stage.Stage;
/** /**
* A class that makes the GUI for the Warehouse class. * A class that makes the GUI for the Warehouse class.
*
*/ */
public class WarehouseGUI { public class WarehouseGUI {
@@ -48,6 +45,7 @@ public class WarehouseGUI {
private CheckMenuItem arms; private CheckMenuItem arms;
private CheckMenuItem silk; private CheckMenuItem silk;
private CheckMenuItem opium; private CheckMenuItem opium;
/** /**
* A constructor that takes an object of type Player as an argument * A constructor that takes an object of type Player as an argument
* *
@@ -73,7 +71,7 @@ public class WarehouseGUI {
* *
* @return returns a copy of the Player object, player * @return returns a copy of the Player object, player
*/ */
public Player getPlayer(){ public Player getPlayer() {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
return playerDummy; return playerDummy;
} }
@@ -129,7 +127,7 @@ public class WarehouseGUI {
* Creates a label "Hong Kong Warehouse: at the top of the borderpane. * Creates a label "Hong Kong Warehouse: at the top of the borderpane.
* *
*/ */
borderPane.setAlignment(title, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
title.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); title.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
title.setStrokeWidth(0.0); title.setStrokeWidth(0.0);
@@ -154,7 +152,7 @@ public class WarehouseGUI {
* creates an HBox at the center of the borderpane with a width of 200 and height of 100. * creates an HBox at the center of the borderpane with a width of 200 and height of 100.
* *
*/ */
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER); hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0); hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0); hBox.setPrefWidth(200.0);
@@ -168,49 +166,49 @@ public class WarehouseGUI {
withdraw.setText("Withdraw"); withdraw.setText("Withdraw");
updateLabels(); updateLabels();
withdraw.setOnAction(new EventHandler<ActionEvent>() { withdraw.setOnAction(new EventHandler<ActionEvent>() {
/** /**
* Creates a button with text "Deposit" which handles user events. * Creates a button with text "Deposit" which handles user events.
* *
*/ */
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
int withdraw = Integer.parseInt(textIn.getText()); int withdraw = Integer.parseInt(textIn.getText());
updateLabels(); updateLabels();
if(opium.isSelected()){ if (opium.isSelected()) {
if (player.getwOpium() >= withdraw) { if (player.getwOpium() >= withdraw) {
player.setwOpium(player.getwOpium() - withdraw); player.setwOpium(player.getwOpium() - withdraw);
player.setOpiumHeld(player.getOpiumHeld() + withdraw); player.setOpiumHeld(player.getOpiumHeld() + withdraw);
} else { } else {
title.setText("You don't have that much opium stored in the warehouse!"); title.setText("You don't have that much opium stored in the warehouse!");
} }
} }
if(silk.isSelected()){ if (silk.isSelected()) {
if (player.getwSilk() >= withdraw) { if (player.getwSilk() >= withdraw) {
player.setwSilk(player.getwSilk() - withdraw); player.setwSilk(player.getwSilk() - withdraw);
player.setSilkHeld(player.getSilkHeld() + withdraw); player.setSilkHeld(player.getSilkHeld() + withdraw);
} else { } else {
title.setText("You don't have that much silk stored in the warehouse!"); title.setText("You don't have that much silk stored in the warehouse!");
} }
} }
if(arms.isSelected()){ if (arms.isSelected()) {
if (player.getwArms() >= withdraw) { if (player.getwArms() >= withdraw) {
player.setwArms(player.getwArms() - withdraw); player.setwArms(player.getwArms() - withdraw);
player.setArmsHeld(player.getArmsHeld() + withdraw); player.setArmsHeld(player.getArmsHeld() + withdraw);
} else { } else {
title.setText("You don't have that much arms stored in the warehouse!"); title.setText("You don't have that much arms stored in the warehouse!");
} }
} }
if(general.isSelected()){ if (general.isSelected()) {
if (player.getwGeneral() >= withdraw) { if (player.getwGeneral() >= withdraw) {
player.setwGeneral(player.getwGeneral() - withdraw); player.setwGeneral(player.getwGeneral() - withdraw);
player.setGeneralHeld(player.getGeneralHeld() + withdraw); player.setGeneralHeld(player.getGeneralHeld() + withdraw);
} else { } else {
title.setText("You don't have that much general stored in the warehouse!"); title.setText("You don't have that much general stored in the warehouse!");
} }
} }
} }
} }
); );
deposit.setMnemonicParsing(false); deposit.setMnemonicParsing(false);
@@ -406,7 +404,7 @@ public class WarehouseGUI {
borderPane.setRight(vBox1); borderPane.setRight(vBox1);
borderPane.setTop(title); borderPane.setTop(title);
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER); hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0); hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0); hBox.setPrefWidth(200.0);
@@ -435,7 +433,7 @@ public class WarehouseGUI {
opium.setText("Opium"); opium.setText("Opium");
borderPane.setBottom(hBox); borderPane.setBottom(hBox);
borderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER_LEFT); BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER_LEFT);
vBox.setPrefHeight(156.0); vBox.setPrefHeight(156.0);
vBox.setPrefWidth(106.0); vBox.setPrefWidth(106.0);
@@ -476,7 +474,7 @@ public class WarehouseGUI {
generalPlayer.setFont(new Font(18.0)); generalPlayer.setFont(new Font(18.0));
borderPane.setLeft(vBox); borderPane.setLeft(vBox);
borderPane.setAlignment(vBox0, javafx.geometry.Pos.TOP_LEFT); BorderPane.setAlignment(vBox0, javafx.geometry.Pos.TOP_LEFT);
vBox0.setAlignment(javafx.geometry.Pos.CENTER); vBox0.setAlignment(javafx.geometry.Pos.CENTER);
vBox0.setPrefHeight(343.0); vBox0.setPrefHeight(343.0);
vBox0.setPrefWidth(261.0); vBox0.setPrefWidth(261.0);
@@ -551,7 +549,7 @@ public class WarehouseGUI {
* Creates a VBox at the center of the borderpane with a width of 152 and a height of 48. * Creates a VBox at the center of the borderpane with a width of 152 and a height of 48.
* *
*/ */
borderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER);
vBox1.setPrefHeight(48.0); vBox1.setPrefHeight(48.0);
vBox1.setPrefWidth(152.0); vBox1.setPrefWidth(152.0);
@@ -626,7 +624,7 @@ public class WarehouseGUI {
* The purpose of this class is to create a warehouse where the goods * The purpose of this class is to create a warehouse where the goods
* can be safely stored without holing space on the ship! * can be safely stored without holing space on the ship!
*/ */
public void updateLabels(){ public void updateLabels() {
generalPlayer.setText("General: " + player.getGeneralHeld()); generalPlayer.setText("General: " + player.getGeneralHeld());
armsPlayer.setText("Arms: " + player.getArmsHeld()); armsPlayer.setText("Arms: " + player.getArmsHeld());
silkPlayer.setText("Silk: " + player.getSilkHeld()); silkPlayer.setText("Silk: " + player.getSilkHeld());

View File

@@ -1,4 +1,3 @@
import javafx.application.Application;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Pos; import javafx.geometry.Pos;
@@ -11,8 +10,9 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
public class bankGUI{ public class bankGUI {
private Player player; private Player player;
/** /**
* setter method that takes in a Player object as an argument. * setter method that takes in a Player object as an argument.
* *
@@ -22,21 +22,23 @@ public class bankGUI{
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
/** /**
* getter method for obtaining a player object. * getter method for obtaining a player object.
* *
* @return returns player object * @return returns player object
*/ */
public Player getPlayer(){ public Player getPlayer() {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
return playerDummy; return playerDummy;
} }
/** /**
* Class Constructor that takes in a type player as a parameter * Class Constructor that takes in a type player as a parameter
* * <p>
//* @param player object of the class Player * //* @param player object of the class Player
*/ */
public bankGUI(Player player){ public bankGUI(Player player) {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
@@ -110,11 +112,10 @@ public class bankGUI{
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
int withdraw = Integer.parseInt(txtField1.getText()); int withdraw = Integer.parseInt(txtField1.getText());
if(withdraw <= player.getBank()){ if (withdraw <= player.getBank()) {
player.setMoney(withdraw + player.getMoney()); player.setMoney(withdraw + player.getMoney());
player.setBank(player.getBank()-withdraw); player.setBank(player.getBank() - withdraw);
} } else {
else {
l5.setText("Sorry you cannot withdraw that much"); l5.setText("Sorry you cannot withdraw that much");
} }
l2.setText("Current Balance: " + player.getBank()); l2.setText("Current Balance: " + player.getBank());
@@ -132,11 +133,10 @@ public class bankGUI{
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
int deposit = Integer.parseInt(txtField1.getText()); int deposit = Integer.parseInt(txtField1.getText());
if(deposit <= player.getMoney()){ if (deposit <= player.getMoney()) {
player.setBank(deposit + player.getBank()); player.setBank(deposit + player.getBank());
player.setMoney(player.getMoney()-deposit); player.setMoney(player.getMoney() - deposit);
} } else {
else{
l5.setText("Sorry you cannot deposit that much"); l5.setText("Sorry you cannot deposit that much");
} }
l2.setText("Current Balance: " + player.getBank()); l2.setText("Current Balance: " + player.getBank());
@@ -151,13 +151,13 @@ public class bankGUI{
* *
*/ */
b3.setOnAction(new EventHandler<ActionEvent>() { b3.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(player); TaipanShopGUI shopGUI = new TaipanShopGUI(player);
shopGUI.initializeShop(primaryStage); shopGUI.initializeShop(primaryStage);
primaryStage.show(); primaryStage.show();
} }
} }
); );
@@ -167,10 +167,14 @@ public class bankGUI{
*/ */
Scene scene = new Scene(brdr1, 600, 480); Scene scene = new Scene(brdr1, 600, 480);
primaryStage.setScene(scene); primaryStage.setScene(scene);
//primaryStage.show();
return primaryStage; return primaryStage;
} }
/**
* sets scene and runs stage
*
* @param primaryStage the stage in which the scene may be run and switched to
*/
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
bankGUI bank = new bankGUI(player); bankGUI bank = new bankGUI(player);
bank.initializeBank(primaryStage); bank.initializeBank(primaryStage);

View File

@@ -1,4 +1,3 @@
import javafx.application.Application;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Pos; import javafx.geometry.Pos;
@@ -11,35 +10,38 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
public class loanSharkGUI{ public class loanSharkGUI {
private Player player; private Player player;
/**
* setter method that takes in a Player object as an argument. /**
* * setter method that takes in a Player object as an argument.
* @param player object of the class Player *
*/ * @param player object of the class Player
public void setPlayer(Player player) { */
Player playerDummy = new Player(player); public void setPlayer(Player player) {
this.player = playerDummy; Player playerDummy = new Player(player);
} this.player = playerDummy;
/** }
* getter method for obtaining a player object.
* /**
* @return returns player object * getter method for obtaining a player object.
*/ *
public Player getPlayer(){ * @return returns player object
Player playerDummy = new Player(player); */
return playerDummy; public Player getPlayer() {
} Player playerDummy = new Player(player);
/** return playerDummy;
* Class Constructor that takes in a type player as a parameter }
*
//* @param player object of the class Player /**
*/ * Class Constructor that takes in a type player as a parameter
public loanSharkGUI(Player player){ * <p>
Player playerDummy = new Player(player); * //* @param player object of the class Player
this.player = playerDummy; */
} public loanSharkGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public Stage initializeLoanShark(Stage primaryStage) { public Stage initializeLoanShark(Stage primaryStage) {
primaryStage.setTitle("Loan Shark"); primaryStage.setTitle("Loan Shark");
@@ -90,58 +92,53 @@ public class loanSharkGUI{
// Set the event handler when the deposit button is clicked // Set the event handler when the deposit button is clicked
boolean keepGoing = true; boolean keepGoing = true;
b1.setOnAction(new EventHandler<ActionEvent>() { b1.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
int loanAsk = Integer.parseInt(txtField1.getText()); int loanAsk = Integer.parseInt(txtField1.getText());
if (loanAsk <= 2 * (player.getMoney() - player.getDebt()) && loanAsk >= 0) { if (loanAsk <= 2 * (player.getMoney() - player.getDebt()) && loanAsk >= 0) {
player.setDebt(player.getDebt() + loanAsk); player.setDebt(player.getDebt() + loanAsk);
player.setMoney(player.getMoney() + loanAsk); player.setMoney(player.getMoney() + loanAsk);
l4.setText("Current cash: " + player.getMoney()); l4.setText("Current cash: " + player.getMoney());
} } else {
else { l5.setText("Sorry you cannot be loaned that much");
l5.setText("Sorry you cannot be loaned that much"); }
}
l2.setText("Debt: " + player.getDebt()); l2.setText("Debt: " + player.getDebt());
} }
} }
); );
// 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(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
int returnAsk = Integer.parseInt(txtField1.getText()); int returnAsk = Integer.parseInt(txtField1.getText());
if(returnAsk <= player.getDebt() && returnAsk >= 0) { if (returnAsk <= player.getDebt() && returnAsk >= 0) {
player.setDebt(player.getDebt() - returnAsk); player.setDebt(player.getDebt() - returnAsk);
player.setMoney(player.getMoney() - returnAsk); player.setMoney(player.getMoney() - returnAsk);
l4.setText("Current cash: " + player.getMoney()); l4.setText("Current cash: " + player.getMoney());
} else if (returnAsk > player.getDebt()) {
l5.setText("Sorry you cannot be loaned that much");
} else {
l5.setText("Sorry you cannot return a negative amount");
}
l2.setText("Debt: " + player.getDebt());
}
} }
else if(returnAsk > player.getDebt()){
l5.setText("Sorry you cannot be loaned that much");
}
else{
l5.setText("Sorry you cannot return a negative amount");
}
l2.setText("Debt: " + player.getDebt());
}
}
); );
b3.setOnAction(new EventHandler<ActionEvent>() { b3.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(player); TaipanShopGUI shopGUI = new TaipanShopGUI(player);
shopGUI.initializeShop(primaryStage); shopGUI.initializeShop(primaryStage);
primaryStage.show(); primaryStage.show();
} }
} }
); );
//Setting the Scene and displaying it //Setting the Scene and displaying it
Scene scene = new Scene(brdr1, 600, 480); Scene scene = new Scene(brdr1, 600, 480);
primaryStage.setScene(scene); primaryStage.setScene(scene);
@@ -158,14 +155,14 @@ public class loanSharkGUI{
/** /**
* This methods purpose is to loan the player the funds it wants * This methods purpose is to loan the player the funds it wants
* or pay its outstanding debts. The method prompts the user if they * 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 * 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 * 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 * money they have minus the debt id their debt exceeds the cash balance, the loan
* cannot be given. * cannot be given.
*/ */
} }