@@ -87,6 +87,7 @@ int main(void)
87
87
88
88
// ThinkGear variables
89
89
char *comPortName = NULL ;
90
+ char *comPortName2 = NULL ;
90
91
int dllVersion = 0 ;
91
92
int connectionId = 0 ;
92
93
int connectionId2 = 0 ;
@@ -115,14 +116,15 @@ int main(void)
115
116
}
116
117
117
118
/* Get a connection ID handle to ThinkGear for player 2 */
119
+ /* *
118
120
connectionId2 = TG_GetNewConnectionId();
119
121
if (connectionId2 < 0) {
120
122
fprintf(stderr, "ERROR: TG_GetNewConnectionId() returned %d for PLAYER 2.\n",
121
123
connectionId);
122
124
fprintf(stderr, "Press ENTER to continue...\n", connectionId2);
123
125
std::cin.ignore();
124
126
//exit(EXIT_FAILURE);
125
- }
127
+ }* */
126
128
127
129
128
130
/* Attempt to connect the connection ID handle to serial port "COM5" */
@@ -138,38 +140,67 @@ int main(void)
138
140
TG_BAUD_57600,
139
141
TG_STREAM_PACKETS);
140
142
if (errCode < 0 ) {
141
- fprintf (stderr, " ERROR: TG_Connect() returned %d for PLAYER 1.\n " , errCode);
143
+ fprintf (stderr, " ERROR: TG_Connect() returned %d.\n " , errCode);
144
+ std::cout << " WARNING: The headset has not been detected!" << std::endl;
142
145
fprintf (stderr, " Press ENTER to continue...\n " , errCode);
143
146
std::cin.ignore ();
144
147
// exit(EXIT_FAILURE);
145
148
}
146
149
147
150
/* PLAYER 2 */
148
151
/* *
149
- comPortName = "\\\\.\\COM4 ";
152
+ comPortName2 = "\\\\.\\COM5 ";
150
153
errCode = TG_Connect(connectionId2,
151
- comPortName ,
152
- TG_BAUD_57600 ,
154
+ comPortName2 ,
155
+ TG_BAUD_9600 ,
153
156
TG_STREAM_PACKETS);
154
157
if (errCode < 0) {
155
158
fprintf(stderr, "ERROR: TG_Connect() returned %d for PLAYER 2.\n", errCode);
156
159
fprintf(stderr, "Press ENTER to continue...\n", errCode);
157
160
std::cin.ignore();
158
161
//exit(EXIT_FAILURE);
159
- }
160
- **/
162
+ }**/
161
163
162
164
// Get names
163
165
std::string p1_name;
164
166
std::string p2_name;
165
- std::cout << " \n Enter name for PLAYER 1: " ;
166
- std::getline (std::cin, p1_name);
167
- /* *
168
- std::cout << "Enter name for PLAYER 2: ";
169
- std::getline(std::cin, p2_name);
170
- **/
167
+ // std::cout << "\nEnter name for PLAYER 1: ";
168
+ // std::getline(std::cin, p1_name);
169
+
170
+ // std::cout << "Enter name for PLAYER 2: ";
171
+ // std::getline(std::cin, p2_name);
171
172
p2_name = " BOT" ;
172
173
174
+ std::string difficulty;
175
+ bool valid_input = false ;
176
+ while (!valid_input) {
177
+ std::cout << " \n Please choose a difficulty: (e)asy, (m)edium, (h)ard, (v)ery hard, (i)mpossible: " ;
178
+ std::getline (std::cin, difficulty);
179
+ if (difficulty == " e" || difficulty == " m" || difficulty == " h" || difficulty == " v" || difficulty == " i" ) {
180
+ valid_input = true ;
181
+ }
182
+ else {
183
+ std::cout << " Invalid input! Try again" << std::endl;
184
+ }
185
+ }
186
+
187
+ std::string full_difficulty;
188
+ if (difficulty == " e" ) {
189
+ full_difficulty = " Easy" ;
190
+ }
191
+ else if (difficulty == " m" ) {
192
+ full_difficulty = " Medium" ;
193
+ }
194
+ else if (difficulty == " h" ) {
195
+ full_difficulty = " Hard" ;
196
+ }
197
+ else if (difficulty == " v" ) {
198
+ full_difficulty = " Very Hard" ;
199
+ }
200
+ else if (difficulty == " i" ) {
201
+ full_difficulty = " Impossible" ;
202
+ }
203
+
173
204
// Set timers
174
205
secondsToRun = 3 ;
175
206
int sec_before_start = 10 ;
@@ -210,17 +241,43 @@ int main(void)
210
241
int player1_meditation = (int )TG_GetValue (connectionId, TG_DATA_MEDITATION);
211
242
// int player2_attention = (int)TG_GetValue(connectionId2, TG_DATA_ATTENTION);
212
243
// int player2_meditation = (int)TG_GetValue(connectionId2, TG_DATA_MEDITATION);
213
- int player2_attention = 0 + (rand () % (int )(100 - 0 + 1 ));
214
- int player2_meditation = 0 + (rand () % (int )(100 - 0 + 1 ));
215
-
244
+ int player2_attention;
245
+ int player2_meditation;
246
+ if (difficulty == " e" ) {
247
+ player2_attention = 0 + (rand () % (int )(35 - 0 + 1 ));
248
+ player2_meditation = 0 + (rand () % (int )(35 - 0 + 1 ));
249
+ }
250
+ else if (difficulty == " m" ) {
251
+ player2_attention = 0 + (rand () % (int )(100 - 0 + 1 ));
252
+ player2_meditation = 0 + (rand () % (int )(100 - 0 + 1 ));
253
+ }
254
+ else if (difficulty == " h" ) {
255
+ player2_attention = 50 + (rand () % (int )(100 - 50 + 1 ));
256
+ player2_meditation = 50 + (rand () % (int )(100 - 50 + 1 ));
257
+ }
258
+ else if (difficulty == " v" ) {
259
+ player2_attention = 75 + (rand () % (int )(100 - 75 + 1 ));
260
+ player2_meditation = 75 + (rand () % (int )(100 - 75 + 1 ));
261
+ }
262
+ else if (difficulty == " i" ) {
263
+ player2_attention = 90 + (rand () % (int )(100 - 90 + 1 ));
264
+ player2_meditation = 90 + (rand () % (int )(100 - 90 + 1 ));
265
+ }
216
266
217
267
// Print player 1 measures
218
- fprintf (stdout, " %s: P1 (%s)\t ATT: %d\n " , currTimeStr, p1_name, player1_attention);
219
- fprintf (stdout, " %s: P1 (%s)\t MED: %d\n " , currTimeStr, p1_name, player1_meditation);
268
+ std::string tabs;
269
+ if (difficulty == " i" ) {
270
+ tabs = " \t\t\t " ;
271
+ }
272
+ else {
273
+ tabs = " \t\t " ;
274
+ }
275
+ fprintf (stdout, " %sPLAYER%s ATT: %d\n " , currTimeStr, tabs, player1_attention);
276
+ fprintf (stdout, " PLAYER%s MED: %d\n " , tabs, player1_meditation);
220
277
221
278
// Print player 2 measures
222
- fprintf (stdout, " %s: P2 (%s)\t ATT: %d\n " , currTimeStr, p2_name , player2_attention);
223
- fprintf (stdout, " %s: P2 (%s)\t MED: %d\n\n " , currTimeStr, p2_name , player2_meditation);
279
+ fprintf (stdout, " %s (%s)\t ATT: %d\n " , p2_name, full_difficulty , player2_attention);
280
+ fprintf (stdout, " %s (%s)\t MED: %d\n\n " , p2_name, full_difficulty , player2_meditation);
224
281
fflush (stdout);
225
282
226
283
// Idle callback. Updating objects, etc. can be done here.
@@ -230,8 +287,35 @@ int main(void)
230
287
// Ball reaches past boundaries
231
288
if (game_over) {
232
289
std::cout << " GAME OVER, BALL REACHED PAST BOUNDARIES." << std::endl;
233
- std::cout << " \n Press ENTER to reset!" << std::endl;
234
- std::cout << " After pressing ENTER, game will restart immediately." << std::endl;
290
+
291
+ bool valid_input = false ;
292
+ while (!valid_input) {
293
+ std::cout << " \n Please choose a difficulty: (e)asy, (m)edium, (h)ard, (v)ery hard, (i)mpossible: " ;
294
+ std::getline (std::cin, difficulty);
295
+ if (difficulty == " e" || difficulty == " m" || difficulty == " h" || difficulty == " v" || difficulty == " i" ) {
296
+ valid_input = true ;
297
+ }
298
+ else {
299
+ std::cout << " Invalid input! Try again." << std::endl;
300
+ }
301
+ }
302
+
303
+ if (difficulty == " e" ) {
304
+ full_difficulty = " Easy" ;
305
+ }
306
+ else if (difficulty == " m" ) {
307
+ full_difficulty = " Medium" ;
308
+ }
309
+ else if (difficulty == " h" ) {
310
+ full_difficulty = " Hard" ;
311
+ }
312
+ else if (difficulty == " v" ) {
313
+ full_difficulty = " Very Hard" ;
314
+ }
315
+ else if (difficulty == " i" ) {
316
+ full_difficulty = " Impossible" ;
317
+ }
318
+ std::cout << " \n Press ENTER to restart game." << std::endl;
235
319
std::cin.ignore ();
236
320
Window::reset_ball ();
237
321
}
0 commit comments