3
3
import com .stackedsuccess .Main ;
4
4
import com .stackedsuccess .SceneManager ;
5
5
import com .stackedsuccess .SceneManager .AppUI ;
6
- import java .io .IOException ;
7
- import javafx .fxml .FXML ;
8
- import javafx .fxml .FXMLLoader ;
9
- import javafx .scene .Parent ;
10
- import javafx .scene .control .Slider ;
11
- import javafx .scene .input .KeyCode ;
12
6
import java .io .BufferedReader ;
13
7
import java .io .FileReader ;
14
8
import java .io .IOException ;
24
18
import javafx .scene .input .KeyEvent ;
25
19
26
20
public class HomeScreenController {
27
- @ FXML Slider difficultySlider ;
21
+ @ FXML Slider difficultySlider ;
28
22
29
- @ FXML private Button pastScoresButton ;
30
- @ FXML private ListView <String > pastScores ;
23
+ @ FXML private Button pastScoresButton ;
24
+ @ FXML private ListView <String > pastScores ;
31
25
32
- @ FXML
33
- public void initialize () {
34
- difficultySlider .requestFocus ();
35
- List <String > scores = loadScoresFromFile ("score.txt" );
36
- pastScores .getItems ().addAll (scores );
37
- }
26
+ @ FXML
27
+ public void initialize () {
28
+ difficultySlider .requestFocus ();
29
+ List <String > scores = loadScoresFromFile ("score.txt" );
30
+ pastScores .getItems ().addAll (scores );
31
+ }
38
32
39
- /**
40
- * Reads scores from a file and returns them as a list of strings.
41
- *
42
- * @param filePath the path to the score file
43
- * @return list of scores as strings
44
- */
45
- private List <String > loadScoresFromFile (String filePath ) {
46
- List <String > scores = new ArrayList <>();
47
- try (BufferedReader reader = new BufferedReader (new FileReader (filePath ))) {
48
- String line ;
49
- while ((line = reader .readLine ()) != null ) {
50
- scores .add (line );
51
- }
52
- } catch (IOException e ) {
53
- throw new IllegalArgumentException ("Issue regarding Score file" , e );
54
- }
55
- return scores ;
33
+ /**
34
+ * Reads scores from a file and returns them as a list of strings.
35
+ *
36
+ * @param filePath the path to the score file
37
+ * @return list of scores as strings
38
+ */
39
+ private List <String > loadScoresFromFile (String filePath ) {
40
+ List <String > scores = new ArrayList <>();
41
+ try (BufferedReader reader = new BufferedReader (new FileReader (filePath ))) {
42
+ String line ;
43
+ while ((line = reader .readLine ()) != null ) {
44
+ scores .add (line );
45
+ }
46
+ } catch (IOException e ) {
47
+ throw new IllegalArgumentException ("Issue regarding Score file" , e );
56
48
}
49
+ return scores ;
50
+ }
57
51
58
52
public void exitGame () {
59
53
System .exit (0 );
@@ -70,23 +64,23 @@ public void startGame() throws IOException {
70
64
Main .setUi (AppUI .GAME );
71
65
}
72
66
73
- public void onKeyPressed (KeyEvent event ) {
74
- difficultySlider .requestFocus ();
75
- if (event .getCode () == KeyCode .SPACE ) {
76
- try {
77
- startGame ();
78
- } catch (IOException e ) {
79
- // Do nothing for now
80
- }
81
- }
67
+ public void onKeyPressed (KeyEvent event ) {
68
+ difficultySlider .requestFocus ();
69
+ if (event .getCode () == KeyCode .SPACE ) {
70
+ try {
71
+ startGame ();
72
+ } catch (IOException e ) {
73
+ // Do nothing for now
74
+ }
82
75
}
76
+ }
83
77
84
- @ FXML
85
- public void showPastScores () {
86
- if (pastScores .isVisible ()) {
87
- pastScores .setVisible (false );
88
- } else {
89
- pastScores .setVisible (true );
90
- }
78
+ @ FXML
79
+ public void showPastScores () {
80
+ if (pastScores .isVisible ()) {
81
+ pastScores .setVisible (false );
82
+ } else {
83
+ pastScores .setVisible (true );
91
84
}
85
+ }
92
86
}
0 commit comments