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();
|
||||
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.stage.Stage;
|
||||
import logic.Player;
|
||||
|
||||
import java.util.Random;
|
||||
import logic.RandomEventLogic;
|
||||
|
||||
/**
|
||||
* 2019-03-19
|
||||
@@ -132,33 +131,20 @@ public class RandomEventGUI extends Player {
|
||||
* 2: Paying Liu Yuen
|
||||
* 3: Repairing the Ship
|
||||
*/
|
||||
Random rand = new Random();
|
||||
int randGenNum = rand.nextInt(3) + 1;
|
||||
while(true){
|
||||
//Buy Guns
|
||||
if (randGenNum == 1) {
|
||||
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
||||
RandomEventLogic randomEventLogic = new RandomEventLogic(getPlayer());
|
||||
int[] randEvent = randomEventLogic.randEvent();
|
||||
eventNumber = randEvent[0];
|
||||
itemPrice = randEvent[1];
|
||||
|
||||
if(eventNumber == 1){
|
||||
sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?");
|
||||
break;
|
||||
}
|
||||
//Liu Yuen
|
||||
if (randGenNum == 2) {
|
||||
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
||||
if(eventNumber == 2){
|
||||
sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
|
||||
setAttackingShips(true);
|
||||
break;
|
||||
}
|
||||
//Ship Repair
|
||||
if (randGenNum == 3 && getHP() < 100) {
|
||||
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
||||
if(eventNumber == 3){
|
||||
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)){
|
||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
||||
@@ -229,4 +215,6 @@ public class RandomEventGUI extends Player {
|
||||
stage.setScene(root);
|
||||
return stage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import logic.Player;
|
||||
import java.util.Random;
|
||||
|
||||
public class TravelGUI extends Player {
|
||||
private TaipanShopGUI shop;
|
||||
private Label firm = new Label();
|
||||
private Label wItemsText = new Label();
|
||||
private Label wItemSpaceText = new Label();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gui;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
@@ -9,10 +10,11 @@ import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Stage;
|
||||
import logic.Player;
|
||||
import logic.WarehouseLogic;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -90,13 +92,7 @@ public class WarehouseGUI extends Player {
|
||||
textField = new TextField();
|
||||
|
||||
//Creating the box for the warehouse GUI
|
||||
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);
|
||||
settingBorderFormat(hBox, vBox);
|
||||
vBox.setPrefHeight(200.0);
|
||||
vBox.setPrefWidth(100.0);
|
||||
|
||||
@@ -137,20 +133,14 @@ public class WarehouseGUI extends Player {
|
||||
|
||||
|
||||
//Takes you to the HK warehouse
|
||||
borderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
|
||||
borderPane.setAlignment(title, Pos.CENTER);
|
||||
title.setText("Hong Kong Warehouse");
|
||||
title.setFont(new Font(24.0));
|
||||
title.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
|
||||
borderPane.setTop(title);
|
||||
|
||||
// Making the BOX again
|
||||
borderPane.setAlignment(hBox0, javafx.geometry.Pos.CENTER);
|
||||
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);
|
||||
settingBorderFormat(hBox0, vBox0);
|
||||
vBox0.setSpacing(10.0);
|
||||
|
||||
playerLabel.setText("Player:");
|
||||
@@ -171,10 +161,10 @@ public class WarehouseGUI extends Player {
|
||||
|
||||
playerOpium.setText("Opium:");
|
||||
|
||||
vBox1.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||
vBox1.setAlignment(Pos.CENTER_LEFT);
|
||||
vBox1.setSpacing(10.0);
|
||||
|
||||
houseLabel.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
||||
houseLabel.setAlignment(Pos.TOP_CENTER);
|
||||
houseLabel.setText("Warehouse:");
|
||||
houseLabel.setFont(new Font(18.0));
|
||||
|
||||
@@ -231,85 +221,46 @@ public class WarehouseGUI extends Player {
|
||||
taipanShopGUI.initializeShop(stage);
|
||||
stage.show();
|
||||
});
|
||||
|
||||
//Runs when the withdraw button is selected. and removes the amount of the selected good
|
||||
withdrawButton.setOnAction(event -> {
|
||||
try {
|
||||
int withdraw = Integer.parseInt(textField.getText());
|
||||
|
||||
if(withdraw <= 0){
|
||||
title.setText("Please enter a valid value");
|
||||
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||
if(Goods.getSelectedToggle() == generalRadio){
|
||||
title.setText(warehouseLogic.withdraw(textField.getText(),1));
|
||||
}
|
||||
//Transfers general amount
|
||||
else if(Goods.getSelectedToggle() == generalRadio && withdraw <= getwGeneral()){
|
||||
setGeneralHeld(getPlayer().getGeneralHeld()+withdraw);
|
||||
setwGeneral(getPlayer().getwGeneral()-withdraw);
|
||||
else if(Goods.getSelectedToggle() == armsRadio){
|
||||
title.setText(warehouseLogic.withdraw(textField.getText(),2));
|
||||
}
|
||||
//Transfers Arms amount
|
||||
else if(Goods.getSelectedToggle() == armsRadio && withdraw <= getwArms()){
|
||||
setArmsHeld(getPlayer().getArmsHeld()+withdraw);
|
||||
setwArms(getPlayer().getwArms()-withdraw);
|
||||
else if(Goods.getSelectedToggle() == silkRadio){
|
||||
title.setText(warehouseLogic.withdraw(textField.getText(),3));
|
||||
}
|
||||
//Transfers Silk Amount
|
||||
else if(Goods.getSelectedToggle() == silkRadio && withdraw <= getwSilk()){
|
||||
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");
|
||||
else if(Goods.getSelectedToggle() == opiumRadio){
|
||||
title.setText(warehouseLogic.withdraw(textField.getText(),4));
|
||||
}
|
||||
setPlayer(warehouseLogic.getPlayer());
|
||||
updateLabels();
|
||||
}
|
||||
catch (Exception e) {
|
||||
title.setText("Please enter a valid value");
|
||||
}
|
||||
});
|
||||
|
||||
//Button to add a user entered amount to the warehouse
|
||||
depositButton.setOnAction(event -> {
|
||||
try {
|
||||
int deposit = Integer.parseInt(textField.getText());
|
||||
|
||||
if(deposit <= 0){
|
||||
title.setText("Please enter a valid value");
|
||||
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||
if(Goods.getSelectedToggle() == generalRadio){
|
||||
title.setText(warehouseLogic.deposit(textField.getText(),1));
|
||||
}
|
||||
//Transfers general amount
|
||||
else if(Goods.getSelectedToggle() == generalRadio && deposit <= getGeneralHeld()){
|
||||
setGeneralHeld(getPlayer().getGeneralHeld()-deposit);
|
||||
setwGeneral(getPlayer().getwGeneral()+deposit);
|
||||
else if(Goods.getSelectedToggle() == armsRadio){
|
||||
title.setText(warehouseLogic.deposit(textField.getText(),2));
|
||||
}
|
||||
//Transfers Arms amount
|
||||
else if(Goods.getSelectedToggle() == armsRadio && deposit <= getArmsHeld()){
|
||||
setArmsHeld(getPlayer().getArmsHeld()-deposit);
|
||||
setwArms(getPlayer().getwArms()+deposit);
|
||||
else if(Goods.getSelectedToggle() == silkRadio){
|
||||
title.setText(warehouseLogic.deposit(textField.getText(),3));
|
||||
}
|
||||
//Transfers Silk amount
|
||||
else if(Goods.getSelectedToggle() == silkRadio && deposit <= getSilkHeld()){
|
||||
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");
|
||||
else if(Goods.getSelectedToggle() == opiumRadio){
|
||||
title.setText(warehouseLogic.deposit(textField.getText(),4));
|
||||
}
|
||||
setPlayer(warehouseLogic.getPlayer());
|
||||
updateLabels();
|
||||
}
|
||||
catch (Exception e) {
|
||||
title.setText("Please enter a valid value");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Create the sceene and box of the desired size
|
||||
//Create the scene and box of the desired size
|
||||
Scene root = new Scene(borderPane, 600, 480);
|
||||
root.getStylesheets().add("styleguide.css");
|
||||
|
||||
@@ -319,6 +270,15 @@ public class WarehouseGUI extends Player {
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package logic;
|
||||
|
||||
public class MainLogic extends Player{
|
||||
}
|
||||
@@ -1,4 +1,45 @@
|
||||
package logic;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
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.
|
||||
*
|
||||
* Author: Vikram Bawa
|
||||
*/
|
||||
import java.util.Random;
|
||||
|
||||
@@ -1,4 +1,94 @@
|
||||
package logic;
|
||||
|
||||
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;
|
||||
|
||||
import logic.Player;
|
||||
import logic.WarehouseLogic;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
@@ -20,80 +21,29 @@ public class WarehouseText extends Player {
|
||||
*
|
||||
*/
|
||||
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);
|
||||
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
|
||||
due to any errors while giving the program an incorrect input*/
|
||||
try {
|
||||
//The if statement checks that you have enough resources to make the transfer
|
||||
if (Integer.parseInt(amount) <= getOpiumHeld() || Integer.parseInt(amount) <= getSilkHeld() || Integer.parseInt(amount) <= getGeneralHeld() || Integer.parseInt(amount) <= getArmsHeld()) {
|
||||
finalAmount = Integer.parseInt(amount);
|
||||
askGood = true;
|
||||
System.out.println("Please enter a good to transfer O, S, A, G :");
|
||||
String good = keyboard.nextLine();
|
||||
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||
if(good.equalsIgnoreCase("g")){
|
||||
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 {
|
||||
System.out.println("Nice try but you don't have any items of that quantity!");
|
||||
askGood = false;
|
||||
else if(good.equalsIgnoreCase("a")){
|
||||
System.out.println(warehouseLogic.deposit(amount,2));
|
||||
}
|
||||
//Ensures that goods are only transferred if they have the specified amount
|
||||
//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
|
||||
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")){
|
||||
System.out.println(warehouseLogic.deposit(amount,3));
|
||||
}
|
||||
} else if (good.equalsIgnoreCase("S")) {
|
||||
if (getSilkHeld() >= Integer.parseInt(amount)) {
|
||||
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");
|
||||
else if(good.equalsIgnoreCase("o")){
|
||||
System.out.println(warehouseLogic.deposit(amount,4));
|
||||
}
|
||||
setPlayer(warehouseLogic.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,82 +56,28 @@ public class WarehouseText extends Player {
|
||||
*/
|
||||
|
||||
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);
|
||||
//Prompts the user for the amount they would like to remove
|
||||
amount = keyboard.nextLine();
|
||||
//The if statement checks that you have enough resources to make the transfer
|
||||
try {
|
||||
//The if statement checks that you have enough resources to make the transfer
|
||||
if (Integer.parseInt(amount) <= getwOpium() || Integer.parseInt(amount) <= getwSilk() || Integer.parseInt(amount) <= getwGeneral() || Integer.parseInt(amount) <= getwArms()) {
|
||||
finalAmount = Integer.parseInt(amount);
|
||||
askGood = true;
|
||||
System.out.println("Please enter the amount of the good you would like to withdraw.");
|
||||
String amount = keyboard.nextLine();
|
||||
//Asks the user for the amount of the good they would like to withdraw
|
||||
/*The try function ensures that the program does not crash
|
||||
due to any errors while giving the program an incorrect input*/
|
||||
System.out.println("Please enter a good to withdraw (O)pium, (S)ilk, (A)rms, (G)eneral:");
|
||||
String good = keyboard.nextLine();
|
||||
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 {
|
||||
System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
|
||||
askGood = false;
|
||||
else if(good.equalsIgnoreCase("a")){
|
||||
System.out.println(warehouseLogic.withdraw(amount,2));
|
||||
}
|
||||
|
||||
//Ensures that goods are only transferred if they have the specified amount
|
||||
//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")){
|
||||
System.out.println(warehouseLogic.withdraw(amount,3));
|
||||
}
|
||||
} else if (good.equalsIgnoreCase("S")) {
|
||||
if (getwSilk() >= Integer.parseInt(amount)) {
|
||||
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");
|
||||
else if(good.equalsIgnoreCase("o")){
|
||||
System.out.println(warehouseLogic.withdraw(amount,4));
|
||||
}
|
||||
setPlayer(warehouseLogic.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,26 +102,23 @@ public class WarehouseText extends Player {
|
||||
boolean keepGoing = true;
|
||||
while (keepGoing) {
|
||||
this.showWarehouse();
|
||||
String input = " ";
|
||||
System.out.println("Would you like to add(A) or remove(R) resources? ");
|
||||
System.out.println("Would you like to (D)eposit or (W)ithdraw resources? ");
|
||||
Scanner keyboard = new Scanner(System.in);
|
||||
input = keyboard.next();
|
||||
if (input.equalsIgnoreCase("R")) {
|
||||
String input = keyboard.next();
|
||||
if (input.equalsIgnoreCase("D")) {
|
||||
this.removeAmount();
|
||||
this.showWarehouse();
|
||||
} else if (input.equalsIgnoreCase("A")) {
|
||||
} else if (input.equalsIgnoreCase("W")) {
|
||||
this.addAmount();
|
||||
this.showWarehouse();
|
||||
|
||||
}
|
||||
else{
|
||||
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
|
||||
System.out.println("Would you like to do any other business? Y / N?");
|
||||
check = keyboard.nextLine();
|
||||
String check = keyboard.nextLine();
|
||||
check = keyboard.nextLine();
|
||||
|
||||
if (check.equalsIgnoreCase("Y")) {
|
||||
|
||||
Reference in New Issue
Block a user