From 2933b52f29bdac34951a92b67548454e47e6f321 Mon Sep 17 00:00:00 2001 From: Harsh Kumar Date: Thu, 3 Dec 2020 23:51:35 +0530 Subject: [PATCH] Added Triangle (#6) - triangle.fxml - TriangleController.java - Triangle.java - Added class in Game.java Signed-off-by: Harsh Kumar --- src/Game.java | 3 ++- src/obstacles/TestObstacle.java | 2 +- src/obstacles/Triangle.java | 20 ++++++++++++++ .../controllers/SuperController.java | 2 ++ .../controllers/TriangleController.java | 23 ++++++++++++++++ src/obstacles/fxml/triangle.fxml | 27 +++++++++++++++++++ 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/obstacles/Triangle.java create mode 100644 src/obstacles/controllers/TriangleController.java create mode 100644 src/obstacles/fxml/triangle.fxml diff --git a/src/Game.java b/src/Game.java index a8f0432..0d0d424 100644 --- a/src/Game.java +++ b/src/Game.java @@ -18,7 +18,8 @@ public class Game implements Serializable { private static final List map = Arrays.asList( - Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class, DoubleCircleVertical.class + Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class, DoubleCircleVertical.class, + Triangle.class ); private final Ball ball; private final long id; diff --git a/src/obstacles/TestObstacle.java b/src/obstacles/TestObstacle.java index a72b1d1..8ca86b9 100644 --- a/src/obstacles/TestObstacle.java +++ b/src/obstacles/TestObstacle.java @@ -10,7 +10,7 @@ public class TestObstacle extends Application { private Scene loadSampleObstacle() { GridPane pane = new GridPane(); - Obstacle obstacle = new CircleFlow(); + Obstacle obstacle = new Triangle(); obstacle.attachToGrid(pane, 0, 0); return new Scene(pane, 500, 500); } diff --git a/src/obstacles/Triangle.java b/src/obstacles/Triangle.java new file mode 100644 index 0000000..8c47102 --- /dev/null +++ b/src/obstacles/Triangle.java @@ -0,0 +1,20 @@ +package obstacles; + +import elements.Ball; +import obstacles.controllers.TriangleController; + +public class Triangle extends Obstacle { + private TriangleController triangleController; + + public Triangle() { + // Load the FXML and set 'pane' in Parent + loadObstaclePane("/obstacles/fxml/triangle.fxml"); + + triangleController = (TriangleController) controller; + } + + @Override + public int hasCollided(Ball b) { + return 0; + } +} diff --git a/src/obstacles/controllers/SuperController.java b/src/obstacles/controllers/SuperController.java index 885af9c..5afa991 100644 --- a/src/obstacles/controllers/SuperController.java +++ b/src/obstacles/controllers/SuperController.java @@ -74,4 +74,6 @@ protected void addScaling(Node node, int timeInMillis, double scaleFactor) { public void addRotation(Node node) { addRotation(node, defaultRotatingDuration, ((int) (Math.random()*2))==1?true:false); } + + protected Pane getStar() {return star;} } diff --git a/src/obstacles/controllers/TriangleController.java b/src/obstacles/controllers/TriangleController.java new file mode 100644 index 0000000..5f3b4f0 --- /dev/null +++ b/src/obstacles/controllers/TriangleController.java @@ -0,0 +1,23 @@ +package obstacles.controllers; + +import javafx.fxml.FXML; +import javafx.scene.layout.Pane; + +import java.net.URL; +import java.util.ResourceBundle; + +public class TriangleController extends SuperController { + @FXML + public Pane triangle; + + public TriangleController() { + super(); + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + // Add transitions + addRotation(triangle); + loadStar(); + } +} diff --git a/src/obstacles/fxml/triangle.fxml b/src/obstacles/fxml/triangle.fxml new file mode 100644 index 0000000..feb427c --- /dev/null +++ b/src/obstacles/fxml/triangle.fxml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +