A lot of errors but easily fixable SHipwarfareGUI
This commit is contained in:
@@ -29,13 +29,16 @@ public class ShipWarfareGUI {
|
||||
private Label gunsLeftOrTaken;
|
||||
private Label continueToFight;
|
||||
private int counter1;
|
||||
private Button continueButton;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* 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;
|
||||
@@ -175,6 +178,8 @@ public class ShipWarfareGUI {
|
||||
HPLeft.setVisible(true);
|
||||
gunsLeftOrTaken.setVisible(true);
|
||||
continueToFight.setVisible(true);
|
||||
continueButton.setVisible(false);
|
||||
|
||||
|
||||
runAwayOrLeft.setText("No ships ran away");
|
||||
|
||||
@@ -270,12 +275,14 @@ public class ShipWarfareGUI {
|
||||
calculateLoot = (startingPeasantShips *100) + randomValue.nextInt(startingPeasantShips) *200;
|
||||
player.setMoney(player.getMoney() + calculateLoot);
|
||||
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
|
||||
continueButton.setVisible(true);
|
||||
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());
|
||||
continueButton.setVisible(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -302,6 +309,10 @@ public class ShipWarfareGUI {
|
||||
HPLeft = new Label();
|
||||
gunsLeftOrTaken = new Label();
|
||||
continueToFight = new Label();
|
||||
continueButton = new Button();
|
||||
|
||||
continueButton.setVisible(false);
|
||||
|
||||
|
||||
|
||||
BorderPane.setPrefHeight(400.0);
|
||||
@@ -317,6 +328,9 @@ public class ShipWarfareGUI {
|
||||
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));
|
||||
|
||||
continueButton.setMnemonicParsing(false);
|
||||
continueButton.setText("Continue?");
|
||||
|
||||
fightButton.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
fightButton.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||
fightButton.setId("Button1");
|
||||
@@ -353,6 +367,8 @@ public class ShipWarfareGUI {
|
||||
vBox.getChildren().add(HPLeft);
|
||||
vBox.getChildren().add(gunsLeftOrTaken);
|
||||
vBox.getChildren().add(continueToFight);
|
||||
vBox.getChildren().add(continueButton);
|
||||
|
||||
|
||||
//Fight
|
||||
fightButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@@ -361,7 +377,20 @@ public class ShipWarfareGUI {
|
||||
counter++;
|
||||
chooseFightOrRun.setText("Ohh, Fight ehh?");
|
||||
try {
|
||||
destroyPeasantShipsOrEscape();
|
||||
if (destroyPeasantShipsOrEscape()){
|
||||
completeWipe();
|
||||
continueButton.setVisible(true);
|
||||
continueButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||
shop.initializeShop(stage);
|
||||
stage.show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
@@ -384,12 +413,27 @@ public class ShipWarfareGUI {
|
||||
chooseFightOrRun.setVisible(false);
|
||||
report.setText(("Couldn't run away"));
|
||||
try {
|
||||
destroyPeasantShipsOrEscape();
|
||||
if(destroyPeasantShipsOrEscape()==true){
|
||||
completeWipe();
|
||||
continueButton.setVisible(true);
|
||||
continueButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||
shop.initializeShop(stage);
|
||||
stage.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} else {
|
||||
completeWipe();
|
||||
report.setText("Phew! Got away safely");
|
||||
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||
shop.initializeShop(stage);
|
||||
stage.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user