From a0e0ab517db989556d127d36d80314e69e14a691 Mon Sep 17 00:00:00 2001 From: Solargale Date: Sun, 10 Mar 2019 17:35:46 -0600 Subject: [PATCH] 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;