-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.java
More file actions
100 lines (83 loc) · 3.33 KB
/
Copy pathball.java
File metadata and controls
100 lines (83 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.example.ballpane;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Screen;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
public class ball extends Application {
GamePane gamePane; Label score;
@Override
public void start(Stage primaryStage) throws IOException {
gamePane = new GamePane();
Image image = new Image("backGround.jpg");
ImageView imageview = new ImageView(image);
imageview.setPreserveRatio(false);
imageview.fitWidthProperty().bind(primaryStage.widthProperty());
imageview.fitHeightProperty().bind(primaryStage.heightProperty());
gamePane.setOnMouseClicked(e-> {
gamePane.selector(e.getX(),e.getY());
setScore();
});
Font font = new Font(20);
score = new Label("Score: " + gamePane.getScore());
score.setFont(font);
score.setTextFill(Color.WHEAT);
CircleWithText redCircle = new CircleWithText(new Circle(40,Color.RED),new Text("5"));
CircleWithText blueCircle = new CircleWithText(new Circle(40,Color.BLUE),new Text("10"));
CircleWithText greenCircle = new CircleWithText(new Circle(40,Color.GREEN),new Text("15"));
CircleWithText cyanCircle = new CircleWithText(new Circle(40,Color.CYAN),new Text("20"));
VBox vBox = new VBox(redCircle,blueCircle,greenCircle,cyanCircle);
Button play = new Button("Play");
play.setStyle("-fx-font-family: Arial; -fx-font-size: 20px;");
play.setPrefSize(100,50);
play.setOnMouseClicked(e -> {gamePane.startGame();setScore();});
HBox hBox = new HBox(score,play);
BorderPane borderPane = new BorderPane();
borderPane.getChildren().add(imageview);
borderPane.setCenter(gamePane);
borderPane.setRight(vBox);
hBox.setAlignment(Pos.CENTER);
borderPane.setBottom(hBox);
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
// Set the stage dimensions to match the screen dimensions
primaryStage.setX(screenBounds.getMinX());
primaryStage.setY(screenBounds.getMinY());
primaryStage.setWidth(screenBounds.getWidth());
primaryStage.setHeight(screenBounds.getHeight());
Scene scene = new Scene(borderPane);
primaryStage.setScene(scene);
primaryStage.setTitle("Speed Click Game");
primaryStage.show();
}
public void setScore(){
score.setText("Score: "+gamePane.getScore());
}
public static void main(String[] args) {
launch();
}
}
class CircleWithText extends StackPane {
public CircleWithText(Circle circle, Text text) {
super(circle, text);
text.setFont(new Font(20));
setAlignment(Pos.CENTER);
}
}