Added some content to the textgame files and added some stuff to the logic files. Also fixed formating in TravelGUI

This commit is contained in:
2019-04-07 16:35:22 -06:00
parent f37aa91fad
commit 26064ebac3
14 changed files with 1906 additions and 385 deletions

1516
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@@ -100,21 +100,7 @@ public class BankGUI extends Player {
b1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
int withdraw = Integer.parseInt(txtField1.getText());
if (withdraw < 0) {
l5.setText("Come on " + getName() + ", are you trying to fool me?\nNo negative numbers please!");
} else if (withdraw <= getBank()) {
setMoney(withdraw + getMoney());
setBank(getBank() - withdraw);
} else {
l5.setText("Sorry, you can not withdraw that much.");
}
l2.setText("Balance: " + getBank());
l4.setText("Cash: " + getMoney());
} catch (Exception e) {
l5.setText("Please enter a valid response.");
}
withdraw(txtField1, l5, l2, l4);
}
}
);
@@ -127,22 +113,7 @@ public class BankGUI extends Player {
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
int deposit = Integer.parseInt(txtField1.getText());
if (deposit < 0) {
l5.setText("Nice try! You can not enter negative numbers.");
} else if (deposit <= getMoney()) {
setBank(deposit + getBank());
setMoney(getMoney() - deposit);
} else {
l5.setText("Sorry, you can not deposit that much.");
}
l2.setText("Balance: " + getBank());
l4.setText("Cash: " + getMoney());
} catch (Exception e) {
l5.setText("Please enter a valid response.");
}
deposits(txtField1, l5, l2, l4);
}
}
);
@@ -172,6 +143,43 @@ public class BankGUI extends Player {
return primaryStage;
}
private void deposits(TextField txtField1, Label l5, Label l2, Label l4) {
try {
int deposit = Integer.parseInt(txtField1.getText());
if (deposit < 0) {
l5.setText("Nice try! You can not enter negative numbers.");
} else if (deposit <= getMoney()) {
setBank(deposit + getBank());
setMoney(getMoney() - deposit);
} else {
l5.setText("Sorry, you can not deposit that much.");
}
l2.setText("Balance: " + getBank());
l4.setText("Cash: " + getMoney());
} catch (Exception e) {
l5.setText("Please enter a valid response.");
}
}
private void withdraw(TextField txtField1, Label l5, Label l2, Label l4) {
try {
int withdraw = Integer.parseInt(txtField1.getText());
if (withdraw < 0) {
l5.setText("Come on " + getName() + ", are you trying to fool me?\nNo negative numbers please!");
} else if (withdraw <= getBank()) {
setMoney(withdraw + getMoney());
setBank(getBank() - withdraw);
} else {
l5.setText("Sorry, you can not withdraw that much.");
}
l2.setText("Balance: " + getBank());
l4.setText("Cash: " + getMoney());
} catch (Exception e) {
l5.setText("Please enter a valid response.");
}
}
/**
* sets scene and runs stage
*

View File

@@ -8,6 +8,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import logic.Player;
import logic.GameEndLogic;
/**
* 2019-03-10
@@ -72,28 +73,15 @@ public class GameEndGUI extends Player {
netWorth.setFont(new Font(22.0));
borderPane.setCenter(vBox);
//Calculating the netWorth of the Player
GameEndLogic gameEndLogic = new GameEndLogic();
netWorthInt = gameEndLogic.getNetWorth();
//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 health is below or equal to 0 then the game will either show the gameOver screen or the win screen
* */
if (getHP() <= 0) {
title.setText("Game Over!");
} else {
title.setText("Congratulations!");
}
/**
* Calculates the networth of the player by the end of the game
* */
netWorthInt = getMoney() + (getOpiumHeld() * 16000) + (getSilkHeld() * 160) + (getArmsHeld() * 160) + (getGeneralHeld() * 8);
netWorthInt += (getwOpium() * 16000) + (getwSilk() * 160) + (getwArms() * 160) + (getwGeneral() * 8);
netWorthInt -= getDebt();
title.setText(gameEndLogic.endGameText());
//Updating the endgame stats of the player
firmName.setText("Firm Name: " + getName());

