Got the text version up and running, had to make a bunch of methods to get it running though

This commit is contained in:
2019-04-12 01:07:45 -06:00
parent b4f9ce761c
commit 03ff12b832
13 changed files with 1066 additions and 595 deletions

762
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@@ -191,44 +191,38 @@ public class StartGUI extends Player {
* scenario 2 gives the player 5 guns.
*
*/
startButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
StartLogic startLogic = new StartLogic(getPlayer());
if (Start.getSelectedToggle() == cashChoice) {
startLogic.money_and_debt();
}
if (Start.getSelectedToggle() == gunChoice) {
startLogic.guns();
}
startButton.setOnAction(event -> {
StartLogic startLogic = new StartLogic(getPlayer());
if (Start.getSelectedToggle() == cashChoice) {
startLogic.money_and_debt();
}
if (Start.getSelectedToggle() == gunChoice) {
startLogic.guns();
}
String response = nameField.getText();
// purely for testing purposes.
if (response.equalsIgnoreCase("Vikram")) {
startLogic.cheat();
setCargoSpace(Integer.MAX_VALUE);
}
setFirm(response);
String response = nameField.getText();
// purely for testing purposes.
if (response.equalsIgnoreCase("Vikram")) {
startLogic.cheat();
setCargoSpace(Integer.MAX_VALUE);
}
setFirm(response);
setPlayer(startLogic.getPlayer());
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
setPlayer(startLogic.getPlayer());
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
});
continueButton.setOnAction(event -> {
FileSaving saving = new FileSaving();
if(saving.loadFile() != null){
TaipanShopGUI shop = new TaipanShopGUI(saving.loadFile());
shop.initializeShop(stage);
stage.show();
}
});
continueButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
FileSaving saving = new FileSaving();
if(saving.loadFile() != null){
TaipanShopGUI shop = new TaipanShopGUI(saving.loadFile());
shop.initializeShop(stage);
stage.show();
}
else{
authors.setText("There are no previous saves!");
}
else{
authors.setText("There are no previous saves!");
}
});

View File

@@ -9,11 +9,13 @@ import javafx.scene.Scene;
import javafx.scene.control.Button;
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.scene.control.Label;
import javafx.scene.text.Font;
import logic.Player;
import logic.TravelLogic;
import java.util.Random;
@@ -79,82 +81,14 @@ public class TravelGUI extends Player {
//Continues on to either shop or shipwarfare
continueButton.setOnAction(event -> {
if(peasantShipScene && getAttackingShips()){
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
try {
ship.initializeShip(stage);
} catch (Exception e) {
e.printStackTrace();
}
stage.show();
}
else if(shopScene){
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if(randGenNum >= 2) {
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
else {
RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer());
randomEventGUI.initializeRandomEventGUI(stage);
stage.show();
}
}
continueButton(stage);
});
//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 -> {
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
int response;
try {
response = Integer.parseInt(numberInput.getText().replace(" ", ""));
}
catch (Exception e){
response = 0;
}
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())){
//Just in case the player types something that was not intended. It will refresh the question and ask it again
try {
//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);
setBank((int) (getBank() * 1.01));
setDebt((int) (getDebt() * 1.01));
setIsPriceChanged(2);
stormScene = false;
} else{
if(response == getLocation()){
textOut.setText("\tYou're already here " + getName() + "\n");
}
else{
textOut.setText("\t" + getName() + "; Sorry but could you say that again?");
}
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("\tSorry, " + getName() + " could you say that again?");
}
if (hasTraveled) {
continueButton.setVisible(true);
continueButton.setDefaultButton(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
shopScene = true;
}
}
}
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!");
}
numberInput(event);
});
firm.setAlignment(Pos.CENTER);
@@ -174,6 +108,90 @@ public class TravelGUI extends Player {
return stage;
}
public void continueButton(Stage stage) {
if(peasantShipScene && getAttackingShips()){
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
try {
ship.initializeShip(stage);
} catch (Exception e) {
e.printStackTrace();
}
stage.show();
}
else if(shopScene){
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if(randGenNum >= 2) {
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
else {
RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer());
randomEventGUI.initializeRandomEventGUI(stage);
stage.show();
}
}
}
public void numberInput(KeyEvent event) {
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
int response;
try {
response = Integer.parseInt(numberInput.getText().replace(" ", ""));
}
catch (Exception e){
response = 0;
}
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())){
traveling(event, response, hasTraveled);
}
}
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!");
}
}
public void traveling(KeyEvent event, int response, boolean hasTraveled) {
//Just in case the player types something that was not intended. It will refresh the question and ask it again
try {
//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);
setBank((int) (getBank() * 1.01));
setDebt((int) (getDebt() * 1.01));
setIsPriceChanged(2);
stormScene = false;
} else{
responseTravel(response);
}
} catch (Exception e) {
textOut.setText("\tSorry, " + getName() + " could you say that again?");
}
if (hasTraveled) {
continueButton.setVisible(true);
continueButton.setDefaultButton(true);
quitButton.setVisible(false);
numberInput.setVisible(false);
shopScene = true;
}
}
public void responseTravel(int response) {
if(response == getLocation()){
textOut.setText("\tYou're already here " + getName() + "\n");
}
else{
textOut.setText("\t" + getName() + "; Sorry but could you say that again?");
}
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?");
}
/**
* 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.
@@ -233,36 +251,14 @@ public class TravelGUI extends Player {
textOut.setText("\tWe see a ship on the horizon " + getName() + "; Prepare for combat!");
peasantShipScene = true;
}else if (randGenNum == 2) {
disaster(locationOfTravel);
textOut.setText("\tStorm " + getName() + "! ");
TravelLogic travelLogic = new TravelLogic(getPlayer());
textOut.setText(textOut.getText()+"\n\t" + travelLogic.disaster(locationOfTravel));
setPlayer(travelLogic.getPlayer());
textOut.setText(textOut.getText() + "\n " + "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.
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\tWe got through the storm " + getName() + "!");
}else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) {
textOut.setText(textOut.getText() + "\n\tWe've been blown off course!");
seaAtlas(randGenNum);
}
}
}
}
}

View File

@@ -96,12 +96,9 @@ public class ShipWarfareLogic extends Player {
* @return the loot for defeating the fleet
*/
public int calculateLoot() {
Random randomValue = new Random();
int calculateLoot;
calculateLoot = (startingShips * 100) + randomValue.nextInt(startingShips) * 200;
super.setMoney(super.getMoney() + calculateLoot);
return calculateLoot;
}
}

