Added time stuff to Shipwarfare GUI

This commit is contained in:
KahootChampion
2019-03-09 15:00:00 -07:00
parent 6b9e3dcc06
commit 89188152e6

View File

@@ -12,6 +12,7 @@ import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import static javafx.application.Application.launch;
@@ -19,6 +20,7 @@ public class ShipWarfareGUI extends Application {
private Player player = new Player();
public static void main(String args[]) {
launch(args);
}
@@ -29,6 +31,14 @@ public class ShipWarfareGUI extends Application {
private Button button2;
private int counter = 0;
public void delayForSeconds(int num) {
try {
TimeUnit.SECONDS.sleep(num);
}catch(Exception e){
}
}
public int numOfShips() {
int numOfShipsAttacking = 0;
@@ -71,8 +81,7 @@ public class ShipWarfareGUI extends Application {
}
*/
public void start(Stage stage){
public void start(Stage stage) throws Exception {
BorderPane BorderPane = new BorderPane();
@@ -115,15 +124,19 @@ public class ShipWarfareGUI extends Application {
ShipWarfareGUI ship = new ShipWarfareGUI();
label1.setText(ship.numOfShips() + " Merchant Ships are attacking you.");
//Fight
button1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
counter++;
if (counter == 1) {
label1.setText("Ohh, fight ehh?");
delayForSeconds(10);
label1.setText("Tis been 10 seconds");
}
if(player.getHP() <= 0){
if (counter == 2) {
System.out.println("You pressed the button.");
button1.setVisible(false);
button2.setVisible(false);
@@ -133,6 +146,26 @@ public class ShipWarfareGUI extends Application {
}
});
//Flee
button2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
counter++;
if (counter == 1) {
label1.setText("Ohh, Run ehh?");
}
if (counter == 2) {
System.out.println("You pressed the button.");
button1.setVisible(false);
button2.setVisible(false);
button1.setDisable(true);
button2.setDisable(true);
}
}
});
Scene root = new Scene(BorderPane, 600, 480);
stage.setTitle("Ship");