Got the text version up and running, had to make a bunch of methods to get it running though
This commit is contained in:
728
.idea/workspace.xml
generated
728
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -191,9 +191,7 @@ public class StartGUI extends Player {
|
|||||||
* scenario 2 gives the player 5 guns.
|
* scenario 2 gives the player 5 guns.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
startButton.setOnAction(new EventHandler<ActionEvent>() {
|
startButton.setOnAction(event -> {
|
||||||
@Override
|
|
||||||
public void handle(ActionEvent event) {
|
|
||||||
StartLogic startLogic = new StartLogic(getPlayer());
|
StartLogic startLogic = new StartLogic(getPlayer());
|
||||||
if (Start.getSelectedToggle() == cashChoice) {
|
if (Start.getSelectedToggle() == cashChoice) {
|
||||||
startLogic.money_and_debt();
|
startLogic.money_and_debt();
|
||||||
@@ -214,12 +212,9 @@ public class StartGUI extends Player {
|
|||||||
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
||||||
shop.initializeShop(stage);
|
shop.initializeShop(stage);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
continueButton.setOnAction(new EventHandler<ActionEvent>() {
|
continueButton.setOnAction(event -> {
|
||||||
@Override
|
|
||||||
public void handle(ActionEvent event) {
|
|
||||||
FileSaving saving = new FileSaving();
|
FileSaving saving = new FileSaving();
|
||||||
if(saving.loadFile() != null){
|
if(saving.loadFile() != null){
|
||||||
TaipanShopGUI shop = new TaipanShopGUI(saving.loadFile());
|
TaipanShopGUI shop = new TaipanShopGUI(saving.loadFile());
|
||||||
@@ -229,7 +224,6 @@ public class StartGUI extends Player {
|
|||||||
else{
|
else{
|
||||||
authors.setText("There are no previous saves!");
|
authors.setText("There are no previous saves!");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ import javafx.scene.Scene;
|
|||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
import logic.TravelLogic;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -79,6 +81,34 @@ public class TravelGUI extends Player {
|
|||||||
|
|
||||||
//Continues on to either shop or shipwarfare
|
//Continues on to either shop or shipwarfare
|
||||||
continueButton.setOnAction(event -> {
|
continueButton.setOnAction(event -> {
|
||||||
|
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 -> {
|
||||||
|
numberInput(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
firm.setAlignment(Pos.CENTER);
|
||||||
|
firm.setPrefHeight(27.0);
|
||||||
|
firm.setPrefWidth(632.0);
|
||||||
|
firm.setFont(new Font(18.0));
|
||||||
|
flowPane.getChildren().addAll(numberInput, quitButton, continueButton);
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(super.getPlayer());
|
||||||
|
Scene root = new Scene(shop.declareStage(flowPane,firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText,textOut), 600, 480);
|
||||||
|
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("\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);
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void continueButton(Stage stage) {
|
||||||
if(peasantShipScene && getAttackingShips()){
|
if(peasantShipScene && getAttackingShips()){
|
||||||
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
|
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
|
||||||
try {
|
try {
|
||||||
@@ -102,12 +132,9 @@ public class TravelGUI extends Player {
|
|||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
//Text input for where the player needs to go inside of the game world
|
public void numberInput(KeyEvent event) {
|
||||||
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)) {
|
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
|
||||||
int response;
|
int response;
|
||||||
try {
|
try {
|
||||||
@@ -119,6 +146,15 @@ public class TravelGUI extends Player {
|
|||||||
boolean hasTraveled = false;
|
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.
|
//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())){
|
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
|
//Just in case the player types something that was not intended. It will refresh the question and ask it again
|
||||||
try {
|
try {
|
||||||
//Makes sure you can't travel to your own location.
|
//Makes sure you can't travel to your own location.
|
||||||
@@ -131,14 +167,7 @@ public class TravelGUI extends Player {
|
|||||||
stormScene = false;
|
stormScene = false;
|
||||||
|
|
||||||
} else{
|
} else{
|
||||||
if(response == getLocation()){
|
responseTravel(response);
|
||||||
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) {
|
} catch (Exception e) {
|
||||||
textOut.setText("\tSorry, " + getName() + " could you say that again?");
|
textOut.setText("\tSorry, " + getName() + " could you say that again?");
|
||||||
@@ -151,27 +180,16 @@ public class TravelGUI extends Player {
|
|||||||
shopScene = true;
|
shopScene = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
|
|
||||||
textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
firm.setAlignment(Pos.CENTER);
|
public void responseTravel(int response) {
|
||||||
firm.setPrefHeight(27.0);
|
if(response == getLocation()){
|
||||||
firm.setPrefWidth(632.0);
|
textOut.setText("\tYou're already here " + getName() + "\n");
|
||||||
firm.setFont(new Font(18.0));
|
}
|
||||||
flowPane.getChildren().addAll(numberInput, quitButton, continueButton);
|
else{
|
||||||
TaipanShopGUI shop = new TaipanShopGUI(super.getPlayer());
|
textOut.setText("\t" + getName() + "; Sorry but could you say that again?");
|
||||||
Scene root = new Scene(shop.declareStage(flowPane,firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText,textOut), 600, 480);
|
}
|
||||||
root.getStylesheets().add("styleguide.css");
|
|
||||||
//Updates the stage for the first-time you read it
|
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?");
|
||||||
shop.updateStage(firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText);
|
|
||||||
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);
|
|
||||||
return stage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,36 +251,14 @@ public class TravelGUI extends Player {
|
|||||||
textOut.setText("\tWe 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;
|
peasantShipScene = true;
|
||||||
}else if (randGenNum == 2) {
|
}else if (randGenNum == 2) {
|
||||||
disaster(locationOfTravel);
|
|
||||||
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() + "! ");
|
textOut.setText("\tStorm " + getName() + "! ");
|
||||||
Random rand = new Random();
|
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
||||||
int randGenNum = rand.nextInt(5) + 1;
|
textOut.setText(textOut.getText()+"\n\t" + travelLogic.disaster(locationOfTravel));
|
||||||
|
setPlayer(travelLogic.getPlayer());
|
||||||
|
textOut.setText(textOut.getText() + "\n " + "We made it!");
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,12 +96,9 @@ public class ShipWarfareLogic extends Player {
|
|||||||
* @return the loot for defeating the fleet
|
* @return the loot for defeating the fleet
|
||||||
*/
|
*/
|
||||||
public int calculateLoot() {
|
public int calculateLoot() {
|
||||||
|
|
||||||
Random randomValue = new Random();
|
Random randomValue = new Random();
|
||||||
int calculateLoot;
|
int calculateLoot;
|
||||||
calculateLoot = (startingShips * 100) + randomValue.nextInt(startingShips) * 200;
|
calculateLoot = (startingShips * 100) + randomValue.nextInt(startingShips) * 200;
|
||||||
super.setMoney(super.getMoney() + calculateLoot);
|
|
||||||
return calculateLoot;
|
return calculateLoot;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,80 @@
|
|||||||
package logic;
|
package logic;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class TravelLogic extends Player {
|
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.
@@ -11,4 +11,9 @@ public class MainText extends Player {
|
|||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
StartText startText = new StartText(new Player());
|
||||||
|
startText.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,91 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
|
import gui.TaipanShopGUI;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
import logic.RandomEventLogic;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class RandomEventText extends Player {
|
public class RandomEventText extends Player {
|
||||||
public RandomEventText(Player player) {
|
public RandomEventText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
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);
|
delayForSeconds(1);
|
||||||
calculateLoot = logic.calculateLoot();
|
calculateLoot = logic.calculateLoot();
|
||||||
|
setMoney(calculateLoot+ getPlayer().getMoney());
|
||||||
System.out.printf("We got $%,d!", calculateLoot);
|
System.out.printf("We got $%,d!", calculateLoot);
|
||||||
delayForSeconds(2);
|
delayForSeconds(2);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
|
import gui.TaipanShopGUI;
|
||||||
|
import logic.FileSaving;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
import logic.StartLogic;
|
import logic.StartLogic;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@@ -17,20 +19,54 @@ public class StartText extends Player {
|
|||||||
*/
|
*/
|
||||||
public void start() {
|
public void start() {
|
||||||
Scanner userInput = new Scanner(System.in);
|
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:");
|
System.out.println("Taipan, \nWhat will you name your firm:");
|
||||||
setName(userInput.nextLine());
|
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 ");
|
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 ");
|
||||||
|
while (true) {
|
||||||
int input = userInput.nextInt();
|
int input = userInput.nextInt();
|
||||||
StartLogic startLogic = new StartLogic(getPlayer());
|
StartLogic startLogic = new StartLogic(getPlayer());
|
||||||
if (input == 1) {
|
if (input == 1) {
|
||||||
startLogic.money_and_debt();
|
startLogic.money_and_debt();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (input == 2) {
|
else if (input == 2) {
|
||||||
startLogic.guns();
|
startLogic.guns();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// purely for testing purposes.
|
// purely for testing purposes.
|
||||||
if (getName().equalsIgnoreCase("Vikram")) {
|
else if (getName().equalsIgnoreCase("Vikram")) {
|
||||||
startLogic.cheat();
|
startLogic.cheat();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Invalid input, please try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package text;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import javafx.scene.layout.FlowPane;
|
||||||
|
import logic.FileSaving;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
import logic.TaipanShopLogic;
|
import logic.TaipanShopLogic;
|
||||||
|
|
||||||
@@ -91,6 +93,12 @@ public class TaipanShopText extends Player {
|
|||||||
* this is the shop method. Activates the shopping screen.
|
* this is the shop method. Activates the shopping screen.
|
||||||
*/
|
*/
|
||||||
public void shop(){
|
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());
|
TaipanShopLogic logic = new TaipanShopLogic(getPlayer());
|
||||||
System.out.println(logic.updatePrices());
|
System.out.println(logic.updatePrices());
|
||||||
setPlayer(logic.getPlayer());
|
setPlayer(logic.getPlayer());
|
||||||
@@ -115,7 +123,17 @@ public class TaipanShopText extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Scanner input = new Scanner(System.in);
|
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.
|
// as long as the user does not enter a valid input, the code will run in a loop forever.
|
||||||
while(notDone){
|
while(notDone){
|
||||||
printShop();
|
printShop();
|
||||||
@@ -126,6 +144,35 @@ public class TaipanShopText extends Player {
|
|||||||
System.out.println("What do you wish me to buy, " + getName() + "?");
|
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.
|
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
|
||||||
|
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() + "?");
|
||||||
|
selling(input, notDone2);
|
||||||
|
|
||||||
|
} else if (response.equalsIgnoreCase("V") && (caseNum == 1 || caseNum == 3)) {
|
||||||
|
bank();
|
||||||
|
} else if (response.equalsIgnoreCase("T") && (caseNum == 1 || caseNum == 3)) {
|
||||||
|
warehouse();
|
||||||
|
} 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") ) {
|
||||||
|
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.
|
||||||
|
else if (response.equalsIgnoreCase("R") && caseNum == 3) {
|
||||||
|
retire();
|
||||||
|
notDone = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buying(Scanner input, boolean notDone2) {
|
||||||
|
String response;
|
||||||
while (notDone2) {
|
while (notDone2) {
|
||||||
response = input.nextLine();
|
response = input.nextLine();
|
||||||
if (response.equalsIgnoreCase("O")) {
|
if (response.equalsIgnoreCase("O")) {
|
||||||
@@ -186,11 +233,10 @@ public class TaipanShopText extends Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // when selling, the user must enter a non-negative amount of items, and not more than what they have.
|
public void selling(Scanner input, boolean notDone2) {
|
||||||
else if (response.equalsIgnoreCase("S")) {
|
String response;
|
||||||
boolean notDone2 = true;
|
|
||||||
System.out.println("What do you wish me to sell, " + getName() + "?");
|
|
||||||
while (notDone2) {
|
while (notDone2) {
|
||||||
response = input.nextLine();
|
response = input.nextLine();
|
||||||
if (response.equalsIgnoreCase("O")) {
|
if (response.equalsIgnoreCase("O")) {
|
||||||
@@ -252,22 +298,5 @@ public class TaipanShopText extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("V") && (caseNum == 1 || caseNum == 3)) {
|
|
||||||
bank();
|
|
||||||
} else if (response.equalsIgnoreCase("T") && (caseNum == 1 || caseNum == 3)) {
|
|
||||||
warehouse();
|
|
||||||
} 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)) {
|
|
||||||
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.
|
|
||||||
else if (response.equalsIgnoreCase("R") && caseNum == 3) {
|
|
||||||
retire();
|
|
||||||
notDone = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
|
import gui.RandomEventGUI;
|
||||||
|
import gui.TaipanShopGUI;
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
import logic.TravelLogic;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@@ -12,45 +15,6 @@ public class TravelText extends Player {
|
|||||||
setPlayer(playerDummy);
|
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.
|
* 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();
|
shipWarfareText.peasantFleetAttack();
|
||||||
setPlayer(shipWarfareText.getPlayer());
|
setPlayer(shipWarfareText.getPlayer());
|
||||||
} else if (randGenNum == 2) {
|
} else if (randGenNum == 2) {
|
||||||
disaster(locationOfTravel);
|
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
||||||
|
travelLogic.disaster(locationOfTravel);
|
||||||
|
setPlayer(travelLogic.getPlayer());
|
||||||
|
|
||||||
System.out.println("We made it!");
|
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.
|
* Used to travel between different areas inside of the game world.
|
||||||
* If the player's inventory is too full it won't run.
|
* If the player's inventory is too full it won't run.
|
||||||
@@ -105,12 +44,19 @@ public class TravelText extends Player {
|
|||||||
**/
|
**/
|
||||||
public void travelTo() {
|
public void travelTo() {
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
String response;
|
|
||||||
int tempInt;
|
|
||||||
boolean hasTraveled = false;
|
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.
|
//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())) {
|
if (getCargoSpace() >= (getOpiumHeld() + (getGuns() * 10) + getSilkHeld() + getArmsHeld() + getGeneralHeld())) {
|
||||||
|
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) {
|
while (true) {
|
||||||
System.out.println("\n" + getName() + ", do you wish to go to:\n");
|
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?");
|
System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?");
|
||||||
@@ -122,21 +68,37 @@ public class TravelText extends Player {
|
|||||||
//Makes sure you can't travel to your own location.
|
//Makes sure you can't travel to your own location.
|
||||||
if (tempInt != getLocation()) {
|
if (tempInt != getLocation()) {
|
||||||
randomEventSea(tempInt);
|
randomEventSea(tempInt);
|
||||||
seaAtlas(tempInt);
|
|
||||||
|
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
||||||
|
travelLogic.seaAtlas(tempInt);
|
||||||
|
setPlayer(travelLogic.getPlayer());
|
||||||
|
|
||||||
hasTraveled = true;
|
hasTraveled = true;
|
||||||
setBank((int) (getBank() * 1.01));
|
setBank((int) (getBank() * 1.01));
|
||||||
setDebt((int) (getDebt() * 1.01));
|
setDebt((int) (getDebt() * 1.01));
|
||||||
|
setIsPriceChanged(2);
|
||||||
|
|
||||||
} else System.out.println("\nYou're already here " + getName() + ".");
|
} else System.out.println("\nYou're already here " + getName() + ".");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.print("\nSorry, " + getName() + " could you say that again?");
|
System.out.print("\nSorry, " + getName() + " could you say that again?");
|
||||||
}
|
}
|
||||||
if (hasTraveled) {
|
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;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
System.out.println(getName() + " the cargo is too heavy! We can't set sail!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,10 +106,10 @@ public class WarehouseText extends Player {
|
|||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
String input = keyboard.next();
|
String input = keyboard.next();
|
||||||
if (input.equalsIgnoreCase("D")) {
|
if (input.equalsIgnoreCase("D")) {
|
||||||
this.removeAmount();
|
this.addAmount();
|
||||||
this.showWarehouse();
|
this.showWarehouse();
|
||||||
} else if (input.equalsIgnoreCase("W")) {
|
} else if (input.equalsIgnoreCase("W")) {
|
||||||
this.addAmount();
|
this.removeAmount();
|
||||||
this.showWarehouse();
|
this.showWarehouse();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
Reference in New Issue
Block a user