This repository was archived by the owner on Jul 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_menu.java
More file actions
300 lines (262 loc) · 10.3 KB
/
main_menu.java
File metadata and controls
300 lines (262 loc) · 10.3 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
/**
*
* @author Ryan
*/
public class main_menu{
Stage window; //primary window
Scene mainMenuScene, settingsScene, scoreboardScene; //scenes
ScoreBoard score = new ScoreBoard(); //Create scoreboard (scene from another class)
//scene sizes
int sceneWidth = 600;
int sceneHeight = 600;
public static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
public static double height = screenSize.height*0.7;
public static double width = screenSize.width*0.4;
Image backgroundImage = new Image("MenuIcons\\starry_background.png");
Image startButtonImage = new Image("MenuIcons\\startButtonImage.png");
Image scoreButtonImage = new Image("MenuIcons\\scoreButtonImage.png");
Image exitButtonImage = new Image("MenuIcons\\exitButtonImage.png");
Image backButtonImage = new Image("MenuIcons\\backButtonImage.png");
public void start(Stage primaryStage){
window = primaryStage;
//MAIN MENU SCENE
Pane mainMenuPane = new Pane();
//game title splash here
Image gameTitleImage = new Image("MenuIcons\\\\aliens_title.png");
ImagePattern gameTitlePattern = new ImagePattern(gameTitleImage);
Rectangle gameTitleSplash = new Rectangle(width/4,height/14,width/2,height/4);
gameTitleSplash.setFill(gameTitlePattern);
//end of game title splash
//start button
Button start_btn = new Button();
setbutton(start_btn);
start_btn.setLayoutY(height/2.5);
start_btn.setGraphic(new ImageView(startButtonImage));
start_btn.setOnAction(e -> window.setScene(settingsScene));
//end of start button
//exit button
Button exit_btn = new Button();
setbutton(exit_btn);
exit_btn.setLayoutY(height/1.8);
exit_btn.setGraphic(new ImageView(exitButtonImage));
exit_btn.setOnAction(e -> System.exit(0));
//end of exit button
//scoreboard button
Button score_btn = new Button();
setbutton(score_btn);
score_btn.setLayoutY(height/2.1);
score_btn.setGraphic(new ImageView(scoreButtonImage));
score_btn.setOnAction(e ->
score.start(primaryStage)); //Load the scoreboard
//end of scoreboard button
//scene background
ImageView mainMenuBG = new ImageView(backgroundImage);
//end of scene background
mainMenuPane.getChildren().addAll(mainMenuBG, start_btn, exit_btn, score_btn, gameTitleSplash);
mainMenuScene = new Scene(mainMenuPane, width, height); //create scene
//END OF MAIN MENU SCENE
//SETTINGS SCENE
Pane settingsPane = new Pane();
//back button
Button back_button = new Button();
back_button.setLayoutX(width/60);
back_button.setLayoutY(height/60);
back_button.setGraphic(new ImageView(backButtonImage));
back_button.setPadding(Insets.EMPTY);
back_button.setOnAction(e -> window.setScene(mainMenuScene));
//end of back button
//game map
Label mapLabel = new Label("Select Map:");
mapLabel.setLayoutX(width/60);
mapLabel.setLayoutY(height/11.5);
mapLabel.setTextFill(Color.WHITE);
Rectangle gameMapPreview = new Rectangle(width/3,150,width/2,height/3);
gameMapPreview.setFill(Color.WHITE);
gameMapPreview.setStroke(Color.BLACK);
Label gameMapPreviewLabel = new Label("Map Preview");
gameMapPreviewLabel.setLayoutX(width/1.85);
gameMapPreviewLabel.setLayoutY(height/2.8);
gameMapPreviewLabel.setTextFill(Color.WHITE);
//map radio buttons
final ToggleGroup mapGroup = new ToggleGroup();
RadioButton[] mapradios = new RadioButton[4];
for(int i = 1;i<=3;i++) {
RadioButton test = new RadioButton();
test.setToggleGroup(mapGroup);
test.setUserData(i);
test.setLayoutX(width/30);
test.setTextFill(Color.WHITE);
test.setText("Map : "+i);
mapradios[i] = test;
}
mapradios[1].setLayoutY(height/8);
mapradios[1].setSelected(true);
mapradios[2].setLayoutY(height/6);
mapradios[3].setLayoutY(height/4.75);
//set map preview image with radio buttons
//map preview images
Image map1Image = new Image("Maps\\Map1.jpg");
Image map2Image = new Image("Maps\\Map2.jpg");
Image map3Image = new Image("Maps\\Map3.jpg");
//image patterns to fill rectangle with
ImagePattern map1Pattern = new ImagePattern(map1Image);
ImagePattern map2Pattern = new ImagePattern(map2Image);
ImagePattern map3Pattern = new ImagePattern(map3Image);
//set preview with radio buttons
gameMapPreview.setFill(map1Pattern);
mapradios[1].setOnAction(e -> gameMapPreview.setFill(map1Pattern));
mapradios[2].setOnAction(e -> gameMapPreview.setFill(map2Pattern));
mapradios[3].setOnAction(e -> gameMapPreview.setFill(map3Pattern));
//end of map preview images
//end of map radio buttons
//end of game map
//game wave
Label[] choices = new Label[3];
for(int i = 0;i<3;i++) {
Label test = new Label();
test.setLayoutX(width/60);
test.setTextFill(Color.WHITE);
choices[i] = test;
}
choices[0].setText("Number of Waves:");
choices[0].setLayoutY(height/4);
choices[1].setText("Number of starting Humans");
choices[1].setLayoutY(height/3);
choices[2].setText("Number of Starting Aliens");
choices[2].setLayoutY(height/2.4);
ComboBox<String> gameWaveChoice = new ComboBox();
gameWaveChoice.setPromptText("Default: 2");
gameWaveChoice.setValue("Default: 2");
gameWaveChoice.setLayoutY(height/3.6);
combobox(gameWaveChoice);
ComboBox<String> startingHumansChoice = new ComboBox();
startingHumansChoice.setPromptText("Default: 4");
startingHumansChoice.setValue("Default: 4");
startingHumansChoice.setLayoutY(height/2.75);
combobox(startingHumansChoice);
ComboBox<String> startingAliensChoice = new ComboBox();
startingAliensChoice.setPromptText("Default: 3");
startingAliensChoice.setValue("Default: 3");
startingAliensChoice.setLayoutY(height/2.25);
combobox(startingAliensChoice);
//end of starting aliens
//save settings
//settings object to save settings
GameSettings gameSettings = new GameSettings();
//save settings button
Button saveSettingsButton = new Button();
saveSettingsButton.setLayoutX(width/45);
saveSettingsButton.setLayoutY(height/1.7);
saveSettingsButton.setGraphic(new ImageView(startButtonImage));
saveSettingsButton.setPadding(Insets.EMPTY);
//save button action
saveSettingsButton.setOnAction(e -> {
//save map
if(mapGroup.getSelectedToggle() != null){
if(mapGroup.getSelectedToggle() == mapradios[1]){
//set map to map 1
gameSettings.gameMapID = 1;
System.out.println("Game Map Selected: " + gameSettings.gameMapID);
}else if(mapGroup.getSelectedToggle() == mapradios[2]){
//set map to map 2
gameSettings.gameMapID = 2;
System.out.println("Game Map Selected: " + gameSettings.gameMapID);
}else if(mapGroup.getSelectedToggle() == mapradios[3]){
//set map to map 3
gameSettings.gameMapID = 3;
System.out.println("Game Map Selected: " + gameSettings.gameMapID);
}
}
//save number of game waves
if(gameWaveChoice.getValue().toString().equals("Default: 2")) {
gameSettings.numGameWaves = 2; //default value
}else {
gameSettings.numGameWaves = Integer.parseInt(gameWaveChoice.getValue().toString()); //input value
}
System.out.println("Waves: " + gameSettings.numGameWaves);
//save starting number of humans
if(startingHumansChoice.getValue().toString().equals("Default: 4")) {
gameSettings.numStartingHumans = 4; //default value
}else {
gameSettings.numStartingHumans = Integer.parseInt(startingHumansChoice.getValue().toString()); //input value
}
System.out.println("Starting Humans: " + gameSettings.numStartingHumans);
//save starting number of aliens
if(startingAliensChoice.getValue().toString().equals("Default: 3")) {
gameSettings.numStartingAliens = 3;
}else {
gameSettings.numStartingAliens = Integer.parseInt(startingAliensChoice.getValue().toString());
}
System.out.println("Starting Aliens: " + gameSettings.numStartingAliens);
//START GAME FROM HERE WITH SETTINGS GIVEN ABOVE
System.out.println("All settings are filled; starting game...");
try{
window.close();
Gamewindow game = new Gamewindow(gameSettings.numStartingAliens, gameSettings.numStartingHumans, gameSettings.gameMapID, gameSettings.numGameWaves);
}catch(IOException ex) {
ex.printStackTrace();
}
});
//end of save settings button
//scene background
ImageView settingsBG = new ImageView(backgroundImage);
//end of scene background
settingsPane.getChildren().addAll(settingsBG, choices[1], startingHumansChoice,
mapradios[1], mapradios[2], mapradios[3],
mapLabel, gameMapPreview, gameMapPreviewLabel,
choices[2], startingAliensChoice, saveSettingsButton,
choices[0], gameWaveChoice, back_button);
//end of save settings
settingsScene = new Scene(settingsPane, width, height); //create scene
//END OF SETTINGS SCENE
//SCOREBOARD SCENE
Pane scoreboardPane = new Pane();
//back button
Button backFromScoresButton = new Button();
backFromScoresButton.setLayoutX(width/60);
backFromScoresButton.setLayoutY(height/1.1);
backFromScoresButton.setPrefSize(width/10, height/20);
backFromScoresButton.setGraphic(new ImageView(backButtonImage));
backFromScoresButton.setPadding(Insets.EMPTY);
backFromScoresButton.setOnAction(e -> window.setScene(mainMenuScene));
//end of back button
//scene background
ImageView scoreboardBG = new ImageView(backgroundImage);
//end of scene background
scoreboardPane.getChildren().addAll(scoreboardBG, backFromScoresButton);
scoreboardScene = new Scene(scoreboardPane, width, height);
//END OF SCOREBOARD SCENE
//display
window.setTitle("Project: Aliens");
window.setScene(mainMenuScene);
window.setResizable(false);
window.show();
}
public void combobox(ComboBox<String> cb) {
cb.getItems().addAll("1", "2", "3", "4", "5");
cb.setLayoutX(width/45);
}
public void setbutton(Button bt) {
bt.setPrefSize(width/6, height/14);
bt.setLayoutX(width/2.3);
bt.setPadding(Insets.EMPTY);
}
}