Fix bunch of issues with Travel and Taipanshop, also merged Main, Shop, Travel and Start. Now attempting to merge in ship.
This commit is contained in:
58
src/MainGUI.java
Normal file
58
src/MainGUI.java
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class MainGUI extends Application {
|
||||
private Player player = new Player();
|
||||
|
||||
/**
|
||||
* getter method for the Player object player.
|
||||
*
|
||||
* @return returns a copy of the object player
|
||||
*/
|
||||
|
||||
public Player getPlayer(){
|
||||
Player copy = new Player(player);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Taipan shop with the players stats after the player finishes shopping, it updates the player object and returns it.
|
||||
*
|
||||
* @param shop player object from the main class used to update the shop class
|
||||
*/
|
||||
|
||||
public void shop(TaipanShopGUI shop){
|
||||
shop.setPlayer(player);
|
||||
shop.shop();
|
||||
player = shop.getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the player object with 5 guns or $400 and $5000 debt.
|
||||
*
|
||||
* @param start player object from the main class used to update the start class
|
||||
*/
|
||||
|
||||
public void start(Start start){
|
||||
start.setPlayer(player);
|
||||
start.initialize();
|
||||
player = start.getPlayer();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates main class with player data and starts the game.
|
||||
* The game will only run as long as the player has not retired or has been destroyed.
|
||||
* @param args Just the console for the player to look at.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
StartGUI start = new StartGUI(player);
|
||||
start.initializeStart(primaryStage);
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,23 @@ public class Player {
|
||||
private int cargoSpace = 60;
|
||||
|
||||
public Player(){
|
||||
|
||||
this.name = "Taipan";
|
||||
this.bank = 0;
|
||||
this.money = 0;
|
||||
this.opiumHeld = 0;
|
||||
this.silkHeld = 0;
|
||||
this.generalHeld = 0;
|
||||
this.armsHeld = 0;
|
||||
this.location = 1;
|
||||
this.guns = 0;
|
||||
this.HP = 100;
|
||||
this.debt = 0;
|
||||
this.wOpium = 0;
|
||||
this.wSilk = 0;
|
||||
this.wGeneral = 0;
|
||||
this.wArms = 0;
|
||||
this.retire = false;
|
||||
this.cargoSpace = 60;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,6 +46,7 @@ public class Player {
|
||||
* @param player object of the class Player
|
||||
*/
|
||||
public Player(Player player){
|
||||
this.name = player.name;
|
||||
this.bank = player.bank;
|
||||
this.money = player.money;
|
||||
this.opiumHeld = player.opiumHeld;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
|
||||
import javafx.animation.PathTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Application;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
@@ -11,8 +13,15 @@ import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.util.Duration;
|
||||
import javafx.animation.AnimationTimer;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static javafx.application.Application.launch;
|
||||
|
||||
@@ -36,11 +45,21 @@ public class ShipWarfareGUI extends Application {
|
||||
private Label continueToFight;
|
||||
private int counter1;
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
launch(args);
|
||||
/*
|
||||
/**
|
||||
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||
*
|
||||
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||
*/
|
||||
public ShipWarfareGUI(Player player){
|
||||
Player playerDummy = new Player(player);
|
||||
this.player = playerDummy;
|
||||
}
|
||||
|
||||
//public static void main(String args[]) {
|
||||
// launch(args);
|
||||
//}
|
||||
|
||||
private int numOfPeasantShips = 0;
|
||||
private int numOfLittyShips = 0;
|
||||
private boolean userAttacks = true;
|
||||
@@ -176,7 +195,6 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The number of ships that attack is based on the amount of money one has on hand
|
||||
* @return the number of ships which will attack
|
||||
@@ -205,7 +223,7 @@ public class ShipWarfareGUI extends Application {
|
||||
}
|
||||
|
||||
/**
|
||||
* One in ten chance of running away
|
||||
* One in two chance of running away
|
||||
* @return true if the user is allowed to run, false if not, the "default" is false
|
||||
*/
|
||||
|
||||
@@ -226,7 +244,8 @@ public class ShipWarfareGUI extends Application {
|
||||
* The loot for defeating a litty fleet is much higher than that of a peasant one
|
||||
* @return true if the user wins, loses, or flees, it returns false otherwise
|
||||
* @throws Exception in case of errors due to the
|
||||
*/
|
||||
*
|
||||
* */
|
||||
public boolean destroyLittyShipsOrEscape() throws Exception {
|
||||
int calculateLoot = 0;
|
||||
int chanceOfEnemyRun = 0;
|
||||
@@ -261,7 +280,7 @@ public class ShipWarfareGUI extends Application {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName());
|
||||
System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -322,7 +341,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
|
||||
if (exitValue == 1) {
|
||||
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%%% ship status\n", player.getHP());
|
||||
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
|
||||
calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300;
|
||||
player.setMoney(player.getMoney() + calculateLoot);
|
||||
System.out.printf("We got $%,d!\n", calculateLoot);
|
||||
@@ -343,7 +362,8 @@ public class ShipWarfareGUI extends Application {
|
||||
/**
|
||||
* Sets most of the labels invisible except for the "fight or run" label
|
||||
*/
|
||||
public void wipe() {
|
||||
|
||||
public void wipe(){
|
||||
title.setVisible(false);
|
||||
runAwayOrLeft.setVisible(false);
|
||||
shipsRemaining.setVisible(false);
|
||||
@@ -353,6 +373,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets most of the labels invisible including the fight or run label
|
||||
*/
|
||||
@@ -364,8 +385,6 @@ public class ShipWarfareGUI extends Application {
|
||||
HPLeft.setVisible(false);
|
||||
gunsLeftOrTaken.setVisible(false);
|
||||
continueToFight.setVisible(false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,7 +392,6 @@ public class ShipWarfareGUI extends Application {
|
||||
* @return true if the user wins, loses, or flees, it returns false otherwise
|
||||
* @throws Exception in case of errors due to the delay
|
||||
*/
|
||||
|
||||
public boolean destroyPeasantShipsOrEscape() throws Exception {
|
||||
int calculateLoot = 0;
|
||||
int chanceOfEnemyRun = 0;
|
||||
@@ -478,8 +496,6 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
continueToFight.setText(String.format("Shall we continue to fight? (Click the fight button or the run button)", player.getGuns()));
|
||||
|
||||
|
||||
|
||||
if (exitValue == 1) {
|
||||
wipe();
|
||||
chooseFightOrRun.setText(String.format("Ayy! We won and survived at %d%% ship status!", player.getHP()));
|
||||
@@ -495,15 +511,13 @@ public class ShipWarfareGUI extends Application {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
|
||||
public void start(Stage stage) throws Exception {
|
||||
public Stage initializeShip(Stage stage){
|
||||
setNumOfPeasantShips(numOfShips());
|
||||
|
||||
BorderPane BorderPane = new BorderPane();
|
||||
@@ -536,7 +550,7 @@ public class ShipWarfareGUI extends Application {
|
||||
title.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
||||
title.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||
title.setId("Label1");
|
||||
title.setText(String.format("%d ships attacking. Would you like to Fight or Run?", numOfPeasantShips));
|
||||
title.setText(String.format("%d ships attacking. Would you like to Fight or Run?",numOfPeasantShips));
|
||||
title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
|
||||
|
||||
fightButton.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
@@ -548,8 +562,8 @@ public class ShipWarfareGUI extends Application {
|
||||
runButton.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
runButton.setId("Button2");
|
||||
runButton.setMnemonicParsing(false);
|
||||
runButton.setText("Run");
|
||||
BorderPane.setBottom(hBox);
|
||||
|
||||
BorderPane.setBottom(hBox);runButton.setText("Run");
|
||||
|
||||
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
|
||||
vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
||||
@@ -576,10 +590,6 @@ public class ShipWarfareGUI extends Application {
|
||||
vBox.getChildren().add(gunsLeftOrTaken);
|
||||
vBox.getChildren().add(continueToFight);
|
||||
|
||||
|
||||
//report.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), shipWarfare.getNumOfPeasantShips(), player.getHP()));
|
||||
|
||||
|
||||
//Fight
|
||||
fightButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
@@ -619,14 +629,9 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (counter>=2){
|
||||
title.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -636,7 +641,11 @@ public class ShipWarfareGUI extends Application {
|
||||
stage.setTitle("Ship");
|
||||
stage.setResizable(false);
|
||||
stage.setScene(root);
|
||||
stage.show();
|
||||
return stage;
|
||||
}
|
||||
|
||||
public void start(Stage primaryStage){
|
||||
primaryStage = initializeShip(primaryStage);
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class StartGUI extends Application {
|
||||
public class StartGUI {
|
||||
|
||||
private Player player = new Player();
|
||||
private Player player;
|
||||
private BorderPane borderPane = new BorderPane();
|
||||
private HBox hBox = new HBox();
|
||||
private TextField nameField = new TextField();
|
||||
@@ -60,25 +60,17 @@ public class StartGUI extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]){
|
||||
launch(args);
|
||||
}
|
||||
public void start(Stage stage){
|
||||
stage = initializeStart(stage);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
* Copy constructor.
|
||||
* @param player object of the class Player
|
||||
*
|
||||
*/
|
||||
public StartGUI(Player player)
|
||||
{
|
||||
Player playerTemp = new Player(player);
|
||||
this.player = playerTemp;
|
||||
}
|
||||
*/
|
||||
|
||||
public Stage initializeStart(Stage stage){
|
||||
|
||||
@@ -134,11 +126,9 @@ public class StartGUI extends Application {
|
||||
vBox0.getChildren().add(title);
|
||||
vBox0.getChildren().add(authors);
|
||||
|
||||
System.out.println("0");
|
||||
startButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
System.out.println("a");
|
||||
if (Start.getSelectedToggle() == cashChoice) {
|
||||
player.setMoney(400);
|
||||
player.setDebt(5000);
|
||||
@@ -147,7 +137,6 @@ public class StartGUI extends Application {
|
||||
if (Start.getSelectedToggle() == gunChoice) {
|
||||
player.setGuns(5);
|
||||
}
|
||||
System.out.println("b");
|
||||
|
||||
String response = nameField.getText();
|
||||
// purely for testing purposes.
|
||||
@@ -162,8 +151,10 @@ public class StartGUI extends Application {
|
||||
setFirm(response);
|
||||
}
|
||||
|
||||
System.out.println("x");
|
||||
title.setText("SHOP PLACEHOLDER");
|
||||
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||
shop.initializeShop(stage);
|
||||
stage.show();
|
||||
//title.setText("SHOP PLACEHOLDER");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Font;
|
||||
import java.util.Random;
|
||||
|
||||
public class ShopGUI extends Application {
|
||||
private Player player = new Player();
|
||||
public class TaipanShopGUI {
|
||||
private Player player;
|
||||
private Label firm = new Label();
|
||||
private Label wItemsText = new Label();
|
||||
private Label wItemSpaceText = new Label();
|
||||
@@ -45,10 +45,17 @@ public class ShopGUI extends Application {
|
||||
private int armsPrice = 160;
|
||||
private int generalPrice = 8;
|
||||
|
||||
public static void main(String args[]){
|
||||
launch(args);
|
||||
/**
|
||||
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||
*
|
||||
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||
*/
|
||||
public TaipanShopGUI(Player player){
|
||||
Player playerDummy = new Player(player);
|
||||
this.player = playerDummy;
|
||||
}
|
||||
public void start(Stage stage){
|
||||
|
||||
public void startTaipanShop(Stage stage){
|
||||
stage = initializeShop(stage);
|
||||
updateStage();
|
||||
updatePrices();
|
||||
@@ -363,6 +370,7 @@ public class ShopGUI extends Application {
|
||||
}
|
||||
|
||||
public Stage initializeShop(Stage stage){
|
||||
updateStage();
|
||||
Font size14 = new Font(14.0);
|
||||
Rectangle dialogueRectangle = new Rectangle();
|
||||
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||
@@ -521,7 +529,10 @@ public class ShopGUI extends Application {
|
||||
quitButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
System.out.println("PLACEHOLDER FOR TRAVEL");
|
||||
TravelGUI travelGUI = new TravelGUI(player);
|
||||
travelGUI.initializeTravel(stage);
|
||||
stage.show();
|
||||
//System.out.println("PLACEHOLDER FOR TRAVEL");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -17,8 +17,8 @@ import javafx.scene.text.Font;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class TravelGUI extends Application {
|
||||
private Player player = new Player();
|
||||
public class TravelGUI{
|
||||
private Player player;
|
||||
private Label firm = new Label();
|
||||
private Label wItemsText = new Label();
|
||||
private Label wItemSpaceText = new Label();
|
||||
@@ -36,13 +36,10 @@ public class TravelGUI extends Application {
|
||||
private TextField numberInput = new TextField();
|
||||
private int nextScene = 0;
|
||||
|
||||
public static void main(String args[]){
|
||||
launch(args);
|
||||
}
|
||||
public void start(Stage stage){
|
||||
stage = initializeTravel(stage);
|
||||
updateStage();
|
||||
stage.show();
|
||||
|
||||
public TravelGUI(Player player) {
|
||||
Player playerDummy = new Player(player);
|
||||
this.player = playerDummy;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
@@ -55,17 +52,9 @@ public class TravelGUI extends Application {
|
||||
return playerDummy;
|
||||
}
|
||||
|
||||
public int getUserResponse(){
|
||||
try {
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e){
|
||||
textOut.setText(" Sorry could you say that again?");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Stage initializeTravel(Stage stage){
|
||||
updateStage();
|
||||
|
||||
Font size14 = new Font(14.0);
|
||||
Rectangle dialogueRectangle = new Rectangle();
|
||||
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||
@@ -168,7 +157,9 @@ public class TravelGUI extends Application {
|
||||
|
||||
//Goes back to shop
|
||||
quitButton.setOnAction(event -> {
|
||||
textOut.setText(" " + "PLACEHOLDER FOR SHOP");
|
||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player);
|
||||
taipanShopGUI.initializeShop(stage);
|
||||
stage.show();
|
||||
});
|
||||
|
||||
//Continues on to either shop or shipwarefare
|
||||
@@ -193,7 +184,7 @@ public class TravelGUI extends Application {
|
||||
try {
|
||||
//Makes sure you can't travel to your own location.
|
||||
if (response != player.getLocation() && response != 0 && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
|
||||
randomEventSea(response);
|
||||
randomEventSea(response,stage);
|
||||
hasTraveled = seaAtlas(response);
|
||||
player.setBank((int) (player.getBank() * 1.01));
|
||||
player.setDebt((int) (player.getDebt() * 1.01));
|
||||
@@ -205,10 +196,9 @@ public class TravelGUI extends Application {
|
||||
textOut.setText(" " + "Sorry, " + player.getName() + " could you say that again?");
|
||||
}
|
||||
if (hasTraveled) {
|
||||
textOut.setText(textOut.getText() + "\n " + "PLACEHOLDER FOR SHOP");
|
||||
numberInput.setVisible(false);
|
||||
quitButton.setVisible(false);
|
||||
continueButton.setVisible(true);
|
||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player);
|
||||
taipanShopGUI.initializeShop(stage);
|
||||
stage.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,11 +344,14 @@ public class TravelGUI extends Application {
|
||||
* @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 {
|
||||
private void randomEventSea(int locationOfTravel, Stage stage) {
|
||||
Random rand = new Random();
|
||||
int randGenNum = rand.nextInt(3) + 1;
|
||||
if (randGenNum == 1) {
|
||||
textOut.setText(textOut.getText() + "\n " + "PLACEHOLDER FOR SHIPWARFARE");
|
||||
ShipWarfareGUI ship = new ShipWarfareGUI(player);
|
||||
ship.initializeShip(stage);
|
||||
stage.show();
|
||||
System.out.println(textOut.getText() + "\n " + "PLACEHOLDER FOR SHIPWARFARE");
|
||||
}else if (randGenNum == 2) {
|
||||
disaster(locationOfTravel);
|
||||
textOut.setText(textOut.getText() + "\n " + "We made it!");
|
||||
@@ -443,4 +436,9 @@ public class TravelGUI extends Application {
|
||||
bankText.setText(String.format("Bank: %d", player.getBank()));
|
||||
}
|
||||
|
||||
public void start(Stage primaryStage) {
|
||||
primaryStage = initializeTravel(primaryStage);
|
||||
updateStage();
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user