55import com .almasb .fxgl .dsl .FXGL ;
66import com .almasb .fxgl .ui .FontType ;
77import com .dinosaur .dinosaurexploder .model .GameConstants ;
8+ import javafx .collections .FXCollections ;
89import javafx .scene .control .Button ;
10+ import javafx .scene .control .ChoiceBox ;
911import javafx .scene .image .Image ;
1012import javafx .scene .image .ImageView ;
1113import javafx .scene .media .Media ;
1214import javafx .scene .media .MediaPlayer ;
1315import javafx .scene .paint .Color ;
1416import javafx .scene .shape .Rectangle ;
1517
18+ import java .io .File ;
1619import java .io .FileInputStream ;
1720import java .io .FileNotFoundException ;
1821
1922public class DinosaurMenu extends FXGLMenu {
2023
21- public DinosaurMenu () throws FileNotFoundException {
24+ public DinosaurMenu () {
2225 super (MenuType .MAIN_MENU );
2326
2427 Media media = new Media (getClass ().getResource (GameConstants .MAINMENU_SOUND ).toExternalForm ());
@@ -31,59 +34,66 @@ public DinosaurMenu() throws FileNotFoundException {
3134 var title = FXGL .getUIFactoryService ().newText (GameConstants .GAME_NAME , Color .LIME , FontType .MONO , 35 );
3235 var startButton = new Button ("Start Game" );
3336 var quitButton = new Button ("Quit" );
34- FileInputStream fileInputStream = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png" );
35- FileInputStream mutemusic_button =new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/silent.png" );
36-
37- // image for dino in main menu
38- Image image = new Image (fileInputStream );
39- ImageView imageView = new ImageView (image );
40- imageView .setFitHeight (250 );
41- imageView .setFitWidth (200 );
42- imageView .setX (200 );
43- imageView .setY (190 );
44- imageView .setPreserveRatio (true );
45-
46- //adding image to manually mute music
47-
48- Image mute = new Image (mutemusic_button );
49- ImageView imageView_mute =new ImageView (mute );
50- imageView_mute .setFitHeight (40 );
51- imageView_mute .setFitWidth (50 );
52- imageView_mute .setX (490 );
53- imageView_mute .setY (20 );
54- imageView_mute .setPreserveRatio (true );
55-
56- startButton .setMinSize (50 , 50 );
57- quitButton .setMinSize (140 , 50 );
58-
59- title .setTranslateY (100 );
60- title .setTranslateX (getAppWidth () / 2 - 145 );
61-
62- startButton .setTranslateY (400 );
63- startButton .setTranslateX (getAppWidth () / 2 - 50 );
64- startButton .setStyle ("-fx-font-size:20" );
65-
66- quitButton .setTranslateY (500 );
67- quitButton .setTranslateX (getAppWidth () / 2 - 50 );
68- quitButton .setStyle ("-fx-font-size:20" );
69-
70- startButton .setOnAction (event -> {
71- fireNewGame ();
72- mainMenuSound .stop ();
73- });
74-
75- imageView_mute .setOnMouseClicked (mouseEvent -> {
76- mainMenuSound .stop ();
77- });
78-
79- imageView_mute .setOnMousePressed (mouseEvent -> {
80- mainMenuSound .stop ();
81- });
82- quitButton .setOnAction (event -> fireExit ());
83-
84- getContentRoot ().getChildren ().addAll (
85- bg , title , startButton , quitButton ,imageView ,imageView_mute
86- );
37+ try {
38+
39+ FileInputStream fileInputStream = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png" );
40+ FileInputStream mutemusic_button = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/silent.png" );
41+
42+ // image for dino in main menu
43+ Image image = new Image (fileInputStream );
44+ ImageView imageView = new ImageView (image );
45+ imageView .setFitHeight (250 );
46+ imageView .setFitWidth (200 );
47+ imageView .setX (200 );
48+ imageView .setY (190 );
49+ imageView .setPreserveRatio (true );
50+
51+ //adding image to manually mute music
52+
53+ Image mute = new Image (mutemusic_button );
54+ ImageView imageView_mute = new ImageView (mute );
55+ imageView_mute .setFitHeight (40 );
56+ imageView_mute .setFitWidth (50 );
57+ imageView_mute .setX (490 );
58+ imageView_mute .setY (20 );
59+ imageView_mute .setPreserveRatio (true );
60+
61+ startButton .setMinSize (50 , 50 );
62+ quitButton .setMinSize (140 , 50 );
63+
64+ title .setTranslateY (100 );
65+ title .setTranslateX (getAppWidth () / 2 - 145 );
66+
67+ startButton .setTranslateY (400 );
68+ startButton .setTranslateX (getAppWidth () / 2 - 50 );
69+ startButton .setStyle ("-fx-font-size:20" );
70+
71+ quitButton .setTranslateY (500 );
72+ quitButton .setTranslateX (getAppWidth () / 2 - 50 );
73+ quitButton .setStyle ("-fx-font-size:20" );
74+
75+ startButton .setOnAction (event -> {
76+ fireNewGame ();
77+ mainMenuSound .stop ();
78+ });
79+
80+ imageView_mute .setOnMouseClicked (mouseEvent -> {
81+ mainMenuSound .stop ();
82+ });
83+
84+ imageView_mute .setOnMousePressed (mouseEvent -> {
85+ mainMenuSound .stop ();
86+ });
87+ quitButton .setOnAction (event -> fireExit ());
88+
89+ getContentRoot ().getChildren ().addAll (
90+ bg , title , startButton , quitButton , imageView , imageView_mute
91+ );
92+
93+ }
94+ catch (FileNotFoundException e ){
95+ e .printStackTrace ();
96+ }
8797 }
8898
8999}
0 commit comments