forked from We-are-Trying-Our-Best/Final-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI: TwoPlayer
More file actions
246 lines (214 loc) · 10.1 KB
/
Copy pathGUI: TwoPlayer
File metadata and controls
246 lines (214 loc) · 10.1 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
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.util.ArrayList;
public class TwoPlayer {
static boolean correct1 = false, correct2 = false;
static Stage window;
public static int player1Score = 0, player2Score = 0;
public static void Display(String p1Name, String p2Name) {
GridPane grid;
Label catLabel1, catLabel2, score1, score2;
Scene scene1, scene2, sceneEnd;
VBox layout1Player, layout2Player;
grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setVgap(10);
grid.setHgap(10);
window = new Stage();
window.initModality(Modality.NONE);
window.setTitle("2 player: Categories");
window.setMinWidth(400);
final String IDLE_BUTTON_STYLE = "-fx-background-color: black;" +
"-fx-text-fill: white;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 0;" +
"-fx-border-radius: 5;" +
"-fx-border-color: #87CEFA;";
final String HOVERED_BUTTON_STYLE = "-fx-background-color: black;" +
"-fx-shadow-highlight-color: black;" +
"-fx-text-fill: white;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 0;" +
"-fx-border-radius: 5;" +
"-fx-border-color: #7CFC00";
ArrayList<Integer> numberOrder = StartScreen.QuestionOrder();
for (int k = 0; k < 10; k++) {
int number = numberOrder.get(k);
//Label catLabel: prompt to pick category (2 player)
catLabel1 = new Label("Question " + (k + 1) + ": " + p1Name + ": Pick one of the following categories: ");
catLabel1.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
catLabel1.setTextFill(Color.WHITE);
final Button cat1 = new Button("Hypebeast");
cat1.setStyle(IDLE_BUTTON_STYLE);
cat1.setOnMouseEntered(e -> cat1.setStyle(HOVERED_BUTTON_STYLE));
cat1.setOnMouseExited(e -> cat1.setStyle(IDLE_BUTTON_STYLE));
cat1.setOnAction(e -> {
window.hide();
correct1 = Lauren.Display(number);
});
final Button cat2 = new Button("Memes");
cat2.setStyle(IDLE_BUTTON_STYLE);
cat2.setOnMouseEntered(e -> cat2.setStyle(HOVERED_BUTTON_STYLE));
cat2.setOnMouseExited(e -> cat2.setStyle(IDLE_BUTTON_STYLE));
cat2.setOnAction(e -> {
window.hide();
correct1 = Claire.Display(number);
});
final Button cat3 = new Button("Media");
cat3.setStyle(IDLE_BUTTON_STYLE);
cat3.setOnMouseEntered(e -> cat3.setStyle(HOVERED_BUTTON_STYLE));
cat3.setOnMouseExited(e -> cat3.setStyle(IDLE_BUTTON_STYLE));
cat3.setOnAction(e -> {
window.hide();
correct1 = Meagan.Display(number);
});
final Button cat4 = new Button("Science");
cat4.setStyle(IDLE_BUTTON_STYLE);
cat4.setOnMouseEntered(e -> cat4.setStyle(HOVERED_BUTTON_STYLE));
cat4.setOnMouseExited(e -> cat4.setStyle(IDLE_BUTTON_STYLE));
cat4.setOnAction(e -> {
window.hide();
correct1 = Lenice.Display(number);
});
if (correct1) {
player1Score += 1;
}
score1 = new Label(p1Name + "'s score: " + player1Score);
score1.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
score1.setTextFill(Color.WHITE);
score2 = new Label(p2Name + "'s score: " + player2Score);
score2.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
score2.setTextFill(Color.WHITE);
//VBox layout1Player: sets vertical layout of buttons
layout1Player = new VBox(20);
layout1Player.getChildren().addAll(catLabel1, cat1, cat2, cat3, cat4, score1, score2);
layout1Player.setStyle("-fx-padding: 10;" +
"-fx-border-style: dotted;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 5;" +
"-fx-border-radius: 5;" +
"-fx-border-color: #87CEFA;" +
"-fx-background-color: linear-gradient(to bottom, black, #191970);");
scene1 = new Scene(layout1Player, 500, 350);
window.setScene(scene1);
window.showAndWait();
//Label catLabel2: prompt to pick category (2 player)
catLabel2 = new Label("Question " + (k + 1) + ": " + p2Name + ": Pick one of the following categories: ");
catLabel2.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
catLabel2.setTextFill(Color.WHITE);
final Button cat1a = new Button("Hypebeast");
cat1a.setStyle(IDLE_BUTTON_STYLE);
cat1a.setOnMouseEntered(e -> cat1a.setStyle(HOVERED_BUTTON_STYLE));
cat1a.setOnMouseExited(e -> cat1a.setStyle(IDLE_BUTTON_STYLE));
cat1a.setOnAction(e -> {
window.hide();
correct2 = Lauren.Display(number);
});
final Button cat2a = new Button("Memes");
cat2a.setStyle(IDLE_BUTTON_STYLE);
cat2a.setOnMouseEntered(e -> cat2a.setStyle(HOVERED_BUTTON_STYLE));
cat2a.setOnMouseExited(e -> cat2a.setStyle(IDLE_BUTTON_STYLE));
cat2a.setOnAction(e -> {
window.hide();
correct2 = Claire.Display(number);
});
final Button cat3a = new Button("Media");
cat3a.setStyle(IDLE_BUTTON_STYLE);
cat3a.setOnMouseEntered(e -> cat3a.setStyle(HOVERED_BUTTON_STYLE));
cat3a.setOnMouseExited(e -> cat3a.setStyle(IDLE_BUTTON_STYLE));
cat3a.setOnAction(e -> {
window.hide();
correct2 = Meagan.Display(number);
});
final Button cat4a = new Button("Science");
cat4a.setStyle(IDLE_BUTTON_STYLE);
cat4a.setOnMouseEntered(e -> cat4a.setStyle(HOVERED_BUTTON_STYLE));
cat4a.setOnMouseExited(e -> cat4a.setStyle(IDLE_BUTTON_STYLE));
cat4a.setOnAction(e -> {
window.hide();
correct2 = Lenice.Display(number);
});
if (correct2) {
player2Score += 1;
}
score1 = new Label(p1Name + "'s score: " + player1Score);
score1.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
score1.setTextFill(Color.WHITE);
score2 = new Label(p2Name + "'s score: " + player2Score);
score2.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
score2.setTextFill(Color.WHITE);
//VBox layout1Player: sets vertical layout of buttons
layout2Player = new VBox(20);
layout2Player.getChildren().addAll(catLabel2, cat1a, cat2a, cat3a, cat4a, score1, score2);
layout2Player.setStyle("-fx-padding: 10;" +
"-fx-border-style: dotted;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 5;" +
"-fx-border-radius: 5;" +
"-fx-border-color: #87CEFA;" +
"-fx-background-color: linear-gradient(to bottom, black, #191970);");
scene2 = new Scene(layout2Player, 500, 350);
window.setScene(scene2);
window.showAndWait();
}
Label p1Score = new Label(p1Name + "'s score was " + player1Score);
p1Score.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
p1Score.setTextFill(Color.WHITE);
Label p2Score = new Label(p2Name + "'s score was " + player2Score);
p2Score.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
p2Score.setTextFill(Color.WHITE);
Label endMessage = new Label("Yayyyyy!!! You finished the game!" + "\n" + "Wanna play again?");
endMessage.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
endMessage.setTextFill(Color.WHITE);
final Button yesLoop = new Button("Play again");
yesLoop.setStyle(IDLE_BUTTON_STYLE);
yesLoop.setOnMouseEntered(e -> yesLoop.setStyle(HOVERED_BUTTON_STYLE));
yesLoop.setOnMouseExited(e -> yesLoop.setStyle(IDLE_BUTTON_STYLE));
yesLoop.setOnAction(e -> {
window.close();
Platform.runLater(() -> {
try {
player1Score = 0;
player2Score = 0;
new StartScreen().start(new Stage());
}
catch (Exception ex){
ex.printStackTrace();
}
});
});
final Button noLoop = new Button( "Exit game");
noLoop.setStyle(IDLE_BUTTON_STYLE);
noLoop.setOnMouseEntered(e -> noLoop.setStyle(HOVERED_BUTTON_STYLE));
noLoop.setOnMouseExited(e -> noLoop.setStyle(IDLE_BUTTON_STYLE));
noLoop.setOnAction(e -> {
Platform.exit();
});
VBox endLayout = new VBox(20);
endLayout.setAlignment(Pos.CENTER);
endLayout.getChildren().addAll(p1Score, p2Score, endMessage, yesLoop, noLoop);
endLayout.setStyle("-fx-padding: 10;" +
"-fx-border-style: dotted;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 5;" +
"-fx-border-radius: 5;" +
"-fx-border-color: #87CEFA;" +
"-fx-background-color: linear-gradient(to bottom, black, #191970);");
sceneEnd = new Scene(endLayout, 500, 500);
window.setScene(sceneEnd);
window.show();
}
}