View File

@@ -1,4 +1,80 @@
package logic;
import java.util.Random;
public class TravelLogic extends Player {
public TravelLogic(Player player) {
Player playerDummy = new Player(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.
*/
public 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 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.
**/
public String disaster(int locationOfTravel) {
//Tells player that there is a storm approaching.
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) {
return "We got through the storm " + getName() + "!";
}else {
while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) {
seaAtlas(randGenNum);
return "We've been blown off course!";
}
}
}
return null;
}
}

Binary file not shown.

View File

@@ -11,4 +11,9 @@ public class MainText extends Player {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
public static void main(String[] args) {
StartText startText = new StartText(new Player());
startText.start();
}
}

View File

@@ -1,10 +1,91 @@
package text;
import gui.TaipanShopGUI;
import logic.Player;
import logic.RandomEventLogic;
import java.util.Scanner;
public class RandomEventText extends Player {
public RandomEventText(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
public void randomEvent(){
/*Pick a random number dictating the events that could happen.
* 1: New gun for player
* 2: Paying Liu Yuen
* 3: Repairing the Ship
*/
RandomEventLogic randomEventLogic = new RandomEventLogic(getPlayer());
int[] randEvent = randomEventLogic.randEvent();
int eventNumber = randEvent[0];
int itemPrice = randEvent[1];
if(eventNumber == 1){
System.out.println("\nA vendor is selling a gun for $" + itemPrice + " for a gun?");
}
if(eventNumber == 2){
System.out.println("\nLiu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
}
if(eventNumber == 3){
System.out.println("\nMc Henry from the Hong Kong shipyard has arrived,\nwould be willing to repair your ship for $" + itemPrice);
}
if((eventNumber == 1 && getCargoSpace() < 10)){
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
if((eventNumber == 3 && getPlayer().getHP() >= 100)){
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
while(true){
System.out.println("Would you like to pay? (Y)es or (N)o");
Scanner keyboard = new Scanner(System.in);
String input = keyboard.next();
if (input.equalsIgnoreCase("Y") && getPlayer().getMoney() > itemPrice) {
//Buy Guns
if (eventNumber == 1 && (getCargoSpace() >= 10)) {
setGuns(getPlayer().getGuns() + 1);
setMoney(getPlayer().getMoney() - itemPrice);
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
//Liu Yuen
if (eventNumber == 2) {
setAttackingShips(false);
setMoney(getPlayer().getMoney() - itemPrice);
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
//Ship Repair
if (eventNumber == 3 && getPlayer().getHP() != 100) {
setHP(100);
setMoney(getPlayer().getMoney() - itemPrice);
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
}
else {
System.out.println("Sorry you don't have enough money");
}
if(input.equalsIgnoreCase("N")){
System.out.println("Aye aye Taipan, we'll send them off!\n");
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
}
}
}

View File

@@ -234,6 +234,7 @@ public class ShipWarfareText extends Player {
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", getHP());
delayForSeconds(1);
calculateLoot = logic.calculateLoot();
setMoney(calculateLoot+ getPlayer().getMoney());
System.out.printf("We got $%,d!", calculateLoot);
delayForSeconds(2);
return true;

View File

@@ -1,5 +1,7 @@
package text;
import gui.TaipanShopGUI;
import logic.FileSaving;
import logic.Player;
import logic.StartLogic;
import java.util.Scanner;
@@ -17,20 +19,54 @@ public class StartText extends Player {
*/
public void start() {
Scanner userInput = new Scanner(System.in);
System.out.println("Taipan, do you want to...\n\t1) load a save file?\n\t\t\t>> or <<\n\t2) make a new save file?");
while (true) {
int input = userInput.nextInt();
if(input == 1){
FileSaving saving = new FileSaving();
if(saving.loadFile() != null){
TaipanShopText taipanShopText = new TaipanShopText(saving.loadFile());
taipanShopText.shop();
}
else{
System.out.println("There are no previous saves!");
}
break;
}
else if(input == 2){
break;
}
else{
System.out.println("Invalid input, please try again.");
}
}
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();
StartLogic startLogic = new StartLogic(getPlayer());
if (input == 1) {
startLogic.money_and_debt();
}
if (input == 2) {
startLogic.guns();
}
// purely for testing purposes.
if (getName().equalsIgnoreCase("Vikram")) {
startLogic.cheat();
while (true) {
int input = userInput.nextInt();
StartLogic startLogic = new StartLogic(getPlayer());
if (input == 1) {
startLogic.money_and_debt();
break;
}
else if (input == 2) {
startLogic.guns();
break;
}
// purely for testing purposes.
else if (getName().equalsIgnoreCase("Vikram")) {
startLogic.cheat();
}
else {
System.out.println("Invalid input, please try again.");
}
}
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
}

View File

@@ -2,6 +2,8 @@ package text;
import java.util.Scanner;
import javafx.scene.layout.FlowPane;
import logic.FileSaving;
import logic.Player;
import logic.TaipanShopLogic;
@@ -91,6 +93,12 @@ public class TaipanShopText extends Player {
* this is the shop method. Activates the shopping screen.
*/
public void shop(){
//Saves the game when loading into the shop
FileSaving saving = new FileSaving();
saving.saveFile(getPlayer());
FlowPane flowPane = new FlowPane();
TaipanShopLogic logic = new TaipanShopLogic(getPlayer());
System.out.println(logic.updatePrices());
setPlayer(logic.getPlayer());
@@ -115,7 +123,17 @@ public class TaipanShopText extends Player {
}
Scanner input = new Scanner(System.in);
try {
runShop(notDone, caseNum, optionText, input);
}
catch (Exception e){
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
}
public void runShop(boolean notDone, int caseNum, String optionText, Scanner input) {
// as long as the user does not enter a valid input, the code will run in a loop forever.
while(notDone){
printShop();
@@ -126,132 +144,13 @@ public class TaipanShopText extends Player {
System.out.println("What do you wish me to buy, " + getName() + "?");
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / getOpiumPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getOpiumPrice() && num >= 0) {
setOpiumHeld(getOpiumHeld()+num);
setMoney(getMoney()-num *getOpiumPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + getName() + "? (You can afford " + getMoney() /getSilkPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getSilkPrice() && num >= 0) {
setSilkHeld(getSilkHeld()+num);
setMoney(getMoney()-num *getSilkPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + getName() + "? (You can afford " + getMoney() /getArmsPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getArmsPrice() && num >= 0) {
setArmsHeld(getArmsHeld()+num);
setMoney(getMoney() - num*getArmsPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + getName() + "? (You can afford " + getMoney() /getGeneralPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getGeneralPrice() && num >= 0) {
setGeneralHeld(getGeneralHeld()+num);
setMoney(getMoney() - num*getGeneralPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
}
buying(input, notDone2);
} // when selling, the user must enter a non-negative amount of items, and not more than what they have.
else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + getName() + "? (You have " + getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getOpiumHeld() && num >= 0) {
setOpiumHeld(getOpiumHeld()-num);
setMoney(getMoney() + num*getOpiumPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + getName() + "? (You have " + getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getSilkHeld() && num >= 0) {
setSilkHeld(getSilkHeld()-num);
setMoney(getMoney() + num*getSilkPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + getName() + "? (You have " + getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getArmsHeld() && num >= 0) {
setArmsHeld(getArmsHeld()-num);
setMoney(getMoney() + num*getArmsPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + getName() + "? (You have " + getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getGeneralHeld() && num >= 0) {
setGeneralHeld(getGeneralHeld()-num);
setMoney(getMoney() + num*getGeneralPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
}
selling(input, notDone2);
} else if (response.equalsIgnoreCase("V") && (caseNum == 1 || caseNum == 3)) {
bank();
@@ -260,7 +159,8 @@ public class TaipanShopText extends Player {
} else if ((response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) && (caseNum == 1 || caseNum == 3)) {
loan();
} // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("Q") && (caseNum == 1 || caseNum == 3)) {
else if (response.equalsIgnoreCase("Q") ) {
System.out.println("1");
travel();
notDone = false;
} // if the user wishes to retire and win the game, they may do so. Doing this breaks them out of the loop.
@@ -270,4 +170,133 @@ public class TaipanShopText extends Player {
}
}
}
public void buying(Scanner input, boolean notDone2) {
String response;
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / getOpiumPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getOpiumPrice() && num >= 0) {
setOpiumHeld(getOpiumHeld()+num);
setMoney(getMoney()-num *getOpiumPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + getName() + "? (You can afford " + getMoney() /getSilkPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getSilkPrice() && num >= 0) {
setSilkHeld(getSilkHeld()+num);
setMoney(getMoney()-num *getSilkPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + getName() + "? (You can afford " + getMoney() /getArmsPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getArmsPrice() && num >= 0) {
setArmsHeld(getArmsHeld()+num);
setMoney(getMoney() - num*getArmsPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + getName() + "? (You can afford " + getMoney() /getGeneralPrice() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() /getGeneralPrice() && num >= 0) {
setGeneralHeld(getGeneralHeld()+num);
setMoney(getMoney() - num*getGeneralPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you can't afford that!");
} else {
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
}
}
public void selling(Scanner input, boolean notDone2) {
String response;
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + getName() + "? (You have " + getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getOpiumHeld() && num >= 0) {
setOpiumHeld(getOpiumHeld()-num);
setMoney(getMoney() + num*getOpiumPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + getName() + "? (You have " + getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getSilkHeld() && num >= 0) {
setSilkHeld(getSilkHeld()-num);
setMoney(getMoney() + num*getSilkPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + getName() + "? (You have " + getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getArmsHeld() && num >= 0) {
setArmsHeld(getArmsHeld()-num);
setMoney(getMoney() + num*getArmsPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + getName() + "? (You have " + getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getGeneralHeld() && num >= 0) {
setGeneralHeld(getGeneralHeld()-num);
setMoney(getMoney() + num*getGeneralPrice());
notDone2 = false;
} else if (num >= 0) {
System.out.println(getName() + ", you don't have that many to sell!");
} else {
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
}
}
}

View File

@@ -1,6 +1,9 @@
package text;
import gui.RandomEventGUI;
import gui.TaipanShopGUI;
import logic.Player;
import logic.TravelLogic;
import java.util.Random;
import java.util.Scanner;
@@ -12,45 +15,6 @@ 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.
*
@@ -65,39 +29,14 @@ public class TravelText extends Player {
shipWarfareText.peasantFleetAttack();
setPlayer(shipWarfareText.getPlayer());
} else if (randGenNum == 2) {
disaster(locationOfTravel);
TravelLogic travelLogic = new TravelLogic(getPlayer());
travelLogic.disaster(locationOfTravel);
setPlayer(travelLogic.getPlayer());
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.
@@ -105,38 +44,61 @@ public class TravelText extends Player {
**/
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;
}
}
traveling(keyboard, hasTraveled);
} else {
System.out.println(getName() + " the cargo is too heavy! We can't set sail!");
}
}
public void traveling(Scanner keyboard, boolean hasTraveled) {
String response;
int tempInt;
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);
TravelLogic travelLogic = new TravelLogic(getPlayer());
travelLogic.seaAtlas(tempInt);
setPlayer(travelLogic.getPlayer());
hasTraveled = true;
setBank((int) (getBank() * 1.01));
setDebt((int) (getDebt() * 1.01));
setIsPriceChanged(2);
} else System.out.println("\nYou're already here " + getName() + ".");
} catch (Exception e) {
System.out.print("\nSorry, " + getName() + " could you say that again?");
}
if (hasTraveled) {
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if(randGenNum >= 2) {
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
taipanShopText.shop();
}
else {
RandomEventText randomEventText = new RandomEventText(getPlayer());
randomEventText.randomEvent();
setPlayer(randomEventText.getPlayer());
}
break;
}
}
}
}

View File

@@ -106,10 +106,10 @@ public class WarehouseText extends Player {
Scanner keyboard = new Scanner(System.in);
String input = keyboard.next();
if (input.equalsIgnoreCase("D")) {
this.removeAmount();
this.addAmount();
this.showWarehouse();
} else if (input.equalsIgnoreCase("W")) {
this.addAmount();
this.removeAmount();
this.showWarehouse();
}
else{