diff --git a/src/GameEndGUI.java b/src/GameEndGUI.java new file mode 100644 index 0000000..e45faa9 --- /dev/null +++ b/src/GameEndGUI.java @@ -0,0 +1,106 @@ + +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Font; +import javafx.stage.Stage; + +public class GameEndGUI { + + private Label title; + private VBox vBox; + private Label firmName; + private Label gunsHeld; + private Label netWorth; + private BorderPane borderPane; + private Player player; + + public GameEndGUI(Player player) { + Player playerDummy = new Player(player); + this.player = playerDummy; + } + + public void setPlayer(Player player) { + Player playerDummy = new Player(player); + this.player = playerDummy; + } + + public Player getPlayer(){ + Player playerDummy = new Player(player); + return playerDummy; + } + + + public Stage initializeGameEndGUI(Stage stage){ + + title = new Label(); + vBox = new VBox(); + firmName = new Label(); + gunsHeld = new Label(); + netWorth = new Label(); + borderPane = new BorderPane(); + int netWorthInt = 0; + + borderPane.setPrefHeight(480.0); + borderPane.setPrefWidth(600.0); + + BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER); + title.setText("Game Over!"); + title.setFont(new Font(43.0)); + BorderPane.setMargin(title, new Insets(0.0)); + title.setPadding(new Insets(50.0, 0.0, 0.0, 0.0)); + borderPane.setTop(title); + + BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER); + vBox.setAlignment(javafx.geometry.Pos.CENTER); + vBox.setPrefHeight(200.0); + vBox.setPrefWidth(100.0); + + firmName.setText("Name:"); + firmName.setFont(new Font(22.0)); + + gunsHeld.setText("Guns Held:"); + gunsHeld.setFont(new Font(22.0)); + + netWorth.setText("Net Worth:"); + netWorth.setFont(new Font(22.0)); + borderPane.setCenter(vBox); + + + vBox.getChildren().add(firmName); + vBox.getChildren().add(gunsHeld); + vBox.getChildren().add(netWorth); + + if(player.getHP() <= 0){ + title.setText("Game Over!"); + } + else{ + title.setText("Congratulations!"); + } + + netWorthInt = player.getMoney() + (player.getOpiumHeld()*16000) + (player.getSilkHeld()*160) + (player.getArmsHeld()*160) + (player.getGeneralHeld()* 8); + netWorthInt += (player.getwOpium()*16000) + (player.getwSilk()*160) + (player.getwArms()*160) + (player.getwGeneral()* 8); + netWorthInt -= player.getDebt(); + + firmName.setText("Firm Name: " + player.getName()); + gunsHeld.setText("Guns Held: " + player.getGuns()); + netWorth.setText("Net Worth: " + netWorthInt); + + Scene root = new Scene(borderPane, 600, 480); + + stage.setTitle("End Game Stats"); + stage.setResizable(false); + stage.setScene(root); + + return stage; + } + + + public void start(Stage primaryStage) { + GameEndGUI gameEndGUI = new GameEndGUI(player); + gameEndGUI.initializeGameEndGUI(primaryStage); + primaryStage.show(); + } +} diff --git a/src/Player.java b/src/Player.java index 5582a9f..f06d49f 100644 --- a/src/Player.java +++ b/src/Player.java @@ -2,7 +2,7 @@ public class Player { private String name = "Taipan"; private int bank = 0; - private int money = 1000000; + private int money = 0; private int opiumHeld = 0; private int silkHeld = 0; private int generalHeld = 0; diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java index 11d66ab..44fe25b 100644 --- a/src/ShipWarfareGUI.java +++ b/src/ShipWarfareGUI.java @@ -163,7 +163,7 @@ public class ShipWarfareGUI { * @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 { + public boolean destroyPeasantShipsOrEscape(Stage stage) throws Exception { int calculateLoot = 0; int chanceOfEnemyRun = 0; int hitCounter = 0; @@ -278,7 +278,9 @@ public class ShipWarfareGUI { continueButton.setVisible(true); return true; } else if (exitValue == 2) { - player.gameOver(); + GameEndGUI gameEndGUI = new GameEndGUI(player); + gameEndGUI.initializeGameEndGUI(stage); + stage.show(); return true; } else if (exitValue == 3) { System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); @@ -377,7 +379,7 @@ public class ShipWarfareGUI { counter++; chooseFightOrRun.setText("Ohh, Fight ehh?"); try { - if (destroyPeasantShipsOrEscape()){ + if (destroyPeasantShipsOrEscape(stage)){ completeWipe(); continueButton.setVisible(true); fightButton.setVisible(false); @@ -415,7 +417,7 @@ public class ShipWarfareGUI { chooseFightOrRun.setVisible(false); report.setText(("Couldn't run away")); try { - if(destroyPeasantShipsOrEscape()==true){ + if(destroyPeasantShipsOrEscape(stage)==true){ completeWipe(); continueButton.setVisible(true); fightButton.setVisible(false); diff --git a/src/StartGUI.java b/src/StartGUI.java index 9f8ca2b..992b1ad 100644 --- a/src/StartGUI.java +++ b/src/StartGUI.java @@ -1,5 +1,3 @@ - -import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; @@ -60,7 +58,6 @@ public class StartGUI { } } - /* ** * Copy constructor. @@ -80,6 +77,9 @@ public class StartGUI { hBox.setPrefWidth(200.0); hBox.setSpacing(10.0); + borderPane.setPrefHeight(480.0); + borderPane.setPrefWidth(600.0); + nameField.setPromptText("Enter your name."); nameField.setText("Taipan"); diff --git a/src/TravelGUI.java b/src/TravelGUI.java index 4bcca68..90ae4a7 100644 --- a/src/TravelGUI.java +++ b/src/TravelGUI.java @@ -186,9 +186,13 @@ public class TravelGUI{ numberInput.setOnKeyPressed(event -> { if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) { int response; - response = Integer.parseInt(numberInput.getText().replace(" ", "")); + try { + response = Integer.parseInt(numberInput.getText().replace(" ", "")); + } + catch (Exception e){ + response = 0; + } boolean hasTraveled = false; - //Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory. if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){ //Just in case the player types something that was not intended. It will refresh the question and ask it again