View File

@@ -704,7 +704,7 @@ public class TaipanShopGUI extends Player {
textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP);
textOut.setPrefHeight(163.0);
textOut.setPrefWidth(583.0);
//defaultTextOut();
defaultTextOut();
textOut.setFont(size14);
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);

View File

@@ -1,6 +1,7 @@
package gui; /**
package gui;
/**
* TravelGUI is the class in which takes the player from location to location
*
* Author: Harkamal Randhawa
*/
import javafx.geometry.Pos;
@@ -36,10 +37,8 @@ public class TravelGUI extends Player {
private TextField numberInput = new TextField();
private Boolean peasantShipScene = false;
private Boolean littyShipScene = false;
private Boolean shopScene = false;
private Boolean stormScene = false;
private Boolean sceneContinue = false;
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
@@ -126,25 +125,24 @@ public class TravelGUI extends Player {
//Makes sure you can't travel to your own location.
if (response != getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
hasTraveled = seaAtlas(response);
randomEventSea(response,stage);
randomEventSea(response);
setBank((int) (getBank() * 1.01));
setDebt((int) (getDebt() * 1.01));
setIsPriceChanged(2);
//shopScene = false;
//stormScene = false;
stormScene = false;
} else{
if(response == getLocation()){
textOut.setText(" " + "You're already here " + getName() + "\n");
textOut.setText("\tYou're already here " + getName() + "\n");
}
else{
textOut.setText(" " + getName() + "; Sorry but could you say that again?");
textOut.setText("\t" + getName() + "; Sorry but could you say that again?");
}
textOut.setText(textOut.getText() + "\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?");
textOut.setText(textOut.getText() + "\n\n\t\t1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n\t\t5) Manila, 6) Singapore, or 7) Batavia?");
}
} catch (Exception e) {
textOut.setText(" " + "Sorry, " + getName() + " could you say that again?");
textOut.setText("\tSorry, " + getName() + " could you say that again?");
}
if (hasTraveled) {
continueButton.setVisible(true);
@@ -170,7 +168,7 @@ public class TravelGUI extends Player {
root.getStylesheets().add("styleguide.css");
//Updates the stage for the first-time you read it
shop.updateStage(firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText);
textOut.setText(" Taipan, do you wish to go to:\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?\n After typing the number you want to go to press 'Enter' or 'Z'");
textOut.setText("\tTaipan, do you wish to go to:\n\n\t\t1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n\t\t5) Manila, 6) Singapore, or 7) Batavia?\n\n\tAfter typing the number you want to go to press 'Enter' or 'Z'");
stage.setTitle("Travel");
stage.setResizable(false);
stage.setScene(root);
@@ -186,35 +184,35 @@ public class TravelGUI extends Player {
private Boolean seaAtlas(int locationOfTravel) {
switch (locationOfTravel) {
case 1:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong");
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Hong Kong");
setLocation(1);
return true;
case 2:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai");
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Shanghai");
setLocation(2);
return true;
case 3:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki");
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Nagasaki");
setLocation(3);
return true;
case 4:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon");
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Saigon");
setLocation(4);
return true;
case 5:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila");
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Manila");
setLocation(5);
return true;
case 6:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore");
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Singapore");
setLocation(6);
return true;
case 7:
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia");
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Batavia");
setLocation(7);
return true;
default:
textOut.setText(" " + "Sorry but could you say that again " + getName() + "?");
textOut.setText("\tSorry but could you say that again " + getName() + "?");
return false;
}
}
@@ -225,7 +223,7 @@ public class TravelGUI extends Player {
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
* by a typhoon.
**/
private void randomEventSea(int locationOfTravel, Stage stage) {
private void randomEventSea(int locationOfTravel) {
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if (randGenNum == 1) {
@@ -233,7 +231,7 @@ public class TravelGUI extends Player {
continueButton.setDefaultButton(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
textOut.setText(" We see a ship on the horizon " + getName() + "; Prepare for combat!");
textOut.setText("\tWe see a ship on the horizon " + getName() + "; Prepare for combat!");
peasantShipScene = true;
}else if (randGenNum == 2) {
disaster(locationOfTravel);
@@ -250,66 +248,22 @@ public class TravelGUI extends Player {
**/
private void disaster(int locationOfTravel) {
//Tells player that there is a storm approaching.
textOut.setText(" " + "Storm " + getName() + "! ");
textOut.setText("\tStorm " + getName() + "! ");
Random rand = new Random();
int randGenNum = rand.nextInt(5) + 1;
//If the player lands within this range, nothing happens to them
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
if (randGenNum <= 2) {
textOut.setText(textOut.getText() + "\n " + "We got through the storm " + getName() + "!");
textOut.setText(textOut.getText() + "\n\tWe got through the storm " + getName() + "!");
}else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) {
textOut.setText(textOut.getText() + "\n " + "We've been blown off course!");
textOut.setText(textOut.getText() + "\n\tWe've been blown off course!");
seaAtlas(randGenNum);
}
}
}
}
/**
* 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(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;
}
/**
* 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(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;
}
}

View File

@@ -18,20 +18,12 @@ public class FileSaving extends Player implements Serializable {
try {
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
ObjectInputStream inObject = new ObjectInputStream(in);
Player player = (Player) inObject.readObject();
in.close();
inObject.close();
return player;
return getPlayer(in);
}
catch (Exception e) {
try {
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
ObjectInputStream inObject = new ObjectInputStream(in);
Player player = (Player) inObject.readObject();
in.close();
inObject.close();
return player;
return getPlayer(in);
}
catch(Exception e2){
return null;
@@ -39,6 +31,14 @@ public class FileSaving extends Player implements Serializable {
}
}
private Player getPlayer(InputStream in) throws IOException, ClassNotFoundException {
ObjectInputStream inObject = new ObjectInputStream(in);
Player player = (Player) inObject.readObject();
in.close();
inObject.close();
return player;
}
/**
* Saves the file of type player which contains all the player instances
* @param player The player object being saved

View File

@@ -1,4 +1,27 @@
package logic;
public class GameEndLogic extends Player{
/**
* Calculates the networth of the player by the end of the game
* @return the total networth of the player
*/
public int getNetWorth() {
int netWorthInt;
netWorthInt = getMoney() + (getOpiumHeld() * 16000) + (getSilkHeld() * 160) + (getArmsHeld() * 160) + (getGeneralHeld() * 8);
netWorthInt += (getwOpium() * 16000) + (getwSilk() * 160) + (getwArms() * 160) + (getwGeneral() * 8);
netWorthInt -= getDebt();
return netWorthInt;
}
/**
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
* @return the endGame message
*/
public String endGameText() {
if (getHP() <= 0) {
return "Game Over!";
} else {
return "Congratulations!";
}
}
}

View File

@@ -77,42 +77,18 @@ public class TaipanShopLogic extends Player {
public String shipStatusString(){
String shipStatus;
switch(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;
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;
}
@@ -125,32 +101,17 @@ public class TaipanShopLogic extends Player {
public String getStringLocation(){
String location;
switch(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;
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;
}
}

Binary file not shown.

View File

@@ -2,12 +2,78 @@ package text;
import logic.Player;
import java.util.Scanner;
public class BankText extends Player {
public BankText(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* This method is used to withdraw or deposit money into the bank account
* by prompting the user if they would like to withdraw or deposit. Followed
* by prompting them to enter an amount to transfer. This method also uses the
* player class to see if the transfer can be made,and if it can it changes the
* values accordingly
*/
public void bank(){
Scanner input = new Scanner(System.in);
boolean notDone = true;
int check = 0;
while(notDone){
//Prompt the user if they want to withdraw or deposit
System.out.println("Would you like to Withdraw or Deposit?");
String response = input.nextLine();
//If user chose withdraw then subtract the amount from bank account and add it to cash
if(response.equalsIgnoreCase("W")){
boolean notDone2 = true;
while(notDone2){
System.out.println("How much do you wish to Withdraw?");
int withdraw = input.nextInt();
//Prompt the user for the amount and check if the bank has sufficient funds
if(withdraw <= getBank()){
setMoney(withdraw + getMoney());
setBank(getBank()-withdraw);
notDone2 = false;
check = 1;
}
}
}
//If the user chooses to deposit the continue to this code
else if(response.equalsIgnoreCase("D")){
boolean notDone2 = true;
while(notDone2){
//Prompt the user for the amount they would like to deposit and ensure suffiecent funds
System.out.println("How much do you wish to Deposit?");
int deposit = input.nextInt();
if(deposit <= getMoney()){
setBank(deposit + getBank());
setMoney(getMoney()-deposit);
notDone2 = false;
check = 1;
}
}
}
if(check == 1){
boolean notDone3 = true;
// Asks user if they would like to continue in bank or not
while(notDone3){
System.out.println("Would you like to continue? Y/N");
response = input.nextLine();
response = input.nextLine();
if(response.equalsIgnoreCase("Y")){
notDone3 = false;
}else if(response.equalsIgnoreCase("N")){
notDone = false;
notDone3 = false;
}
}
}
}
}
}

View File

@@ -3,8 +3,10 @@ package text;
import logic.Player;
public class GameEndText extends Player {
public GameEndText(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
}

View File

@@ -2,9 +2,43 @@ package text;
import logic.Player;
import java.util.Scanner;
public class StartText extends Player {
public StartText(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
/**
* Initializes the game by asking for your name and if you would like to start with either: 1) money and a debt or
* 2) guns and no cash/debt.
*/
public void start()
{
Scanner userInput = new Scanner(System.in);
System.out.println("Taipan, \nWhat will you name your firm:");
setName(userInput.nextLine());
System.out.println("Do you want to start . . .\n\t1) With cash (and a debt)\n\t\t\t>> or <<\n\t" + "2) With five guns and no cash (But no debt!)?\n ");
int input = userInput.nextInt();
if (input == 1)
{
setMoney(400);
setDebt(5000);
}
if (input == 2)
{
setGuns(5);
}
// purely for testing purposes.
if(getName().equalsIgnoreCase("Vikram")){
setMoney(999999999);
setBank(999999999);
setGuns(999);
setHP(99999999);
setCargoSpace(99999999);
}
}
}

View File

@@ -1,6 +1,10 @@
package text;
import logic.Player;
import java.util.Random;
import java.util.Scanner;
public class TravelText extends Player {
public TravelText(Player player) {
@@ -8,6 +12,131 @@ public class TravelText extends Player {
setPlayer(playerDummy);
}
/**
* When provided a location number: the method returns a print statement stating the location's name and call another
* method to change the location of the Player object.
*
* @param locationOfTravel is a Player object that will be copied and the player instance variable is set to the copy.
*/
private void seaAtlas(int locationOfTravel) {
switch (locationOfTravel) {
case 1:
System.out.println("\nArriving at Hong Kong");
setLocation(1);
break;
case 2:
System.out.println("\nArriving at Shanghai");
setLocation(2);
break;
case 3:
System.out.println("\nArriving at Nagasaki");
setLocation(3);
break;
case 4:
System.out.println("\nArriving at Saigon");
setLocation(4);
break;
case 5:
System.out.println("\nArriving at Manila");
setLocation(5);
break;
case 6:
System.out.println("\nArriving at Singapore");
setLocation(6);
break;
case 7:
System.out.println("\nArriving at Batavia");
setLocation(7);
break;
}
}
/**
* Based on random chance either attacks the player with enemy ships, throws them to a different location or does nothing.
*
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
* by a typhoon.
**/
private void randomEventSea(int locationOfTravel) throws Exception {
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if (randGenNum == 1) {
ShipWarfareText shipWarfareText = new ShipWarfareText(getPlayer());
shipWarfareText.peasantFleetAttack();
setPlayer(shipWarfareText.getPlayer());
} else if (randGenNum == 2) {
disaster(locationOfTravel);
System.out.println("We made it!");
}
}
/**
* Based on random chance either throws the player character off course, or continues them on their way to their
* destination.
*
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
* by a typhoon.
**/
private void disaster(int locationOfTravel) {
//Tells player that there is a storm approaching.
System.out.print("Storm " + getName() + "! ");
Random rand = new Random();
int randGenNum = rand.nextInt(5) + 1;
//If the player lands within this range, nothing happens to them
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
if (randGenNum <= 2) {
System.out.println(" We made it through!");
} else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) {
System.out.println("We've been blown off course!");
seaAtlas(randGenNum);
}
}
}
}
/**
* Used to travel between different areas inside of the game world.
* If the player's inventory is too full it won't run.
* Also calculates loan and bank interest between the jumps between islands.
**/
public void travelTo() {
Scanner keyboard = new Scanner(System.in);
String response;
int tempInt;
boolean hasTraveled = false;
//Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory.
if (getCargoSpace() >= (getOpiumHeld() + (getGuns() * 10) + getSilkHeld() + getArmsHeld() + getGeneralHeld())) {
while (true) {
System.out.println("\n" + getName() + ", do you wish to go to:\n");
System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?");
response = keyboard.nextLine();
//Just in case the player types something that was not intended. It will refresh the question and ask it again
try {
tempInt = Integer.parseInt(response);
//Makes sure you can't travel to your own location.
if (tempInt != getLocation()) {
randomEventSea(tempInt);
seaAtlas(tempInt);
hasTraveled = true;
setBank((int) (getBank() * 1.01));
setDebt((int) (getDebt() * 1.01));
} else System.out.println("\nYou're already here " + getName() + ".");
} catch (Exception e) {
System.out.print("\nSorry, " + getName() + " could you say that again?");
}
if (hasTraveled) {
break;
}
}
} else {
System.out.println(getName() + " the cargo is too heavy! We can't set sail!");
}
}
}

View File

@@ -2,6 +2,8 @@ package text;
import logic.Player;
import java.util.Scanner;
public class WarehouseText extends Player {
public WarehouseText(Player player) {
@@ -9,6 +11,228 @@ public class WarehouseText extends Player {
setPlayer(playerDummy);
}
/**
* This method adds an amount of a certain good
* the user is prompted to enter the amount they would like to
* add followed by the good they would like to add to the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
*
*/
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
/*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;
}
//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;
}
//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")) {
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");
}
}
/**
* This method removes an amount of a certain good
* the user is prompted to enter the amount they would like to
* remove followed by the good they would like to remove from the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
*
*/
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;
}
//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;
}
//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")) {
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");
}
}
/**
* This method prints the stock that is in the warehouse currently using the get and set
* methods from the player class. This is to allow the user to be able to know how much they have
* stored in the warehouse
*/
public void showWarehouse() {
System.out.println("--------------------\nWarehouse\n--------------------");
System.out.println("Opium : " + getwOpium());
System.out.println("Silk : " + getwSilk());
System.out.println("General : " + getwGeneral());
System.out.println("Arms : " + getwArms());
}
/**
* This method combines the add and remove methods and prompts the user to
* enter what they would like to do. Add or remove and accordingly invokes
* the required methods
*/
public void changeWarehouse() {
boolean keepGoing = true;
while (keepGoing) {
this.showWarehouse();
String input = " ";
System.out.println("Would you like to add(A) or remove(R) resources? ");
Scanner keyboard = new Scanner(System.in);
input = keyboard.next();
if (input.equalsIgnoreCase("R")) {
this.removeAmount();
this.showWarehouse();
} else if (input.equalsIgnoreCase("A")) {
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();
check = keyboard.nextLine();
if (check.equalsIgnoreCase("Y")) {
keepGoing = true;
} else if (check.equalsIgnoreCase("N")) {
keepGoing = false;
}
}
}
}