-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
93 lines (75 loc) · 3.4 KB
/
Main.java
File metadata and controls
93 lines (75 loc) · 3.4 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
/**
* Nii Oye Kpakpo
*/
import edu.ncat.brickbreakerbackend.BrickBreakerIO;
import edu.ncat.brickbreakerbackend.GameProfiles;
import edu.ncat.brickbreakerbackend.Level;
import edu.ncat.brickbreakerbackend.PlayerProfile;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Main extends Application {
private Stage primaryStage;
private GameProfiles profiles;
private PlayerProfile playerProfile;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
profiles = new GameProfiles();
// Load the levels from configuration file
Level[] levels = BrickBreakerIO.readConfigFile("brickbreaker.txt");
if (levels.length > 0) {
// Display ProfilePane
ProfilePane profilePane = new ProfilePane("brickbreakerprofiles.txt", "brickbreaker.txt", profiles);
profilePane.setProfileSelectedListener(this::onProfileSelected); // Listen for profile selection
Scene profileScene = new Scene(profilePane, 400, 400);
primaryStage.setTitle("Player Selection");
primaryStage.setScene(profileScene);
primaryStage.show();
} else {
System.out.println("No levels found in the configuration file.");
}
}
// Handle profile selection
private void onProfileSelected(PlayerProfile selectedProfile) {
// Create a new stage to display the profile details
Stage profileStage = new Stage();
profileStage.setTitle("Player Profile: " + selectedProfile.getName());
if (selectedProfile == null) {
Text label = new Text();
label.setText("No valid profile selected.");
return; // Exit early if profile is null
}
// Create a TextArea to display the selected profile
TextArea profileTextArea = new TextArea();
profileTextArea.setEditable(false); // Disable editing
profileTextArea.appendText("Name: " + selectedProfile.getName() + "\n");
profileTextArea.appendText("High Score: " + selectedProfile.getHighScore() + "\n");
profileTextArea.appendText("Games Played: " + selectedProfile.getNumGamesPlayed() + "\n");
// Set up the profile scene and show the profile window
Scene profileScene = new Scene(profileTextArea, 300, 250);
profileStage.setScene(profileScene);
profileStage.show();
// When profile details are closed, transition to the GameBoard
profileStage.setOnCloseRequest(event -> openGameBoard(selectedProfile));
}
// Transition to the GameBoard after profile is viewed
private void openGameBoard(PlayerProfile selectedProfile) {
// Load the levels
Level[] levels = BrickBreakerIO.readConfigFile("brickbreaker.txt");
if (levels.length > 0) {
// Initialize the GameBoard with the selected profile
GameBoard gameBoard = new GameBoard(levels, profiles, "brickbreakerprofiles.txt", selectedProfile);
Scene gameScene = new Scene(gameBoard, 700, 600);
primaryStage.setTitle("Brick Breaker Game" );
primaryStage.setScene(gameScene);
primaryStage.show();
}
}
public static void main(String[] args) {
launch(args);
}
}