From 3b38c2475bd3084a72c69f6b160089586474eb1c Mon Sep 17 00:00:00 2001
From: KahootChampion
Date: Sat, 23 Mar 2019 22:12:51 -0600
Subject: [PATCH] Sep up the scene which will be used for animation
---
src/AnimationTesting.java | 190 +++++++++++++++++++++++++++++++++++++-
src/ShipWarfareGUI.java | 11 ++-
2 files changed, 197 insertions(+), 4 deletions(-)
diff --git a/src/AnimationTesting.java b/src/AnimationTesting.java
index 5af5d7c..751ad0e 100644
--- a/src/AnimationTesting.java
+++ b/src/AnimationTesting.java
@@ -1,17 +1,21 @@
import javafx.animation.TranslateTransition;
-import javafx.application.Application;
+
import javafx.geometry.Insets;
import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
+import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
+
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -22,8 +26,20 @@ public class AnimationTesting extends Player {
private HBox usAgainstEnemyDivisor;
private BorderPane centeringUserShipPane;
private Circle cannon;
- private BorderPane centeringMerchantShipPane;
+ private BorderPane centeringLittyShipPane;
private BorderPane encompassingPane;
+ private VBox buttonBox;
+ private HBox fightRunBox;
+ private Button fightButton;
+ private Button runButton;
+ private Button continueButton;
+ private VBox labelBox;
+ private Label title;
+ private Label HPLeft;
+ private Label gunsLeftOrTaken;
+ private Label runAwayOrLeft;
+ private Label shipsRemaining;
+ private Label report;
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
@@ -37,6 +53,176 @@ public class AnimationTesting extends Player {
}
+ public void startShipAnimation(Stage primaryStage) throws Exception {
+
+
+ Pane root = new Pane();
+ HBox usAgainstEnemyDivisor;
+ BorderPane centeringUserShipPane = new BorderPane();
+ Circle cannon;
+ BorderPane centeringLittyShipPane = new BorderPane();
+ BorderPane encompassingPane = new BorderPane();
+ usAgainstEnemyDivisor = new HBox();
+ cannon = new Circle();
+
+ buttonBox = new VBox();
+ fightRunBox = new HBox();
+ fightButton = new Button();
+ runButton = new Button();
+ continueButton = new Button();
+ labelBox = new VBox();
+ title = new Label();
+ HPLeft = new Label();
+ gunsLeftOrTaken = new Label();
+ runAwayOrLeft = new Label();
+ shipsRemaining = new Label();
+ report = new Label();
+
+ title.setText("7 ships from Liu Yuen's Fleet are attacking, Would you like to fight or run?");
+
+ HPLeft.setText("Ship Status: 100%");
+
+ gunsLeftOrTaken.setText("Guns: 5");
+
+ runAwayOrLeft.setText("6 Ships Ran Away:");
+
+ shipsRemaining.setText("Number Of Ships Remaining:");
+
+ report.setText("Report: Ships hit 4, Shots missed 1");
+
+
+
+ fightButton.setText("Fight");
+ runButton.setText("Run");
+ continueButton.setText("Continue");
+
+
+
+ final int USER_SHOOTS_X = 150;
+ final int USER_SHOOTS_Y = 245;
+
+ final int CLEAN_SHOT_X = 350;
+ final int CLEAN_SHOT_Y = 90;
+
+ encompassingPane.setAlignment(labelBox, javafx.geometry.Pos.CENTER);
+ labelBox.setAlignment(javafx.geometry.Pos.CENTER);
+ labelBox.setPrefHeight(41.0);
+ labelBox.setPrefWidth(600.0);
+ labelBox.setSpacing(20.0);
+
+ labelBox.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
+
+ encompassingPane.setAlignment(buttonBox, javafx.geometry.Pos.CENTER);
+ buttonBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
+
+ fightButton.setVisible(true);
+ runButton.setVisible(true);
+ continueButton.setVisible(true);
+
+ fightRunBox.setAlignment(javafx.geometry.Pos.CENTER);
+ fightRunBox.setPrefHeight(100.0);
+ fightRunBox.setPrefWidth(200.0);
+ fightRunBox.setSpacing(10.0);
+
+ VBox.setMargin(continueButton, new Insets(0.0, 0.0, 20.0, 0.0));
+
+
+
+ root.getChildren().add(cannon);
+
+ encompassingPane.setPrefHeight(480);
+ encompassingPane.setPrefWidth(600);
+
+
+ usAgainstEnemyDivisor.setPrefHeight(0.0);
+ usAgainstEnemyDivisor.setPrefWidth(600.0);
+
+ centeringUserShipPane.setPrefHeight(200.0);
+ centeringUserShipPane.setPrefWidth(200.0);
+
+ Image ourShip = new Image(new FileInputStream("src/images/ourShip.png"));
+ Image enemyShip = new Image(new FileInputStream("src/images/enemyShip.png"));
+
+
+ //Setting the image view
+ ImageView userShip = new ImageView(ourShip);
+ ImageView littyShip = new ImageView(enemyShip);
+
+ BorderPane.setAlignment(userShip, javafx.geometry.Pos.CENTER);
+ userShip.setFitHeight(150.0);
+ userShip.setFitWidth(248.0);
+ userShip.setPickOnBounds(true);
+ userShip.setPreserveRatio(true);
+ centeringUserShipPane.setCenter(userShip);
+
+ BorderPane.setAlignment(buttonBox, javafx.geometry.Pos.CENTER);
+ buttonBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
+
+ usAgainstEnemyDivisor.setTranslateY(-20.0);
+
+ cannon.setRadius(10.0);
+ cannon.setStroke(javafx.scene.paint.Color.BLACK);
+ cannon.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
+ centeringUserShipPane.setRight(cannon);
+
+ centeringLittyShipPane.setPrefHeight(200.0);
+ centeringLittyShipPane.setPrefWidth(200.0);
+ centeringLittyShipPane.setOpaqueInsets(new Insets(0.0));
+ HBox.setMargin(centeringLittyShipPane, new Insets(0.0, 0.0, 0.0, 200.0));
+
+ encompassingPane.setAlignment(littyShip, javafx.geometry.Pos.CENTER);
+ littyShip.setFitHeight(165.0);
+ littyShip.setFitWidth(180.0);
+ littyShip.setPickOnBounds(true);
+ littyShip.setPreserveRatio(true);
+ encompassingPane.setMargin(littyShip, new Insets(0.0, 0.0, 20.0, 0.0));
+ centeringLittyShipPane.setCenter(littyShip);
+
+ usAgainstEnemyDivisor.getChildren().add(centeringUserShipPane);
+ usAgainstEnemyDivisor.getChildren().add(centeringLittyShipPane);
+ fightRunBox.getChildren().add(fightButton);
+ fightRunBox.getChildren().add(continueButton);
+ fightRunBox.getChildren().add(runButton);
+ buttonBox.getChildren().add(fightRunBox);
+ labelBox.getChildren().add(title);
+ labelBox.getChildren().add(HPLeft);
+ labelBox.getChildren().add(gunsLeftOrTaken);
+ labelBox.getChildren().add(runAwayOrLeft);
+ labelBox.getChildren().add(shipsRemaining);
+ labelBox.getChildren().add(report);
+
+ encompassingPane.setTop(labelBox);
+ encompassingPane.setCenter(usAgainstEnemyDivisor);
+
+ encompassingPane.setBottom(buttonBox);
+
+ root.getChildren().addAll(encompassingPane, cannon);
+
+ // start
+ cannon.setLayoutX(USER_SHOOTS_X);
+ cannon.setLayoutY(USER_SHOOTS_Y);
+
+ TranslateTransition shotsFired = new TranslateTransition();
+
+ shotsFired.setDuration(Duration.seconds(3));
+ shotsFired.setToX(CLEAN_SHOT_X);
+ shotsFired.setToY(CLEAN_SHOT_Y);
+ shotsFired.setCycleCount(getGuns());
+ shotsFired.setNode(cannon);
+ shotsFired.play();
+
+
+
+ Scene scene = new Scene(root, 600, 480);
+ root.getStylesheets().add("styleguide.css");
+
+ primaryStage.setResizable(false);
+
+ primaryStage.setScene(scene);
+ primaryStage.show();
+
+ }
+
}
diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java
index bb2ad65..898f569 100644
--- a/src/ShipWarfareGUI.java
+++ b/src/ShipWarfareGUI.java
@@ -15,7 +15,6 @@ import javafx.util.Duration;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Random;
-import java.util.concurrent.TimeUnit;
/**
@@ -433,6 +432,13 @@ public class ShipWarfareGUI extends Player {
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
+ AnimationTesting test = new AnimationTesting(getPlayer());
+ try {
+ test.startShipAnimation(stage);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ stage.show();
try {
shipsAttackingOrRunningGif.setImage(new Image(new FileInputStream("src/images/ShipsAttacking.gif")));
@@ -564,6 +570,7 @@ public class ShipWarfareGUI extends Player {
stage.show();
});
}
+/*
public void startShipAnimation(Stage primaryStage) throws Exception {
@@ -652,7 +659,7 @@ public class ShipWarfareGUI extends Player {
primaryStage.show();
}
-
+ */
/**
* sets scene and runs stage
*