Finished the End Game Screen

This commit is contained in:
2019-03-10 22:10:45 -06:00
parent 01ee9b2600
commit f4fbc474e7
5 changed files with 122 additions and 10 deletions

106
src/GameEndGUI.java Normal file
View File

@@ -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();
}
}

View File

@@ -4,7 +4,7 @@ public class Player {
private String name = "Taipan"; private String name = "Taipan";
private int bank = 0; private int bank = 0;
private int money = 1000000; private int money = 0;
private int opiumHeld = 0; private int opiumHeld = 0;
private int silkHeld = 0; private int silkHeld = 0;
private int generalHeld = 0; private int generalHeld = 0;

View File

@@ -163,7 +163,7 @@ public class ShipWarfareGUI {
* @return true if the user wins, loses, or flees, it returns false otherwise * @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the delay * @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 calculateLoot = 0;
int chanceOfEnemyRun = 0; int chanceOfEnemyRun = 0;
int hitCounter = 0; int hitCounter = 0;
@@ -278,7 +278,9 @@ public class ShipWarfareGUI {
continueButton.setVisible(true); continueButton.setVisible(true);
return true; return true;
} else if (exitValue == 2) { } else if (exitValue == 2) {
player.gameOver(); GameEndGUI gameEndGUI = new GameEndGUI(player);
gameEndGUI.initializeGameEndGUI(stage);
stage.show();
return true; return true;
} else if (exitValue == 3) { } else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
@@ -377,7 +379,7 @@ public class ShipWarfareGUI {
counter++; counter++;
chooseFightOrRun.setText("Ohh, Fight ehh?"); chooseFightOrRun.setText("Ohh, Fight ehh?");
try { try {
if (destroyPeasantShipsOrEscape()){ if (destroyPeasantShipsOrEscape(stage)){
completeWipe(); completeWipe();
continueButton.setVisible(true); continueButton.setVisible(true);
fightButton.setVisible(false); fightButton.setVisible(false);
@@ -415,7 +417,7 @@ public class ShipWarfareGUI {
chooseFightOrRun.setVisible(false); chooseFightOrRun.setVisible(false);
report.setText(("Couldn't run away")); report.setText(("Couldn't run away"));
try { try {
if(destroyPeasantShipsOrEscape()==true){ if(destroyPeasantShipsOrEscape(stage)==true){
completeWipe(); completeWipe();
continueButton.setVisible(true); continueButton.setVisible(true);
fightButton.setVisible(false); fightButton.setVisible(false);

View File

@@ -1,5 +1,3 @@
import javafx.application.Application;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.Scene; import javafx.scene.Scene;
@@ -60,7 +58,6 @@ public class StartGUI {
} }
} }
/* /*
** **
* Copy constructor. * Copy constructor.
@@ -80,6 +77,9 @@ public class StartGUI {
hBox.setPrefWidth(200.0); hBox.setPrefWidth(200.0);
hBox.setSpacing(10.0); hBox.setSpacing(10.0);
borderPane.setPrefHeight(480.0);
borderPane.setPrefWidth(600.0);
nameField.setPromptText("Enter your name."); nameField.setPromptText("Enter your name.");
nameField.setText("Taipan"); nameField.setText("Taipan");

View File

@@ -186,9 +186,13 @@ public class TravelGUI{
numberInput.setOnKeyPressed(event -> { 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;
response = Integer.parseInt(numberInput.getText().replace(" ", "")); try {
response = Integer.parseInt(numberInput.getText().replace(" ", ""));
}
catch (Exception e){
response = 0;
}
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(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){ 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 //Just in case the player types something that was not intended. It will refresh the question and ask it again