Merge remote-tracking branch 'origin/master'
This commit is contained in:
1682
.idea/workspace.xml
generated
1682
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -169,13 +169,6 @@ public class LoanSharkGUI extends Player {
|
|||||||
//primaryStage.show();
|
//primaryStage.show();
|
||||||
return primaryStage;
|
return primaryStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void start(Stage primaryStage) {
|
|
||||||
LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
|
|
||||||
loan.initializeLoanShark(primaryStage);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import javafx.scene.layout.HBox;
|
|||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
import logic.RandomEventLogic;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-19
|
* 2019-03-19
|
||||||
@@ -132,33 +131,20 @@ public class RandomEventGUI extends Player {
|
|||||||
* 2: Paying Liu Yuen
|
* 2: Paying Liu Yuen
|
||||||
* 3: Repairing the Ship
|
* 3: Repairing the Ship
|
||||||
*/
|
*/
|
||||||
Random rand = new Random();
|
RandomEventLogic randomEventLogic = new RandomEventLogic(getPlayer());
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
int[] randEvent = randomEventLogic.randEvent();
|
||||||
while(true){
|
eventNumber = randEvent[0];
|
||||||
//Buy Guns
|
itemPrice = randEvent[1];
|
||||||
if (randGenNum == 1) {
|
|
||||||
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
if(eventNumber == 1){
|
||||||
sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?");
|
sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
//Liu Yuen
|
if(eventNumber == 2){
|
||||||
if (randGenNum == 2) {
|
|
||||||
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
|
||||||
sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
|
sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
|
||||||
setAttackingShips(true);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
//Ship Repair
|
if(eventNumber == 3){
|
||||||
if (randGenNum == 3 && getHP() < 100) {
|
|
||||||
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
|
||||||
sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived,\n would be willing to repair your ship for $" + itemPrice);
|
sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived,\n would be willing to repair your ship for $" + itemPrice);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
randGenNum = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
eventNumber = randGenNum;
|
|
||||||
|
|
||||||
if((eventNumber == 1 && getCargoSpace() < 10)){
|
if((eventNumber == 1 && getCargoSpace() < 10)){
|
||||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
||||||
@@ -229,4 +215,6 @@ public class RandomEventGUI extends Player {
|
|||||||
stage.setScene(root);
|
stage.setScene(root);
|
||||||
return stage;
|
return stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,6 @@ import logic.Player;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class TravelGUI extends Player {
|
public class TravelGUI extends Player {
|
||||||
private TaipanShopGUI shop;
|
|
||||||
private Label firm = new Label();
|
private Label firm = new Label();
|
||||||
private Label wItemsText = new Label();
|
private Label wItemsText = new Label();
|
||||||
private Label wItemSpaceText = new Label();
|
private Label wItemSpaceText = new Label();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
@@ -9,10 +10,11 @@ import javafx.scene.layout.VBox;
|
|||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
import logic.WarehouseLogic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-19
|
* 2019-03-19
|
||||||
* Authors:Siddhant, Vikram, Harkamal, Haris, Nathan
|
* Authors:Siddhant and Harkamal
|
||||||
* WarehouseGUI allows the user to store goods in a warehouse in order to have more hold on the ship
|
* WarehouseGUI allows the user to store goods in a warehouse in order to have more hold on the ship
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -90,13 +92,7 @@ public class WarehouseGUI extends Player {
|
|||||||
textField = new TextField();
|
textField = new TextField();
|
||||||
|
|
||||||
//Creating the box for the warehouse GUI
|
//Creating the box for the warehouse GUI
|
||||||
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
|
settingBorderFormat(hBox, vBox);
|
||||||
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
|
||||||
hBox.setPrefHeight(100.0);
|
|
||||||
hBox.setPrefWidth(200.0);
|
|
||||||
hBox.setSpacing(10.0);
|
|
||||||
|
|
||||||
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
|
||||||
vBox.setPrefHeight(200.0);
|
vBox.setPrefHeight(200.0);
|
||||||
vBox.setPrefWidth(100.0);
|
vBox.setPrefWidth(100.0);
|
||||||
|
|
||||||
@@ -137,20 +133,14 @@ public class WarehouseGUI extends Player {
|
|||||||
|
|
||||||
|
|
||||||
//Takes you to the HK warehouse
|
//Takes you to the HK warehouse
|
||||||
borderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
|
borderPane.setAlignment(title, Pos.CENTER);
|
||||||
title.setText("Hong Kong Warehouse");
|
title.setText("Hong Kong Warehouse");
|
||||||
title.setFont(new Font(24.0));
|
title.setFont(new Font(24.0));
|
||||||
title.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
|
title.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
|
||||||
borderPane.setTop(title);
|
borderPane.setTop(title);
|
||||||
|
|
||||||
// Making the BOX again
|
// Making the BOX again
|
||||||
borderPane.setAlignment(hBox0, javafx.geometry.Pos.CENTER);
|
settingBorderFormat(hBox0, vBox0);
|
||||||
hBox0.setAlignment(javafx.geometry.Pos.CENTER);
|
|
||||||
hBox0.setPrefHeight(100.0);
|
|
||||||
hBox0.setPrefWidth(200.0);
|
|
||||||
hBox0.setSpacing(10.0);
|
|
||||||
|
|
||||||
vBox0.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
|
||||||
vBox0.setSpacing(10.0);
|
vBox0.setSpacing(10.0);
|
||||||
|
|
||||||
playerLabel.setText("Player:");
|
playerLabel.setText("Player:");
|
||||||
@@ -171,10 +161,10 @@ public class WarehouseGUI extends Player {
|
|||||||
|
|
||||||
playerOpium.setText("Opium:");
|
playerOpium.setText("Opium:");
|
||||||
|
|
||||||
vBox1.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
vBox1.setAlignment(Pos.CENTER_LEFT);
|
||||||
vBox1.setSpacing(10.0);
|
vBox1.setSpacing(10.0);
|
||||||
|
|
||||||
houseLabel.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
houseLabel.setAlignment(Pos.TOP_CENTER);
|
||||||
houseLabel.setText("Warehouse:");
|
houseLabel.setText("Warehouse:");
|
||||||
houseLabel.setFont(new Font(18.0));
|
houseLabel.setFont(new Font(18.0));
|
||||||
|
|
||||||
@@ -231,85 +221,46 @@ public class WarehouseGUI extends Player {
|
|||||||
taipanShopGUI.initializeShop(stage);
|
taipanShopGUI.initializeShop(stage);
|
||||||
stage.show();
|
stage.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
//Runs when the withdraw button is selected. and removes the amount of the selected good
|
//Runs when the withdraw button is selected. and removes the amount of the selected good
|
||||||
withdrawButton.setOnAction(event -> {
|
withdrawButton.setOnAction(event -> {
|
||||||
try {
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
int withdraw = Integer.parseInt(textField.getText());
|
if(Goods.getSelectedToggle() == generalRadio){
|
||||||
|
title.setText(warehouseLogic.withdraw(textField.getText(),1));
|
||||||
if(withdraw <= 0){
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
//Transfers general amount
|
else if(Goods.getSelectedToggle() == armsRadio){
|
||||||
else if(Goods.getSelectedToggle() == generalRadio && withdraw <= getwGeneral()){
|
title.setText(warehouseLogic.withdraw(textField.getText(),2));
|
||||||
setGeneralHeld(getPlayer().getGeneralHeld()+withdraw);
|
|
||||||
setwGeneral(getPlayer().getwGeneral()-withdraw);
|
|
||||||
}
|
}
|
||||||
//Transfers Arms amount
|
else if(Goods.getSelectedToggle() == silkRadio){
|
||||||
else if(Goods.getSelectedToggle() == armsRadio && withdraw <= getwArms()){
|
title.setText(warehouseLogic.withdraw(textField.getText(),3));
|
||||||
setArmsHeld(getPlayer().getArmsHeld()+withdraw);
|
|
||||||
setwArms(getPlayer().getwArms()-withdraw);
|
|
||||||
}
|
}
|
||||||
//Transfers Silk Amount
|
else if(Goods.getSelectedToggle() == opiumRadio){
|
||||||
else if(Goods.getSelectedToggle() == silkRadio && withdraw <= getwSilk()){
|
title.setText(warehouseLogic.withdraw(textField.getText(),4));
|
||||||
setSilkHeld(getPlayer().getSilkHeld()+withdraw);
|
|
||||||
setwSilk(getPlayer().getwSilk()-withdraw);
|
|
||||||
}
|
|
||||||
//Transfers Opium amount
|
|
||||||
else if(Goods.getSelectedToggle() == opiumRadio && withdraw <= getwOpium()) {
|
|
||||||
setOpiumHeld(getPlayer().getOpiumHeld() + withdraw);
|
|
||||||
setwOpium(getPlayer().getwOpium() - withdraw);
|
|
||||||
}
|
|
||||||
// Ensures a valid value is entered
|
|
||||||
else{
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Button to add a user entered amount to the warehouse
|
//Button to add a user entered amount to the warehouse
|
||||||
depositButton.setOnAction(event -> {
|
depositButton.setOnAction(event -> {
|
||||||
try {
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
int deposit = Integer.parseInt(textField.getText());
|
if(Goods.getSelectedToggle() == generalRadio){
|
||||||
|
title.setText(warehouseLogic.deposit(textField.getText(),1));
|
||||||
if(deposit <= 0){
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
//Transfers general amount
|
else if(Goods.getSelectedToggle() == armsRadio){
|
||||||
else if(Goods.getSelectedToggle() == generalRadio && deposit <= getGeneralHeld()){
|
title.setText(warehouseLogic.deposit(textField.getText(),2));
|
||||||
setGeneralHeld(getPlayer().getGeneralHeld()-deposit);
|
|
||||||
setwGeneral(getPlayer().getwGeneral()+deposit);
|
|
||||||
}
|
}
|
||||||
//Transfers Arms amount
|
else if(Goods.getSelectedToggle() == silkRadio){
|
||||||
else if(Goods.getSelectedToggle() == armsRadio && deposit <= getArmsHeld()){
|
title.setText(warehouseLogic.deposit(textField.getText(),3));
|
||||||
setArmsHeld(getPlayer().getArmsHeld()-deposit);
|
|
||||||
setwArms(getPlayer().getwArms()+deposit);
|
|
||||||
}
|
}
|
||||||
//Transfers Silk amount
|
else if(Goods.getSelectedToggle() == opiumRadio){
|
||||||
else if(Goods.getSelectedToggle() == silkRadio && deposit <= getSilkHeld()){
|
title.setText(warehouseLogic.deposit(textField.getText(),4));
|
||||||
setSilkHeld(getPlayer().getSilkHeld()-deposit);
|
|
||||||
setwSilk(getPlayer().getwSilk()+deposit);
|
|
||||||
}
|
|
||||||
//Transfers Opium amount
|
|
||||||
else if(Goods.getSelectedToggle() == opiumRadio && deposit <= getOpiumHeld()){
|
|
||||||
setOpiumHeld(getPlayer().getOpiumHeld()-deposit);
|
|
||||||
setwOpium(getPlayer().getwOpium()+deposit);
|
|
||||||
}
|
|
||||||
//Checks if the correct value is entered
|
|
||||||
else{
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Create the scene and box of the desired size
|
||||||
//Create the sceene and box of the desired size
|
|
||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
root.getStylesheets().add("styleguide.css");
|
root.getStylesheets().add("styleguide.css");
|
||||||
|
|
||||||
@@ -319,6 +270,15 @@ public class WarehouseGUI extends Player {
|
|||||||
return stage;
|
return stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void settingBorderFormat(HBox hBox, VBox vBox) {
|
||||||
|
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
hBox.setSpacing(10.0);
|
||||||
|
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* As soon as the transfer is made the table of the amount of goods is updated using this method
|
* As soon as the transfer is made the table of the amount of goods is updated using this method
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
package logic;
|
|
||||||
|
|
||||||
public class MainLogic extends Player{
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,45 @@
|
|||||||
package logic;
|
package logic;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class RandomEventLogic extends Player{
|
public class RandomEventLogic extends Player{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public RandomEventLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] randEvent() {
|
||||||
|
Random rand = new Random();
|
||||||
|
int itemPrice;
|
||||||
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
while(true){
|
||||||
|
//Buy Guns
|
||||||
|
if (randGenNum == 1) {
|
||||||
|
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Liu Yuen
|
||||||
|
if (randGenNum == 2) {
|
||||||
|
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
||||||
|
setAttackingShips(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Ship Repair
|
||||||
|
if (randGenNum == 3 && getHP() < 100) {
|
||||||
|
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
randGenNum = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new int[]{randGenNum,itemPrice};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package logic; /**
|
package logic;
|
||||||
|
|
||||||
|
/**
|
||||||
* TaipanShopLogic deals with the computations necessary for the shop such as randomizing prices.
|
* TaipanShopLogic deals with the computations necessary for the shop such as randomizing prices.
|
||||||
*
|
|
||||||
* Author: Vikram Bawa
|
* Author: Vikram Bawa
|
||||||
*/
|
*/
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|||||||
@@ -1,4 +1,94 @@
|
|||||||
package logic;
|
package logic;
|
||||||
|
|
||||||
public class WarehouseLogic extends Player {
|
public class WarehouseLogic extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public WarehouseLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String deposit(String str, int goodsNum) {
|
||||||
|
try {
|
||||||
|
int deposit = Integer.parseInt(str);
|
||||||
|
if(deposit <= 0){
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
//Transfers General amount
|
||||||
|
else if(goodsNum == 1 && deposit <= getGeneralHeld()){
|
||||||
|
setGeneralHeld(getPlayer().getGeneralHeld()-deposit);
|
||||||
|
setwGeneral(getPlayer().getwGeneral()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Transfers Arms amount
|
||||||
|
else if(goodsNum == 2 && deposit <= getArmsHeld()){
|
||||||
|
setArmsHeld(getPlayer().getArmsHeld()-deposit);
|
||||||
|
setwArms(getPlayer().getwArms()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Transfers Silk amount
|
||||||
|
else if(goodsNum == 3 && deposit <= getSilkHeld()){
|
||||||
|
setSilkHeld(getPlayer().getSilkHeld()-deposit);
|
||||||
|
setwSilk(getPlayer().getwSilk()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Transfers Opium amount
|
||||||
|
else if(goodsNum == 4 && deposit <= getOpiumHeld()){
|
||||||
|
setOpiumHeld(getPlayer().getOpiumHeld()-deposit);
|
||||||
|
setwOpium(getPlayer().getwOpium()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Checks if the correct value is entered
|
||||||
|
else{
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String withdraw(String str, int goodsNum) {
|
||||||
|
try {
|
||||||
|
int withdraw = Integer.parseInt(str);
|
||||||
|
if(withdraw <= 0){
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
//Transfers general amount
|
||||||
|
else if(goodsNum == 1 && withdraw <= getwGeneral()){
|
||||||
|
setGeneralHeld(getPlayer().getGeneralHeld()+withdraw);
|
||||||
|
setwGeneral(getPlayer().getwGeneral()-withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
//Transfers Arms amount
|
||||||
|
else if(goodsNum == 2 && withdraw <= getwArms()){
|
||||||
|
setArmsHeld(getPlayer().getArmsHeld()+withdraw);
|
||||||
|
setwArms(getPlayer().getwArms()-withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
//Transfers Silk Amount
|
||||||
|
else if(goodsNum == 3 && withdraw <= getwSilk()){
|
||||||
|
setSilkHeld(getPlayer().getSilkHeld()+withdraw);
|
||||||
|
setwSilk(getPlayer().getwSilk()-withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
//Transfers Opium amount
|
||||||
|
else if(goodsNum == 4 && withdraw <= getwOpium()) {
|
||||||
|
setOpiumHeld(getPlayer().getOpiumHeld() + withdraw);
|
||||||
|
setwOpium(getPlayer().getwOpium() - withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
// Ensures a valid value is entered
|
||||||
|
else{
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1,6 +1,7 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
import logic.WarehouseLogic;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@@ -20,80 +21,29 @@ public class WarehouseText extends Player {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void addAmount() {
|
public void addAmount() {
|
||||||
boolean askGood = false;
|
|
||||||
String amount;
|
|
||||||
int finalAmount = 0;
|
|
||||||
System.out.println("Please enter the amount of the good you would like to ADD.");
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
amount = keyboard.nextLine();//Asks the user for the amount of the good they would like to add
|
|
||||||
|
System.out.println("Please enter the amount of the good you would like to deposit.");
|
||||||
|
String amount = keyboard.nextLine();
|
||||||
|
//Asks the user for the amount of the good they would like to add
|
||||||
/*The try function ensures that the program does not crash
|
/*The try function ensures that the program does not crash
|
||||||
due to any errors while giving the program an incorrect input*/
|
due to any errors while giving the program an incorrect input*/
|
||||||
try {
|
System.out.println("Please enter a good to transfer O, S, A, G :");
|
||||||
//The if statement checks that you have enough resources to make the transfer
|
String good = keyboard.nextLine();
|
||||||
if (Integer.parseInt(amount) <= getOpiumHeld() || Integer.parseInt(amount) <= getSilkHeld() || Integer.parseInt(amount) <= getGeneralHeld() || Integer.parseInt(amount) <= getArmsHeld()) {
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
finalAmount = Integer.parseInt(amount);
|
if(good.equalsIgnoreCase("g")){
|
||||||
askGood = true;
|
System.out.println(warehouseLogic.deposit(amount,1));
|
||||||
}
|
}
|
||||||
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
|
else if(good.equalsIgnoreCase("a")){
|
||||||
else {
|
System.out.println(warehouseLogic.deposit(amount,2));
|
||||||
System.out.println("Nice try but you don't have any items of that quantity!");
|
|
||||||
askGood = false;
|
|
||||||
}
|
}
|
||||||
//Ensures that goods are only transferred if they have the specified amount
|
else if(good.equalsIgnoreCase("s")){
|
||||||
//The user is prompted to enter which good they want to transfer
|
System.out.println(warehouseLogic.deposit(amount,3));
|
||||||
if (askGood == true) {
|
|
||||||
String good;
|
|
||||||
System.out.println("Please enter a good to transfer O, S, G, A :");
|
|
||||||
good = keyboard.nextLine();
|
|
||||||
int held = 0;
|
|
||||||
//The following set of loops check to see which good the user has selected and makes the transfer
|
|
||||||
if (Integer.parseInt(amount) > 0) {
|
|
||||||
if (good.equalsIgnoreCase("O")) {
|
|
||||||
if (getOpiumHeld() >= Integer.parseInt(amount)) {
|
|
||||||
setwOpium(getwOpium() + finalAmount);
|
|
||||||
held = getOpiumHeld();
|
|
||||||
setOpiumHeld(held - finalAmount);
|
|
||||||
System.out.println(getOpiumHeld());
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much opium!");
|
|
||||||
}
|
}
|
||||||
} else if (good.equalsIgnoreCase("S")) {
|
else if(good.equalsIgnoreCase("o")){
|
||||||
if (getSilkHeld() >= Integer.parseInt(amount)) {
|
System.out.println(warehouseLogic.deposit(amount,4));
|
||||||
setwSilk(getwSilk() + finalAmount);
|
|
||||||
held = getSilkHeld();
|
|
||||||
setSilkHeld(held - finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much silk!");
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("G")) {
|
|
||||||
if (getGeneralHeld() >= Integer.parseInt(amount)) {
|
|
||||||
setwGeneral(getwGeneral() + finalAmount);
|
|
||||||
held = getGeneralHeld();
|
|
||||||
setGeneralHeld(held - finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much general cargo!");
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("A")) {
|
|
||||||
if (getArmsHeld() >= Integer.parseInt(amount)) {
|
|
||||||
setwArms(getwArms() + finalAmount);
|
|
||||||
held = getArmsHeld();
|
|
||||||
setArmsHeld(held - finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much Arms!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Ensures no negative amounts are entered
|
|
||||||
else {
|
|
||||||
System.out.println("Sorry this transfer cannot be made");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Wait, that's not a valid input please try again");
|
|
||||||
}
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,82 +56,28 @@ public class WarehouseText extends Player {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public void removeAmount() {
|
public void removeAmount() {
|
||||||
String amount;
|
|
||||||
boolean askGood = false;
|
|
||||||
int finalAmount = 0;
|
|
||||||
System.out.println("Please enter the amount of the good you would like to REMOVE");
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
//Prompts the user for the amount they would like to remove
|
System.out.println("Please enter the amount of the good you would like to withdraw.");
|
||||||
amount = keyboard.nextLine();
|
String amount = keyboard.nextLine();
|
||||||
//The if statement checks that you have enough resources to make the transfer
|
//Asks the user for the amount of the good they would like to withdraw
|
||||||
try {
|
/*The try function ensures that the program does not crash
|
||||||
//The if statement checks that you have enough resources to make the transfer
|
due to any errors while giving the program an incorrect input*/
|
||||||
if (Integer.parseInt(amount) <= getwOpium() || Integer.parseInt(amount) <= getwSilk() || Integer.parseInt(amount) <= getwGeneral() || Integer.parseInt(amount) <= getwArms()) {
|
System.out.println("Please enter a good to withdraw (O)pium, (S)ilk, (A)rms, (G)eneral:");
|
||||||
finalAmount = Integer.parseInt(amount);
|
String good = keyboard.nextLine();
|
||||||
askGood = true;
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
|
if(good.equalsIgnoreCase("g")){
|
||||||
|
System.out.println(warehouseLogic.withdraw(amount,1));
|
||||||
}
|
}
|
||||||
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
|
else if(good.equalsIgnoreCase("a")){
|
||||||
else {
|
System.out.println(warehouseLogic.withdraw(amount,2));
|
||||||
System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
|
|
||||||
askGood = false;
|
|
||||||
}
|
}
|
||||||
|
else if(good.equalsIgnoreCase("s")){
|
||||||
//Ensures that goods are only transferred if they have the specified amount
|
System.out.println(warehouseLogic.withdraw(amount,3));
|
||||||
//The user is prompted to enter which good they want to transfer
|
|
||||||
|
|
||||||
if (askGood == true) {
|
|
||||||
String good;
|
|
||||||
System.out.println("Please enter a good to transfer O, S, G, A :");
|
|
||||||
good = keyboard.nextLine();
|
|
||||||
int held = 0;
|
|
||||||
//The following set of loops check to see which good the user has selected and makes the transfer and amount > 0
|
|
||||||
if (Integer.parseInt(amount) > 0) {
|
|
||||||
if (good.equalsIgnoreCase("O")) {
|
|
||||||
if (getwOpium() >= Integer.parseInt(amount)) {
|
|
||||||
setwOpium(getwOpium() - Integer.parseInt(amount));
|
|
||||||
held = getOpiumHeld();
|
|
||||||
setOpiumHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much opium stored in the warehouse!");
|
|
||||||
}
|
}
|
||||||
} else if (good.equalsIgnoreCase("S")) {
|
else if(good.equalsIgnoreCase("o")){
|
||||||
if (getwSilk() >= Integer.parseInt(amount)) {
|
System.out.println(warehouseLogic.withdraw(amount,4));
|
||||||
setwSilk(getwSilk() - Integer.parseInt(amount));
|
|
||||||
held = getSilkHeld();
|
|
||||||
setSilkHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much silk stored in the warehouse!");
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("G")) {
|
|
||||||
if (getwGeneral() >= Integer.parseInt(amount)) {
|
|
||||||
setwGeneral(getwGeneral() - Integer.parseInt(amount));
|
|
||||||
held = getGeneralHeld();
|
|
||||||
setGeneralHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much general cargo stored in the warehouse!");
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("A")) {
|
|
||||||
if (getwArms() >= Integer.parseInt(amount)) {
|
|
||||||
setwArms(getwArms() - Integer.parseInt(amount));
|
|
||||||
held = getArmsHeld();
|
|
||||||
setArmsHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much arms stored in the warehouse!");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Ensures the value entered is positive
|
|
||||||
else {
|
|
||||||
System.out.println("Sorry this transfer cannot be made");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
|
|
||||||
catch (Exception e){
|
|
||||||
System.out.println("Wait, that's not a valid input please try again");
|
|
||||||
}
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,26 +102,23 @@ public class WarehouseText extends Player {
|
|||||||
boolean keepGoing = true;
|
boolean keepGoing = true;
|
||||||
while (keepGoing) {
|
while (keepGoing) {
|
||||||
this.showWarehouse();
|
this.showWarehouse();
|
||||||
String input = " ";
|
System.out.println("Would you like to (D)eposit or (W)ithdraw resources? ");
|
||||||
System.out.println("Would you like to add(A) or remove(R) resources? ");
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
input = keyboard.next();
|
String input = keyboard.next();
|
||||||
if (input.equalsIgnoreCase("R")) {
|
if (input.equalsIgnoreCase("D")) {
|
||||||
this.removeAmount();
|
this.removeAmount();
|
||||||
this.showWarehouse();
|
this.showWarehouse();
|
||||||
} else if (input.equalsIgnoreCase("A")) {
|
} else if (input.equalsIgnoreCase("W")) {
|
||||||
this.addAmount();
|
this.addAmount();
|
||||||
this.showWarehouse();
|
this.showWarehouse();
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
System.out.println("Don't waste the warehouse's time, try again later with a valid input");
|
System.out.println("Don't waste the warehouse's time, try again later with a valid input");
|
||||||
}
|
}
|
||||||
|
|
||||||
String check;
|
|
||||||
//Check to see if the player wants to continue in the warehouse or they are done
|
//Check to see if the player wants to continue in the warehouse or they are done
|
||||||
System.out.println("Would you like to do any other business? Y / N?");
|
System.out.println("Would you like to do any other business? Y / N?");
|
||||||
check = keyboard.nextLine();
|
String check = keyboard.nextLine();
|
||||||
check = keyboard.nextLine();
|
check = keyboard.nextLine();
|
||||||
|
|
||||||
if (check.equalsIgnoreCase("Y")) {
|
if (check.equalsIgnoreCase("Y")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user