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

View File

@@ -1,4 +1,3 @@
import javafx.application.Application;
import javafx.stage.Stage;
@@ -11,7 +10,7 @@ public class MainGUI extends Application {
* @return returns a copy of the object player
*/
public Player getPlayer(){
public Player getPlayer() {
Player copy = new Player(player);
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
*/
public void shop(TaipanShopGUI shop){
public void shop(TaipanShopGUI shop) {
shop.setPlayer(player);
shop.shop();
player = shop.getPlayer();
@@ -31,6 +30,7 @@ public class MainGUI extends Application {
/**
* 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.
*
* @param args Just the console for the player to look at.
*/
public static void main(String[] args) {

View File

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

View File

@@ -357,7 +357,7 @@ public class ShipWarfareGUI {
BorderPane.setBottom(hBox);
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.setPrefHeight(200.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
*/
public void setFirm (String name) {
public void setFirm(String name) {
if (name.length() <= 22) {
player.setName(name);
}
else{
} else {
player.setName("Taipan");
}
}
/*
**
**
* Copy constructor.
* @param player object of the class Player
*/
public StartGUI(Player player)
{
public StartGUI(Player player) {
Player playerTemp = new Player(player);
this.player = playerTemp;
}
@@ -75,13 +73,13 @@ public class StartGUI {
* @param stage object of type Stage
* @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.
*
*/
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);

View File

@@ -1,17 +1,18 @@
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
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.text.Font;
import javafx.stage.Stage;
import java.util.Random;
public class TaipanShopGUI {
@@ -36,7 +37,7 @@ public class TaipanShopGUI {
private Button cargoButton = new Button();
private Button opiumButton = new Button();
private Button silkButton = new Button();
private Button armsButton = new Button();
private Button armsButton = new Button();
private Button generalButton = new Button();
private TextField numberInput = new TextField();
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.
*/
public TaipanShopGUI(Player player){
public TaipanShopGUI(Player player) {
Player playerDummy = new Player(player);
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).
*/
public void retire(Stage stage){
public void retire(Stage stage) {
player.setRetire(true);
GameEndGUI gameEndGUI = new GameEndGUI(player);
gameEndGUI.initializeGameEndGUI(stage);
@@ -79,7 +80,7 @@ public class TaipanShopGUI {
*
* @return playerDummy -- playerDummy is a copy of the player instance variable.
*/
public Player getPlayer(){
public Player getPlayer() {
Player playerDummy = new Player(player);
return playerDummy;
}
@@ -99,7 +100,7 @@ public class TaipanShopGUI {
* @param opiumPrice -- what the instance variable opiumPrice should be changed to.
*/
public void setOpiumPrice(int opiumPrice) {
if(opiumPrice > 0){
if (opiumPrice > 0) {
this.opiumPrice = opiumPrice;
}
}
@@ -119,7 +120,7 @@ public class TaipanShopGUI {
* @param silkPrice -- what the instance variable silkPrice should be changed to.
*/
public void setSilkPrice(int silkPrice) {
if(silkPrice > 0){
if (silkPrice > 0) {
this.silkPrice = silkPrice;
}
}
@@ -139,7 +140,7 @@ public class TaipanShopGUI {
* @param armsPrice -- what the instance variable armsPrice should be changed to.
*/
public void setArmsPrice(int armsPrice) {
if(armsPrice > 0){
if (armsPrice > 0) {
this.armsPrice = armsPrice;
}
}
@@ -159,7 +160,7 @@ public class TaipanShopGUI {
* @param generalPrice -- what the instance variable generalPrice should be changed to.
*/
public void setGeneralPrice(int generalPrice) {
if(generalPrice > 0){
if (generalPrice > 0) {
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.
*/
public void updatePrices(){
public void updatePrices() {
String s = "\t" + player.getName() + ", the price of ";
double value = 80*Math.random();
double value = 80 * Math.random();
Random rand = new Random();
opiumPrice = (rand.nextInt(201) + 60)*100;
silkPrice = (rand.nextInt(201) + 60)*10;
armsPrice = (rand.nextInt(21) + 6)*10;
opiumPrice = (rand.nextInt(201) + 60) * 100;
silkPrice = (rand.nextInt(201) + 60) * 10;
armsPrice = (rand.nextInt(21) + 6) * 10;
generalPrice = 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){
if (value < 8) {
if (value < 2) {
if (value < 1) {
opiumPrice /= 5;
textOut.setText(s + "Opium has dropped to " + opiumPrice +"!!!\n"+textOut.getText());
}else{
textOut.setText(s + "Opium has dropped to " + opiumPrice + "!!!\n" + textOut.getText());
} else {
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){
if(value < 3){
} else if (value < 4) {
if (value < 3) {
silkPrice /= 5;
textOut.setText(s + "Silk has dropped to " + silkPrice +"!!!\n"+textOut.getText());
}else{
textOut.setText(s + "Silk has dropped to " + silkPrice + "!!!\n" + textOut.getText());
} else {
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){
if(value < 3){
} else if (value < 6) {
if (value < 3) {
armsPrice /= 5;
textOut.setText(s + "Arms has dropped to " + armsPrice +"!!!\n"+textOut.getText());
}else{
textOut.setText(s + "Arms has dropped to " + armsPrice + "!!!\n" + textOut.getText());
} else {
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{
if(value < 7){
} else {
if (value < 7) {
generalPrice = 1;
textOut.setText(s + "General Cargo has dropped to 1!!!\n"+textOut.getText());
}else{
textOut.setText(s + "General Cargo has dropped to 1!!!\n" + textOut.getText());
} else {
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.
*/
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()));
}
@@ -266,7 +267,7 @@ public class TaipanShopGUI {
generalButton.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);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -279,7 +280,7 @@ public class TaipanShopGUI {
generalButton.setVisible(false);
armsButton.setVisible(false);
retireButton.setVisible(false);
}else if(player.getLocation() == 1){
} else if (player.getLocation() == 1) {
buyButton.setVisible(true);
sellButton.setVisible(true);
bankButton.setVisible(true);
@@ -293,7 +294,7 @@ public class TaipanShopGUI {
armsButton.setVisible(false);
retireButton.setVisible(true);
}
} else if(state.equals("input")){
} else if (state.equals("input")) {
buyButton.setVisible(false);
sellButton.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.
*/
public void shop(){
public void shop() {
String originalDialogue = textOut.getText();
int num = Integer.parseInt(numberInput.getText().replace(" ", ""));
if(buyButton.getText().contains(".")){
if(opiumButton.getText().contains(".") && num <= player.getMoney() / opiumPrice && num >= 0){
player.setMoney(player.getMoney()-num*opiumPrice);
player.setOpiumHeld(player.getOpiumHeld()+num);
}else if (num >= 0 && opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.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() / silkPrice && num >= 0){
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney()-num * silkPrice);
}else if (num >= 0 && silkButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.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() / armsPrice && num >= 0){
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
}else if(num >= 0 && armsButton.getText().contains(".")){
textOut.setText(originalDialogue+"\n\t"+ player.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() / generalPrice && num >= 0){
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
}else if(num >= 0 && generalButton.getText().contains(".")){
textOut.setText(originalDialogue+"\n\t"+ player.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?");
if (buyButton.getText().contains(".")) {
if (opiumButton.getText().contains(".") && num <= player.getMoney() / opiumPrice && num >= 0) {
player.setMoney(player.getMoney() - num * opiumPrice);
player.setOpiumHeld(player.getOpiumHeld() + num);
} else if (num >= 0 && opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld() + num);
player.setMoney(player.getMoney() - num * silkPrice);
} else if (num >= 0 && silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld() + num);
player.setMoney(player.getMoney() - num * armsPrice);
} else if (num >= 0 && armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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() / generalPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld() + num);
player.setMoney(player.getMoney() - num * generalPrice);
} else if (num >= 0 && generalButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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?");
}
}else if(sellButton.getText().contains(".")){
if(opiumButton.getText().contains(".") && num <= player.getOpiumHeld() && num >= 0){
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
}else if (num >= 0 && opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.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*silkPrice);
}else if (num >= 0 && silkButton.getText().contains(".")) {
textOut.setText(originalDialogue+"\n\t"+ player.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*armsPrice);
}else if(num >= 0 && armsButton.getText().contains(".")){
textOut.setText(originalDialogue+"\n\t"+ player.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*generalPrice);
}else if(num >= 0 && generalButton.getText().contains(".")){
textOut.setText(originalDialogue+"\n\t"+ player.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?");
} else if (sellButton.getText().contains(".")) {
if (opiumButton.getText().contains(".") && num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld() - num);
player.setMoney(player.getMoney() + num * opiumPrice);
} else if (num >= 0 && opiumButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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 * silkPrice);
} else if (num >= 0 && silkButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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 * armsPrice);
} else if (num >= 0 && armsButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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 * generalPrice);
} else if (num >= 0 && generalButton.getText().contains(".")) {
textOut.setText(originalDialogue + "\n\t" + player.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?");
}
}
}
@@ -383,7 +384,7 @@ public class TaipanShopGUI {
*
* @param stage
*/
public void initializeShop(Stage stage){
public void initializeShop(Stage stage) {
Font size14 = new Font(14.0);
Rectangle dialogueRectangle = new Rectangle();
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
@@ -484,7 +485,7 @@ public class TaipanShopGUI {
buttonSetup("shop");
buyButton.setText("Buy.");
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");
sellButton.setText("Sell.");
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);
@@ -587,12 +588,12 @@ public class TaipanShopGUI {
opiumButton.setText("Opium.");
defaultTextOut();
String extraText;
if(buyButton.getText().contains(".")){
extraText = String.format(" (You can afford %d)", player.getMoney()/opiumPrice);
}else{
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / opiumPrice);
} else {
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.");
defaultTextOut();
String extraText;
if(buyButton.getText().contains(".")){
extraText = String.format(" (You can afford %d)", player.getMoney()/silkPrice);
}else{
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / silkPrice);
} else {
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.");
defaultTextOut();
String extraText;
if(buyButton.getText().contains(".")){
extraText = String.format(" (You can afford %d)", player.getMoney()/armsPrice);
}else{
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / armsPrice);
} else {
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");
@@ -653,12 +654,12 @@ public class TaipanShopGUI {
generalButton.setText("General.");
defaultTextOut();
String extraText;
if(buyButton.getText().contains(".")){
extraText = String.format(" (You can afford %d)", player.getMoney()/generalPrice);
}else{
if (buyButton.getText().contains(".")) {
extraText = String.format(" (You can afford %d)", player.getMoney() / generalPrice);
} else {
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) {
boolean exit = true;
defaultTextOut();
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
while(true){
if(!textOut.getText().contains("You entered an invalid input!")&& !exit){
textOut.setText(textOut.getText()+"\n\n\tYou entered an invalid input! Please try again.");
if (event.getCode().equals(KeyCode.ENTER) || event.getCode().equals(KeyCode.Z)) {
while (true) {
if (!textOut.getText().contains("You entered an invalid input!") && !exit) {
textOut.setText(textOut.getText() + "\n\n\tYou entered an invalid input! Please try again.");
break;
}
try{
try {
shop();
}catch(Exception e){
} catch (Exception e) {
exit = false;
}
if(exit){
if (exit) {
break;
}
}
updateStage();
buttonSetup("reset");
}
}
@@ -714,13 +715,13 @@ public class TaipanShopGUI {
wItemSpaceText.setPrefHeight(108.0);
wItemSpaceText.setPrefWidth(215.0);
wItemSpaceText.setFont(size14);
locationText.setAlignment(Pos.BOTTOM_CENTER);
locationText.setPrefHeight(106.0);
locationText.setPrefWidth(175.0);
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
locationText.setFont(size14);
inventoryText.setAlignment(Pos.CENTER);
inventoryText.setFont(size14);
@@ -733,14 +734,14 @@ public class TaipanShopGUI {
gunsText.setPrefWidth(212.0);
gunsText.setAlignment(Pos.CENTER_LEFT);
gunsText.setFont(size14);
shipStatusText.setAlignment(Pos.TOP_CENTER);
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
shipStatusText.setPrefHeight(110.0);
shipStatusText.setPrefWidth(180.0);
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
shipStatusText.setFont(size14);
GridPane.setRowIndex(cashText, 3);
cashText.setPrefHeight(17.0);
cashText.setPrefWidth(209.0);
@@ -776,7 +777,7 @@ public class TaipanShopGUI {
anchorPane.getChildren().add(gridPane);
Scene root = new Scene(anchorPane, 600, 480);
stage.setTitle("Shop");
stage.setResizable(false);
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.
*/
public String getStringLocation(){
public String getStringLocation() {
String location;
switch(player.getLocation()){
case 1: location = "Hong Kong"; break;
case 2: location = "Shanghai"; break;
case 3: 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;
switch (player.getLocation()) {
case 1:
location = "Hong Kong";
break;
case 2:
location = "Shanghai";
break;
case 3:
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;
}
@@ -813,21 +830,45 @@ public class TaipanShopGUI {
*
* @return shipStatus -- a representation of their ship's health in words.
*/
public String shipStatusString(){
public String shipStatusString() {
String shipStatus;
switch(player.getHP()/10){
case 10: shipStatus = "Mint Condition"; break;
case 9: shipStatus = "Near Perfect"; break;
case 8: shipStatus = "Great"; break;
case 7: shipStatus = "Good"; 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;
switch (player.getHP() / 10) {
case 10:
shipStatus = "Mint Condition";
break;
case 9:
shipStatus = "Near Perfect";
break;
case 8:
shipStatus = "Great";
break;
case 7:
shipStatus = "Good";
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;
}
@@ -835,16 +876,16 @@ public class TaipanShopGUI {
/**
* 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()));
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();
wItemSpaceText.setText(String.format("\n\t\tIn use:\n\t\t %d \n\t\tVacant:\n\t\t %d", itemsInWarehouse, (10000-itemsInWarehouse)));
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)));
locationText.setText(String.format("Location\n%s", getStringLocation()));
int itemsInInventory = player.getCargoSpace()-player.getSilkHeld()-player.getOpiumHeld()-player.getGeneralHeld()-player.getArmsHeld()-10*player.getGuns();
if(itemsInInventory < 0){
int itemsInInventory = player.getCargoSpace() - player.getSilkHeld() - player.getOpiumHeld() - player.getGeneralHeld() - player.getArmsHeld() - 10 * player.getGuns();
if (itemsInInventory < 0) {
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));
}
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()));
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.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
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.text.Font;
import javafx.stage.Stage;
import java.util.Random;
@@ -41,22 +36,24 @@ public class TravelGUI{
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) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public void setPlayer(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public Player getPlayer(){
Player playerDummy = new Player(player);
return playerDummy;
}
/**
* Sets up the graphical part of TravelGUI and includes all logic for the class
*
* @param stage sets the stage to which we will execute the scene of the TravelGUI class
* @return stage so that another class can switch to the stage
*/
public Stage initializeTravel(Stage stage){
//Updates the stage for the first-time you read it
updateStage();
Font size14 = new Font(14.0);
@@ -148,6 +145,7 @@ public class TravelGUI{
flowPane.setPrefHeight(200.0);
flowPane.setPrefWidth(200.0);
//Creating the continue and quit buttons
quitButton.setPrefHeight(25.0);
quitButton.setMnemonicParsing(false);
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.setText("Enter preferred location.");
numberInput.setOnKeyPressed(event -> {
@@ -217,9 +215,6 @@ public class TravelGUI{
quitButton.setVisible(false);
numberInput.setVisible(false);
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.setFont(size14);
//Added all the nodes into a single scene
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
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(){
String location;
switch(player.getLocation()){
@@ -425,6 +426,11 @@ public class TravelGUI{
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(){
String shipStatus;
switch(player.getHP()/10){
@@ -444,6 +450,9 @@ public class TravelGUI{
return shipStatus;
}
/**
* 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()));
@@ -462,10 +471,4 @@ public class TravelGUI{
cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
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.EventHandler;
import javafx.scene.Scene;
@@ -13,7 +11,6 @@ import javafx.stage.Stage;
/**
* A class that makes the GUI for the Warehouse class.
*
*/
public class WarehouseGUI {
@@ -48,6 +45,7 @@ public class WarehouseGUI {
private CheckMenuItem arms;
private CheckMenuItem silk;
private CheckMenuItem opium;
/**
* 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
*/
public Player getPlayer(){
public Player getPlayer() {
Player playerDummy = new Player(player);
return playerDummy;
}
@@ -129,7 +127,7 @@ public class WarehouseGUI {
* 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.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.
*
*/
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
@@ -168,49 +166,49 @@ public class WarehouseGUI {
withdraw.setText("Withdraw");
updateLabels();
withdraw.setOnAction(new EventHandler<ActionEvent>() {
/**
* Creates a button with text "Deposit" which handles user events.
*
*/
@Override
public void handle(ActionEvent event) {
/**
* Creates a button with text "Deposit" which handles user events.
*
*/
@Override
public void handle(ActionEvent event) {
int withdraw = Integer.parseInt(textIn.getText());
updateLabels();
if(opium.isSelected()){
if (player.getwOpium() >= withdraw) {
player.setwOpium(player.getwOpium() - withdraw);
player.setOpiumHeld(player.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);
} 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);
} 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);
} else {
title.setText("You don't have that much general stored in the warehouse!");
}
}
}
}
int withdraw = Integer.parseInt(textIn.getText());
updateLabels();
if (opium.isSelected()) {
if (player.getwOpium() >= withdraw) {
player.setwOpium(player.getwOpium() - withdraw);
player.setOpiumHeld(player.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);
} 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);
} 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);
} else {
title.setText("You don't have that much general stored in the warehouse!");
}
}
}
}
);
deposit.setMnemonicParsing(false);
@@ -406,7 +404,7 @@ public class WarehouseGUI {
borderPane.setRight(vBox1);
borderPane.setTop(title);
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
@@ -435,7 +433,7 @@ public class WarehouseGUI {
opium.setText("Opium");
borderPane.setBottom(hBox);
borderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER_LEFT);
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER_LEFT);
vBox.setPrefHeight(156.0);
vBox.setPrefWidth(106.0);
@@ -476,7 +474,7 @@ public class WarehouseGUI {
generalPlayer.setFont(new Font(18.0));
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.setPrefHeight(343.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.
*
*/
borderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER);
BorderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER);
vBox1.setPrefHeight(48.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
* can be safely stored without holing space on the ship!
*/
public void updateLabels(){
public void updateLabels() {
generalPlayer.setText("General: " + player.getGeneralHeld());
armsPlayer.setText("Arms: " + player.getArmsHeld());
silkPlayer.setText("Silk: " + player.getSilkHeld());

View File

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

View File

@@ -1,4 +1,3 @@
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
@@ -11,35 +10,38 @@ 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;
}
/**
* Class Constructor that takes in a type player as a parameter
*
//* @param player object of the class Player
*/
public loanSharkGUI(Player player){
Player playerDummy = new Player(player);
this.player = playerDummy;
}
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;
}
/**
* Class Constructor that takes in a type player as a parameter
* <p>
* //* @param player object of the class Player
*/
public loanSharkGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public Stage initializeLoanShark(Stage primaryStage) {
primaryStage.setTitle("Loan Shark");
@@ -90,58 +92,53 @@ public class loanSharkGUI{
// Set the event handler when the deposit button is clicked
boolean keepGoing = true;
b1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
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());
}
else {
l5.setText("Sorry you cannot be loaned that much");
}
@Override
public void handle(ActionEvent event) {
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());
} else {
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
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int returnAsk = Integer.parseInt(txtField1.getText());
if(returnAsk <= player.getDebt() && returnAsk >= 0) {
player.setDebt(player.getDebt() - returnAsk);
player.setMoney(player.getMoney() - returnAsk);
l4.setText("Current cash: " + player.getMoney());
@Override
public void handle(ActionEvent event) {
int returnAsk = Integer.parseInt(txtField1.getText());
if (returnAsk <= player.getDebt() && returnAsk >= 0) {
player.setDebt(player.getDebt() - returnAsk);
player.setMoney(player.getMoney() - returnAsk);
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>() {
@Override
public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(player);
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
}
@Override
public void handle(ActionEvent event) {
TaipanShopGUI shopGUI = new TaipanShopGUI(player);
shopGUI.initializeShop(primaryStage);
primaryStage.show();
}
}
);
//Setting the Scene and displaying it
Scene scene = new Scene(brdr1, 600, 480);
primaryStage.setScene(scene);
@@ -158,14 +155,14 @@ public class loanSharkGUI{
/**
* 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.
*/
}
* 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.
*/
}