Skip to content

Commit 2933b52

Browse files
committed
Added Triangle (#6)
- triangle.fxml - TriangleController.java - Triangle.java - Added class in Game.java Signed-off-by: Harsh Kumar <harsh19043@iiitd.ac.in>
1 parent 5b6f0a9 commit 2933b52

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed

src/Game.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
public class Game implements Serializable {
2020
private static final List<Class> map = Arrays.asList(
21-
Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class, DoubleCircleVertical.class
21+
Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class, DoubleCircleVertical.class,
22+
Triangle.class
2223
);
2324
private final Ball ball;
2425
private final long id;

src/obstacles/TestObstacle.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class TestObstacle extends Application {
1111
private Scene loadSampleObstacle() {
1212
GridPane pane = new GridPane();
13-
Obstacle obstacle = new CircleFlow();
13+
Obstacle obstacle = new Triangle();
1414
obstacle.attachToGrid(pane, 0, 0);
1515
return new Scene(pane, 500, 500);
1616
}

src/obstacles/Triangle.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package obstacles;
2+
3+
import elements.Ball;
4+
import obstacles.controllers.TriangleController;
5+
6+
public class Triangle extends Obstacle {
7+
private TriangleController triangleController;
8+
9+
public Triangle() {
10+
// Load the FXML and set 'pane' in Parent
11+
loadObstaclePane("/obstacles/fxml/triangle.fxml");
12+
13+
triangleController = (TriangleController) controller;
14+
}
15+
16+
@Override
17+
public int hasCollided(Ball b) {
18+
return 0;
19+
}
20+
}

src/obstacles/controllers/SuperController.java

+2
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,6 @@ protected void addScaling(Node node, int timeInMillis, double scaleFactor) {
7474
public void addRotation(Node node) {
7575
addRotation(node, defaultRotatingDuration, ((int) (Math.random()*2))==1?true:false);
7676
}
77+
78+
protected Pane getStar() {return star;}
7779
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package obstacles.controllers;
2+
3+
import javafx.fxml.FXML;
4+
import javafx.scene.layout.Pane;
5+
6+
import java.net.URL;
7+
import java.util.ResourceBundle;
8+
9+
public class TriangleController extends SuperController {
10+
@FXML
11+
public Pane triangle;
12+
13+
public TriangleController() {
14+
super();
15+
}
16+
17+
@Override
18+
public void initialize(URL url, ResourceBundle resourceBundle) {
19+
// Add transitions
20+
addRotation(triangle);
21+
loadStar();
22+
}
23+
}

src/obstacles/fxml/triangle.fxml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import java.net.*?>
4+
<?import javafx.geometry.*?>
5+
<?import javafx.scene.layout.*?>
6+
<?import javafx.scene.shape.*?>
7+
8+
<Pane xmlns:fx="http://javafx.com/fxml/1" maxHeight="350" maxWidth="350" minHeight="350" minWidth="350" xmlns="http://javafx.com/javafx/11.0.1" fx:controller="obstacles.controllers.TriangleController">
9+
10+
<stylesheets>
11+
<URL value="@../../style/style.css" />
12+
</stylesheets>
13+
14+
<Pane>
15+
<Pane fx:id="triangle" layoutX="-4.0" layoutY="16.0" prefHeight="350" prefWidth="350.0" scaleX="0.9" scaleY="0.9">
16+
<Rectangle arcHeight="5.0" arcWidth="5.0" height="350.0" layoutX="252.0" layoutY="-47.0" rotate="150.0" styleClass="fill-purple" width="28.0" />
17+
<Rectangle arcHeight="5.0" arcWidth="5.0" height="28.0" layoutX="5.0" layoutY="258.0" styleClass="fill-pink" width="350.0" />
18+
<Rectangle arcHeight="5.0" arcWidth="5.0" height="350.0" layoutX="81.0" layoutY="-45.0" rotate="30.0" styleClass="fill-yellow" width="28.0" />
19+
<padding>
20+
<Insets bottom="25.0" />
21+
</padding>
22+
</Pane>
23+
<Pane layoutX="137.0" layoutY="149.0" prefHeight="75" prefWidth="75">
24+
<Pane fx:id="star" />
25+
</Pane>
26+
</Pane>
27+
</Pane>

0 commit comments

Comments
 (0)