From 325c4127dd1e7d788c285f982a8f575d649bb9ab Mon Sep 17 00:00:00 2001 From: Solargale Date: Sun, 10 Mar 2019 16:06:48 -0600 Subject: [PATCH 1/3] Fix bunch of issues with Travel and Taipanshop, also merged Main, Shop, Travel and Start. Now attempting to merge in ship. --- src/MainGUI.java | 58 +++++++++++++++++++ src/Player.java | 19 +++++- src/ShipWarfareGUI.java | 73 +++++++++++++----------- src/StartGUI.java | 23 +++----- src/{ShopGUI.java => TaipanShopGUI.java} | 23 ++++++-- src/TravelGUI.java | 52 ++++++++--------- 6 files changed, 166 insertions(+), 82 deletions(-) create mode 100644 src/MainGUI.java rename src/{ShopGUI.java => TaipanShopGUI.java} (97%) diff --git a/src/MainGUI.java b/src/MainGUI.java new file mode 100644 index 0000000..f5ab1df --- /dev/null +++ b/src/MainGUI.java @@ -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(); + } +} diff --git a/src/Player.java b/src/Player.java index d38f758..8ff4e2b 100644 --- a/src/Player.java +++ b/src/Player.java @@ -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; diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java index 63a8645..5fe22b4 100644 --- a/src/ShipWarfareGUI.java +++ b/src/ShipWarfareGUI.java @@ -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() { @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; } -} \ No newline at end of file + + public void start(Stage primaryStage){ + primaryStage = initializeShip(primaryStage); + primaryStage.show(); + } +} diff --git a/src/StartGUI.java b/src/StartGUI.java index 7037cda..de9b167 100644 --- a/src/StartGUI.java +++ b/src/StartGUI.java @@ -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() { @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"); } }); diff --git a/src/ShopGUI.java b/src/TaipanShopGUI.java similarity index 97% rename from src/ShopGUI.java rename to src/TaipanShopGUI.java index 2d2df5b..9dbe358 100644 --- a/src/ShopGUI.java +++ b/src/TaipanShopGUI.java @@ -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() { @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"); } }); diff --git a/src/TravelGUI.java b/src/TravelGUI.java index a4e6c4e..a8dda91 100644 --- a/src/TravelGUI.java +++ b/src/TravelGUI.java @@ -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(); + } } From 5e33374e3c433fa5b80568a07d8e196fc4376da3 Mon Sep 17 00:00:00 2001 From: Nathan Lum <33772546+Templarre@users.noreply.github.com> Date: Sun, 10 Mar 2019 17:27:17 -0600 Subject: [PATCH 2/3] Add files via upload --- src/WarehouseGUI.java | 221 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 src/WarehouseGUI.java diff --git a/src/WarehouseGUI.java b/src/WarehouseGUI.java new file mode 100644 index 0000000..72a93bd --- /dev/null +++ b/src/WarehouseGUI.java @@ -0,0 +1,221 @@ + +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.scene.text.Font; +import javafx.scene.text.Text; + +public class WarehouseGUI extends BorderPane { + + private final Text text; + private final HBox hBox; + private final Button button; + private final Button button0; + private final VBox vBox; + private final Text text0; + private final Text text1; + private final Label label; + private final Label label0; + private final Label label1; + private final Label label2; + private final VBox vBox0; + private final Text text2; + private final Text text3; + private final Text text4; + private final Text text5; + private final Text text6; + private final Text text7; + private final VBox vBox1; + private final Text text8; + private final Text text9; + + public WarehouseGUI() { + + text = new Text(); + hBox = new HBox(); + button = new Button(); + button0 = new Button(); + vBox = new VBox(); + text0 = new Text(); + text1 = new Text(); + label = new Label(); + label0 = new Label(); + label1 = new Label(); + label2 = new Label(); + vBox0 = new VBox(); + text2 = new Text(); + text3 = new Text(); + text4 = new Text(); + text5 = new Text(); + text6 = new Text(); + text7 = new Text(); + vBox1 = new VBox(); + text8 = new Text(); + text9 = new Text(); + + setMaxHeight(USE_PREF_SIZE); + setMaxWidth(USE_PREF_SIZE); + setMinHeight(USE_PREF_SIZE); + setMinWidth(USE_PREF_SIZE); + setPrefHeight(480.0); + setPrefWidth(600.0); + + BorderPane.setAlignment(text, javafx.geometry.Pos.CENTER); + text.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text.setStrokeWidth(0.0); + text.setText("Hong Kong Warehouse"); + text.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text.setWrappingWidth(393.63671875); + text.setFont(new Font(24.0)); + setTop(text); + + BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER); + hBox.setAlignment(javafx.geometry.Pos.CENTER); + hBox.setPrefHeight(100.0); + hBox.setPrefWidth(200.0); + + button.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER); + button.setMnemonicParsing(false); + button.setPrefWidth(250.0); + button.setText("Withdraw"); + + button0.setMnemonicParsing(false); + button0.setPrefWidth(250.0); + button0.setText("Deposit"); + button0.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + setBottom(hBox); + + BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER_LEFT); + vBox.setMaxHeight(USE_PREF_SIZE); + vBox.setMaxWidth(USE_PREF_SIZE); + vBox.setMinHeight(USE_PREF_SIZE); + vBox.setMinWidth(USE_PREF_SIZE); + vBox.setPrefHeight(156.0); + vBox.setPrefWidth(106.0); + + text0.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text0.setStrokeWidth(0.0); + text0.setText("Player"); + text0.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text0.setWrappingWidth(103.47265625); + text0.setFont(new Font(18.0)); + + text1.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text1.setStrokeWidth(0.0); + text1.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text1.setWrappingWidth(103.47265625); + text1.setFont(new Font(18.0)); + + label.setAlignment(javafx.geometry.Pos.CENTER); + label.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER); + label.setPrefWidth(100.0); + label.setText("Opium"); + label.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + label.setFont(new Font(18.0)); + + label0.setAlignment(javafx.geometry.Pos.CENTER); + label0.setPrefWidth(100.0); + label0.setText("Silk"); + label0.setFont(new Font(18.0)); + + label1.setAlignment(javafx.geometry.Pos.CENTER); + label1.setPrefWidth(100.0); + label1.setText("Arms"); + label1.setFont(new Font(18.0)); + + label2.setAlignment(javafx.geometry.Pos.CENTER); + label2.setPrefWidth(100.0); + label2.setText("General"); + label2.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + label2.setFont(new Font(18.0)); + setLeft(vBox); + + BorderPane.setAlignment(vBox0, javafx.geometry.Pos.TOP_LEFT); + vBox0.setAlignment(javafx.geometry.Pos.CENTER); + vBox0.setMaxHeight(USE_PREF_SIZE); + vBox0.setMaxWidth(USE_PREF_SIZE); + vBox0.setMinHeight(USE_PREF_SIZE); + vBox0.setMinWidth(USE_PREF_SIZE); + vBox0.setPrefHeight(343.0); + vBox0.setPrefWidth(261.0); + + text2.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text2.setStrokeWidth(0.0); + text2.setText("Warehouse"); + text2.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text2.setWrappingWidth(103.47265625); + text2.setFont(new Font(18.0)); + + text3.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text3.setStrokeWidth(0.0); + text3.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text3.setWrappingWidth(103.47265625); + text3.setFont(new Font(18.0)); + + text4.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text4.setStrokeWidth(0.0); + text4.setText("Opium"); + text4.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text4.setWrappingWidth(103.47265625); + text4.setFont(new Font(18.0)); + + text5.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text5.setStrokeWidth(0.0); + text5.setText("Silk"); + text5.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text5.setWrappingWidth(103.47265625); + text5.setFont(new Font(18.0)); + + text6.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text6.setStrokeWidth(0.0); + text6.setText("Arms"); + text6.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text6.setWrappingWidth(103.47265625); + text6.setFont(new Font(18.0)); + + text7.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text7.setStrokeWidth(0.0); + text7.setText("General"); + text7.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); + text7.setWrappingWidth(103.47265625); + text7.setFont(new Font(18.0)); + setCenter(vBox0); + + BorderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER); + vBox1.setMaxHeight(USE_PREF_SIZE); + vBox1.setMaxWidth(USE_PREF_SIZE); + vBox1.setPrefHeight(48.0); + vBox1.setPrefWidth(152.0); + + text8.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text8.setStrokeWidth(0.0); + text8.setText("In use:"); + text8.setFont(new Font(18.0)); + + text9.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE); + text9.setStrokeWidth(0.0); + text9.setText("Vacant:"); + text9.setFont(new Font(18.0)); + setRight(vBox1); + + hBox.getChildren().add(button); + hBox.getChildren().add(button0); + vBox.getChildren().add(text0); + vBox.getChildren().add(text1); + vBox.getChildren().add(label); + vBox.getChildren().add(label0); + vBox.getChildren().add(label1); + vBox.getChildren().add(label2); + vBox0.getChildren().add(text2); + vBox0.getChildren().add(text3); + vBox0.getChildren().add(text4); + vBox0.getChildren().add(text5); + vBox0.getChildren().add(text6); + vBox0.getChildren().add(text7); + vBox1.getChildren().add(text8); + vBox1.getChildren().add(text9); + + } +} From a0e0ab517db989556d127d36d80314e69e14a691 Mon Sep 17 00:00:00 2001 From: Solargale Date: Sun, 10 Mar 2019 17:35:46 -0600 Subject: [PATCH 3/3] Merged Travel and Ship warfare --- src/ShipWarfareGUI.java | 240 +--------------------------------------- src/TravelGUI.java | 61 ++++++---- 2 files changed, 41 insertions(+), 260 deletions(-) diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java index 5fe22b4..92536cb 100644 --- a/src/ShipWarfareGUI.java +++ b/src/ShipWarfareGUI.java @@ -1,7 +1,3 @@ - -import javafx.animation.PathTransition; -import javafx.animation.Timeline; -import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; @@ -13,20 +9,9 @@ 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; - -@SuppressWarnings("Duplicates") -public class ShipWarfareGUI extends Application { +public class ShipWarfareGUI { private Player player = new Player(); @@ -66,9 +51,9 @@ public class ShipWarfareGUI extends Application { private int startingPeasantShips = 0; private int startingLittyShips = 0; private int howMuchRun = 0; + private int counter = 0; private String pirateName = "Liu Yen"; - /** * setter method for player * @param player object of the class Player @@ -87,105 +72,10 @@ public class ShipWarfareGUI extends Application { return playerDummy; } - /** - * This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits - * @throws Exception in case of errors due to the delay - */ - public void peasantFleetAttack() throws Exception { - Scanner userResponse = new Scanner(System.in); - setNumOfPeasantShips(numOfShips()); - - title.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(), numOfPeasantShips, player.getHP())); - fightOrRunMessage(); - while (true) { - String response = userResponse.nextLine(); - if (response.equalsIgnoreCase("f")) { - userAttacks = true; - System.out.println("Ohh, fight ehh?"); - boolean winOrLose = destroyPeasantShipsOrEscape(); - if (winOrLose == true) { - break; - } - - - } else if (response.equalsIgnoreCase("r")) { - if (runFromShips() == false) { - System.out.println("Couldn't run away!"); - if (destroyPeasantShipsOrEscape()) - break; - } else { - System.out.println("Phew! Got away safely"); - break; - } - - } - - } - - - } - - /** - * This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits - * @throws Exception in case of errors due to the delay - */ - public void littyFleetAttack() throws Exception { - Scanner userResponse = new Scanner(System.in); - setNumOfLittyShips(numOfShips()); - System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfLittyShips, pirateName, player.getHP()); - fightOrRunMessage(); - while (true) { - String response = userResponse.nextLine(); - if (response.equalsIgnoreCase("f")) { - userAttacks = true; - System.out.println("Ohh, fight ehh?"); - boolean winOrLose = destroyLittyShipsOrEscape(); - if (winOrLose == true) { - break; - } - - - } else if (response.equalsIgnoreCase("r")) { - if (runFromShips() == false) { - System.out.println("Couldn't run away!"); - if (destroyLittyShipsOrEscape()) - break; - } else { - System.out.println("Phew! Got away safely"); - break; - } - - } - - } - - - } - - /** - * Asks user if they would like to fight or run against ships - */ - - public void fightOrRunMessage() { - System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)\n", player.getGuns()); - - } - - /** - * setter method that takes in an integer as an argument - * @param numOfLittyShips the number of ships to be used in the litty fleet attack - */ - public void setNumOfLittyShips(int numOfLittyShips) { - this.numOfLittyShips = numOfLittyShips; - startingLittyShips = numOfLittyShips; - - } - /** * setter method that takes in an integer as an argument * @param numOfPeasantShips the number of ships to be used in the peasant fleet attack */ - public void setNumOfPeasantShips(int numOfPeasantShips){ counter1++; this.numOfPeasantShips = numOfPeasantShips; @@ -226,7 +116,6 @@ public class ShipWarfareGUI extends Application { * One in two chance of running away * @return true if the user is allowed to run, false if not, the "default" is false */ - public boolean runFromShips() { userAttacks = false; Random randomValue = new Random(); @@ -239,130 +128,9 @@ public class ShipWarfareGUI extends Application { return false; } - /** - * The user faces off against the litty ships and either prevails, dies, or runs away - * 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; - - - Scanner userInput = new Scanner(System.in); - Random randomValue = new Random(); - int exitValue = 0; - - //Player volley - while (exitValue == 0) { - if (player.getGuns() > 0) { - for (int j = 0; j < player.getGuns(); j++) { - if (userAttacks == true) { - int hitOrMiss = randomValue.nextInt(3) + 1; - if (hitOrMiss == 1) { - numOfLittyShips--; - if (numOfLittyShips <= 0) { - exitValue = 1; - break; - } - System.out.println("Got eem"); - } else if (hitOrMiss == 2) { - System.out.printf("ARRG! We missed %s\n", player.getName()); - } else { - System.out.println("Darn! Their fleet tanked our attack"); - } - - - } else { - continue; - } - } - } else { - System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName()); - } - - - if (numOfLittyShips <= 0) { - exitValue = 1; - break; - } - if (player.getGuns() > 0) { - if (chanceOfEnemyRun == 2) { - chanceOfEnemyRun = randomValue.nextInt(2) + 1; - howMuchRun = randomValue.nextInt(10) + 1; - if (howMuchRun != 0 && howMuchRun < numOfLittyShips) { - - - setNumOfLittyShips(numOfLittyShips - howMuchRun); - if (userAttacks == true) { - System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, player.getName()); - } else { - System.out.printf("Escaped %d of them!\n", howMuchRun); - } - } - } - } - - System.out.printf("%d ships remaining\n", numOfLittyShips); - System.out.println("Oh no, they are taking the offensive!"); - //Computer volley - int takeGunChance = randomValue.nextInt(4) + 1; - if (takeGunChance == 1 && player.getGuns() > 0) { - player.setGuns(player.getGuns() - 1); - System.out.println("Dang it! They destroyed one of our guns"); - } else { - player.setHP(player.getHP() - (1 + randomValue.nextInt(15))); - } - if (player.getHP() <= 0) { - exitValue = 2; - break; - } - System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); - if (userAttacks == false) { - userAttacks = true; - } - - System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns()); - - String response = userInput.nextLine(); - if (response.equalsIgnoreCase("r")) { - if (runFromShips() == false) { - System.out.println("Couldn't run away"); - } else { - System.out.println("Phew! Got away safely"); - break; - } - } - - - } - - - 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()); - calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300; - player.setMoney(player.getMoney() + calculateLoot); - System.out.printf("We got $%,d!\n", calculateLoot); - return true; - } else if (exitValue == 2) { - player.gameOver(); - - return true; - } else if (exitValue == 3) { - System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); - return true; - } - return false; - - - } - /** * Sets most of the labels invisible except for the "fight or run" label */ - public void wipe(){ title.setVisible(false); runAwayOrLeft.setVisible(false); @@ -513,10 +281,6 @@ public class ShipWarfareGUI extends Application { return false; } - - private int counter = 0; - - public Stage initializeShip(Stage stage){ setNumOfPeasantShips(numOfShips()); diff --git a/src/TravelGUI.java b/src/TravelGUI.java index a8dda91..5a5dbf6 100644 --- a/src/TravelGUI.java +++ b/src/TravelGUI.java @@ -34,7 +34,10 @@ public class TravelGUI{ private Button quitButton = new Button(); private Button continueButton = new Button(); private TextField numberInput = new TextField(); - private int nextScene = 0; + + private Boolean peasantShipScene = false; + private Boolean littyShipScene = false; + private Boolean shopScene = false; public TravelGUI(Player player) { @@ -162,13 +165,20 @@ public class TravelGUI{ stage.show(); }); - //Continues on to either shop or shipwarefare - continueButton.setOnKeyPressed(event -> { - + //Continues on to either shop or shipwarfare + continueButton.setOnAction(event -> { + if(peasantShipScene){ + ShipWarfareGUI ship = new ShipWarfareGUI(player); + ship.initializeShip(stage); + stage.show(); + } + else if(shopScene){ + TaipanShopGUI shop = new TaipanShopGUI(player); + shop.initializeShop(stage); + stage.show(); + } }); - - //Text input for where the player needs to go. numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT); numberInput.setText("Enter preferred location."); @@ -188,6 +198,7 @@ public class TravelGUI{ hasTraveled = seaAtlas(response); player.setBank((int) (player.getBank() * 1.01)); player.setDebt((int) (player.getDebt() * 1.01)); + shopScene = true; } else{ textOut.setText(" " + "You're already here " + player.getName()); textOut.setText(textOut.getText() + ", 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?"); @@ -196,9 +207,13 @@ public class TravelGUI{ textOut.setText(" " + "Sorry, " + player.getName() + " could you say that again?"); } if (hasTraveled) { - TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player); - taipanShopGUI.initializeShop(stage); - stage.show(); + continueButton.setVisible(true); + quitButton.setVisible(false); + numberInput.setVisible(false); + shopScene = true; + //TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player); + //taipanShopGUI.initializeShop(stage); + //stage.show(); } } } @@ -271,7 +286,7 @@ public class TravelGUI{ textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP); textOut.setPrefHeight(163.0); textOut.setPrefWidth(583.0); - 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?"); + 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.setFont(size14); anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle); @@ -305,31 +320,31 @@ public class TravelGUI{ private Boolean seaAtlas(int locationOfTravel) { switch (locationOfTravel) { case 1: - textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong"); + if(!peasantShipScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong"); player.setLocation(1); return true; case 2: - textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai"); + if(!peasantShipScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai"); player.setLocation(2); return true; case 3: - textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki"); + if(!peasantShipScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki"); player.setLocation(3); return true; case 4: - textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon"); + if(!peasantShipScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon"); player.setLocation(4); return true; case 5: - textOut.setText( textOut.getText() + "\n " + "Arriving at Manila"); + if(!peasantShipScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila"); player.setLocation(5); return true; case 6: - textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore"); + if(!peasantShipScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore"); player.setLocation(6); return true; case 7: - textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia"); + if(!peasantShipScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia"); player.setLocation(7); return true; default: @@ -348,10 +363,12 @@ public class TravelGUI{ Random rand = new Random(); int randGenNum = rand.nextInt(3) + 1; if (randGenNum == 1) { - ShipWarfareGUI ship = new ShipWarfareGUI(player); - ship.initializeShip(stage); - stage.show(); - System.out.println(textOut.getText() + "\n " + "PLACEHOLDER FOR SHIPWARFARE"); + continueButton.setVisible(true); + quitButton.setVisible(false); + numberInput.setVisible(false); + peasantShipScene = true; + textOut.setText(" We see a ship on the horizon " + player.getName() + "; Prepare for combat!"); + //System.out.println(textOut.getText() + "\n " + "PLACEHOLDER FOR SHIPWARFARE"); }else if (randGenNum == 2) { disaster(locationOfTravel); textOut.setText(textOut.getText() + "\n " + "We made it!"); @@ -367,7 +384,7 @@ public class TravelGUI{ **/ private void disaster(int locationOfTravel) { //Tells player that there is a storm approaching. - textOut.setText(textOut.getText() + "\n " + "Storm " + player.getName() + "! "); + textOut.setText(" " + "Storm " + player.getName() + "! "); Random rand = new Random(); int randGenNum = rand.nextInt(5) + 1;