-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscore_window.cpp
More file actions
199 lines (186 loc) · 4.53 KB
/
score_window.cpp
File metadata and controls
199 lines (186 loc) · 4.53 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
#include "score_window.h"
#include "mdo_fileio.h"
using namespace Graph_lib;
score_window::score_window(Point xy, int w, int h, const string& title, const int& difficulty, string playername) :
Window(xy, w, h, title),
button_proceed(Point(x_max() - 70, 0), 70, 20, "Continue", cb_proceed),
highScore(Point(x_max() / 2, 140), 150, 25, "First Place: "),
secondPlace(Point(x_max() / 2, 170), 150, 25, "Second Place: "),
thirdPlace(Point(x_max() / 2, 200), 150, 25, "Third Place: "),
fourthPlace(Point(x_max() / 2, 230), 150, 25, "Fourth Place: "),
fifthPlace(Point(x_max() / 2, 260), 150, 25, "Fifth Place: "),
level{ difficulty },
playername{ playername },
button_pushed(false)
{
attach(button_proceed);
attach(highScore);
attach(secondPlace);
attach(thirdPlace);
attach(fourthPlace);
attach(fifthPlace);
}
bool score_window::wait_for_button()
// modified event loop:
// handle all events (as per default), quit when button_pushed becomes true
// this allows graphics without control inversion
{
show();
button_pushed = false;
#if 1
// Simpler handler
while (!button_pushed) Fl::wait();
Fl::redraw();
#else
// To handle the case where the user presses the X button in the window frame
// to kill the application, change the condition to 0 to enable this branch.
Fl::run();
#endif
return button_pushed;
}
void score_window::cb_proceed(Address, Address pw)
// call the game to continue
{
reference_to<score_window>(pw).proceed();
}
int score_window::get_level() {
return level;
}
void score_window::proceed() {
hide();
}
void score_window::show_scores() {
int difficulty = get_level();
mdo::user_score tostring;
stringstream output;
if (difficulty == 1) {
mdo::score_io score{ "\121\WhenInDoubtCYourWayOut\GameGUI\GameGUI\beginner.txt", 320 };
for (int i = 1; i <= 5; ++i) {
tostring = score.get(i);
output << tostring.name << " scoring " << tostring.score;
string box = output.str();
switch (i) {
case 1:
highScore.put(box);
break;
case 2:
secondPlace.put(box);
break;
case 3:
thirdPlace.put(box);
break;
case 4:
fourthPlace.put(box);
break;
case 5:
fifthPlace.put(box);
break;
}
output.str("");
}
}
if (difficulty == 2) {
mdo::score_io score{ "\121\WhenInDoubtCYourWayOut\GameGUI\GameGUI\intermediate.txt", 640 };
for (int i = 1; i <= 5; ++i) {
tostring = score.get(i);
output << tostring.name << " scoring " << tostring.score;
string box = output.str();
switch (i) {
case 1:
highScore.put(box);
break;
case 2:
secondPlace.put(box);
break;
case 3:
thirdPlace.put(box);
break;
case 4:
fourthPlace.put(box);
break;
case 5:
fifthPlace.put(box);
break;
}
output.str("");
}
}
if (difficulty == 3) {
mdo::score_io score{ "\121\WhenInDoubtCYourWayOut\GameGUI\GameGUI\advanced.txt", 1280 };
for (int i = 1; i <= 5; ++i) {
tostring = score.get(i);
output << tostring.name << " scoring " << tostring.score;
string box = output.str();
switch (i) {
case 1:
highScore.put(box);
break;
case 2:
secondPlace.put(box);
break;
case 3:
thirdPlace.put(box);
break;
case 4:
fourthPlace.put(box);
break;
case 5:
fifthPlace.put(box);
break;
}
output.str("");
}
}
if (difficulty == 4) {
mdo::score_io score{ "\121\WhenInDoubtCYourWayOut\GameGUI\GameGUI\expert.txt", 2560 };
for (int i = 1; i <= 5; ++i) {
tostring = score.get(i);
output << tostring.name << " scoring " << tostring.score;
string box = output.str();
switch (i) {
case 1:
highScore.put(box);
break;
case 2:
secondPlace.put(box);
break;
case 3:
thirdPlace.put(box);
break;
case 4:
fourthPlace.put(box);
break;
case 5:
fifthPlace.put(box);
break;
}
output.str("");
}
}
if (difficulty == 5) {
mdo::score_io score{ "\altodd\121\WhenInDoubtCYourWayOut\GameGUI\GameGUI\missionImpossible.txt", 5120 };
for (int i = 1; i <= 5; ++i) {
tostring = score.get(i);
output << tostring.name << " scoring " << tostring.score;
string box = output.str();
switch (i) {
case 1:
highScore.put(box);
break;
case 2:
secondPlace.put(box);
break;
case 3:
thirdPlace.put(box);
break;
case 4:
fourthPlace.put(box);
break;
case 5:
fifthPlace.put(box);
break;
}
output.str("");
}
}
}