-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
254 lines (198 loc) · 7.35 KB
/
Game.java
File metadata and controls
254 lines (198 loc) · 7.35 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
/**
* class that controls the flow of the game
*
* @author Cyrine Ben Ayed and Jessica Fend
* @version Spring 2022
*/
public class Game {
/** holds the window */
static Window win = new Window("O'College");
/** holds one game day */
static GameDay oneDay;
/** holds the academics score */
static int academics_score = 50;
/** holds the physical health score */
static int physical_score = 50;
/** holds the mental health score */
static int mental_score = 50;
/** holds the social score */
static int social_score = 50;
/** runs one day */
public static void runDay(int dayNum) throws InterruptedException {
// creates the decision tree
oneDay = new GameDay(dayNum);
DecisionTree dayTree = oneDay.dayTree;
/**holds the current position of the decison tree */
DecisionTree current = dayTree;
while (!current.isLeaf()){
/** holds the prompt */
String prompt = current.getData().substring(0, current.getData().indexOf("@"));
/** holds the image file */
String imgFile = current.getData().substring(current.getData().indexOf("@")+1);;
// print statements for debugging
System.out.println(prompt);
System.out.println(imgFile);
// set the window
win.updateComponents(imgFile, prompt, true);
//tests the buttons
Tests.checkButton(win.choices);
//wait for response
waitForEnter();
// get the response
//for testing and debugging
// System.out.println(win.getResponse());
// if they answered yes
if (win.getResponse().equals("yes")){
current = current.getLeft();
// if they answered no
} else {
current = current.getRight();
}
win.setResponse("");
// for debugging and testing
// System.out.println(win.getResponse());
}
/** holds last line */
String prompt = current.getData().substring(0, current.getData().indexOf("@"));
/** holds the image path */
String imgFile = current.getData().substring(current.getData().indexOf("@")+1, current.getData().indexOf("#"));
/** holds the score update */
String score_update = current.getData().substring(current.getData().indexOf("#")+1);
//for debugging
// System.out.println("mental: "+ String.valueOf(mental_score));
// System.out.println("physical: "+ String.valueOf(physical_score));
// System.out.println("social: "+ String.valueOf(social_score));
// System.out.println("academics: "+ String.valueOf(academics_score));
//update the score
updateScore(score_update);
//for debugging
// System.out.println("update:**"+ String.valueOf(score_update)+ "**");
// System.out.println("mental: "+ String.valueOf(mental_score));
// System.out.println("physical: "+ String.valueOf(physical_score));
// System.out.println("social: "+ String.valueOf(social_score));
// System.out.println("academics: "+ String.valueOf(academics_score));
// System.out.println("33333333333");
Tests.checkButton(win.choices);
// sets the window
win.updateComponents(imgFile, prompt, false);
// for testing and debugging
System.out.println(prompt);
System.out.println(imgFile);
// wait for 3 seconds
try {
Thread.sleep(5000);
Tests.checkButton(win.choices);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
// tell them they have reached the end of the day
win.updateComponents("Pictures/quad.jpeg", ".... End of the game day...", false);
// wait for 3 seconds
try {
Thread.sleep(4000);
// for testing and debugging
// System.out.println("666666666666");
Tests.checkButton(win.choices);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
/** method that wait for the user's click on one of the buttons */
public static void waitForEnter() throws InterruptedException {
synchronized(win.anyButton) {
try {
win.anyButton.wait();
Tests.checkButton(win.choices);
} catch (InterruptedException ex) {
System.out.println("Interrupted");
}
}
// for debugging
System.out.println("After button clicked");
}
/**
* updates the player's score
* @param score_update
*/
public static void updateScore (String score_update){
if (score_update.equals("P1")){
physical_score += 10;
} else if (score_update.equals("P0")) {
physical_score -= 10;
} else if (score_update.equals("A1")) {
academics_score += 10;
} else if (score_update.equals("A0")) {
academics_score -= 10;
} else if (score_update.equals("S1")) {
social_score += 10;
} else if (score_update.equals("S0")) {
social_score -= 10;
} else if (score_update.equals("M1")) {
mental_score += 10;
} else{
mental_score -= 10;
}
}
/** method that display's the player's scores and achievements */
public static void displayScores(){
// get each score
String mental = "Mental Health: " + String.valueOf(mental_score) + "/";
String physical = "Physcial Health: " + String.valueOf(physical_score) + "/";
String academics = "Academics Performance: " + String.valueOf(academics_score) + "/";
String social = "Social Involvment: " + String.valueOf(social_score) + "/";
// get their acievement
String achievement = "";
// get maximum score
int max_score = Math.max(mental_score, physical_score);
max_score = Math.max(max_score, academics_score);
max_score = Math.max(max_score, social_score);
//update achievement
if (max_score == mental_score && mental_score>100){
achievement = "Your really took care of yourself, good job!";
} else if(max_score == physical_score && physical_score>100) {
achievement = "You looked so fit and you're in good health, keep it up!";
}else if(max_score == social_score && social_score>100) {
achievement = "You're so popular now!";
}else if(max_score == academics_score && academics_score>100) {
achievement = "A 4.0 GPA? Dang!";
}
// display
String message = "Game over, here's your performance: " + mental + physical + academics + social + achievement;
// for testing
// System.out.println(message);
win.updateComponents("Pictures/scores.jpeg", "<html><p style=\"width:250px\">"+message+"</p></html>", false);
Tests.checkButton(win.choices);
// wait for 3 seconds
try {
Tests.checkButton(win.choices);
Thread.sleep(5000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
/** the main class to run our program
*
* @param args
* @throws InterruptedException
*/
public static void main (String[] args) throws InterruptedException{
// show the window
win.showWindow("Pictures/Welcome.jpeg", "Welcome to Smith!!");
// wait for 3 seconds
try {
Thread.sleep(3000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
//loop through each day
for (int i=1; i<9; i++){
runDay(i);
}
Tests.checkButton(win.choices);
//display scores
displayScores();
Tests.checkScore(1, mental_score, physical_score, academics_score, social_score);
//exit when done
System.exit(0);
}
}