-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
493 lines (450 loc) · 9.9 KB
/
main.h
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/****************************************************************************
* Copyright (C) 2020 Lu Meng and Chen Xueqing.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
/** @file main.h
* @version 1.0
* @date May 2020
*
*/
#ifndef __MAIN_H__
#define __MAIN_H__
#ifdef MAIN_H_GLOBAL
#define MAIN_H_EXTERN
#else
#define MAIN_H_EXTERN extern
#endif
#define DENSITY 20 //in 1000
#define WIDTH 51
#define HEIGHT 11
#define CORRECT 1
#define WRONG -1
#define BLANK 0
const int LIST_LENGTH = 100;
const std::string word_list[LIST_LENGTH] = {
"panda",
"shirt",
"candy",
"drink",
"white",
"zero",
"lemon",
"result",
"humor",
"sleepy",
"police",
"shower",
"morning",
"summer",
"teacher",
"mobile",
"society",
"pardon",
"flower",
"culture",
"umbrella",
"window",
"yesterday",
"kitchen",
"theater",
"pancake",
"sandwich",
"bamboo",
"random",
"discuss",
"birthday",
"engineering",
"expensive",
"headache",
"history",
"introduce",
"newspaper",
"strawberry",
"vegetable",
"watermelon",
"activity",
"achieve",
"apology",
"jewelry",
"laundry",
"forgive",
"festival",
"neighbor",
"between",
"calculate",
"abnormal",
"abundant",
"adjustment",
"bridegroom",
"bungalow",
"communicate",
"information",
"keyboard",
"envelope",
"interface",
"circumstance",
"coincidence",
"compulsory",
"deliberate",
"earthquake",
"kindergarten",
"literature",
"brainstorm",
"commander",
"phenomena",
"formula",
"graduate",
"heritage",
"fortunate",
"balcony",
"standard",
"feedback",
"dwelling",
"estimate",
"innocent",
"advertisement",
"approximate",
"emergency",
"individual",
"instrument",
"percentage",
"represent",
"scholarship",
"convention",
"significant",
"acquaintance",
"atmosphere",
"congratulate",
"paramount",
"hurricane",
"incredible",
"architecture",
"deficiency",
"transaction",
"distinguish",
};
const std::string tip_list[LIST_LENGTH] = {
"an animal",
"a kind of clothes",
"a kind of food",
"an action",
"a colour",
"a number",
"a kind of fruit",
"a consequence",
"something that can evoke laughter",
"to describe a feeling",
"an occupation",
"an everyday doing",
"a time peroid",
"a time peroid",
"an occupation",
"to describe something moving",
"a group",
"an action",
"a kind of plant",
"shared by a society",
"an everyday object",
"an everyday object",
"a time",
"a place",
"a place",
"a kind of food",
"a kind of food",
"a kinf of plant",
"by chance",
"an action",
"an special day",
"a course",
"to describe goods",
"an illness",
"a course",
"an action",
"a media",
"a kind of fruit",
"a kind of food",
"a kind of fruit",
"an everyday thing",
"an action",
"an action",
"a treasure",
"a place",
"an action",
"a special day",
"a kind of people",
"a preposition",
"an action",
"to describe something odd",
"to describe something plentiful",
"a action",
"a person",
"a kind of house",
"an action",
"a message",
"a device",
"a container",
"something used to interact",
"a situation",
"an acccidental event",
"to describe something required",
"on purpose",
"a disaster",
"a school",
"an kind of art",
"an activity",
"a person",
"something observable",
"a statement",
"an action",
"a property",
"to describe something good",
"a place",
"to describe something normal",
"a response",
"a house",
"ac action",
"to describe a person",
"a message",
"to estimate",
"an unusual situation",
"to describe someone single",
"a device",
"a proportion",
"delegate",
"an award",
"something normative",
"to describe something impprtant",
"a relationship",
"a particular environment",
"an action",
"to describe something impprtant",
"a disaster",
"to describe something good",
"a course",
"something not enough",
"an action",
"an action",
};
class Fall
{
public:
std::vector<std::string> display;
int col; //only odd number
int row;
/**
* @brief set Fall's col and row and fill display with blanks
* @param col colomns of Fall
* row rows of Fall
*/
Fall(int col, int row)
{
this->col = col;
this->row = row;
for (int i = 0; i < this->row; i++)
{
(this->display).push_back(std::string(col, ' '));
}
}
/**
* @brief put a string in the begin of display and erase the last string
* @param str the input string
* @retval void
*/
void push(std::string str)
{
(this->display).erase((this->display).begin());
(this->display).push_back(str);
}
};
class Word
{
public:
int length;
std::string target;
std::string display;
std::string tip;
/**
* @brief initialize length, target, display, tip of Word using target and tip given
* @param target the target word
* tip the tip for target word
* @retval void
*/
void init(std::string target, std::string tip)
{
this->target = target;
this->length = this->target.length();
this->display = std::string(this->length, '-');
this->tip = tip;
}
/**
* @brief reveal every appearance of a character in display according to its position in target
* @param c the charater needed to be revealed
* @retval void
*/
void reveal(char c)
{
int last_pos = (this->target).find(c);
while (last_pos != std::string::npos)
{
(this->display).replace(last_pos, 1, std::string(1, c));
if (last_pos >= this->length)
{
break;
}
int pos = (this->target).find(c, last_pos + 1);
last_pos = pos;
}
}
/**
* @brief print the display and tip
* @param void
* @retval void
*/
void print()
{
std::cout << this->display << " (" << this->tip << ")";
}
};
class Player_line
{
public:
std::string display;
int index;
/**
* @brief initialize the display of Player_line with a basket in the middle
* @param length the length of the Player_line
* @retval void
*/
void init(int length)
{
this->display = std::string((length - 3) / 2, ' ') + "\\_/" + std::string((length - 3) / 2, ' ');
}
/**
* @brief fill basket with "o" if catch right, with "x" if catch wrong or restore otherwise
* @param m how to fill, 1 is right, -1 is wrong, 0 to restore
* @retval void
*/
void fill_bucket(int m)
{
if (m == 1)
{
if ((this->display).find("_") != std::string::npos)
{
(this->display).replace((this->display).find("_"), 1, "o");
}
}
else if (m == -1)
{
if ((this->display).find("_") != std::string::npos)
{
(this->display).replace((this->display).find("_"), 1, "x");
}
}
else
{
if ((this->display).find("o") != std::string::npos)
{
(this->display).replace((this->display).find("o"), 1, "_");
}
if ((this->display).find("x") != std::string::npos)
{
(this->display).replace((this->display).find("x"), 1, "_");
}
}
}
/**
* @brief move the basket left or right
* @param dir -1 left, 1 right
* @retval void
*/
void update(int dir)
{
if (dir == -1)
{
this->display = (this->display).substr(1) + ' ';
this->index--;
}
if (dir == 1)
{
(this->display) = ' ' + (this->display).substr(0, (this->display).size() - 1);
this->index++;
}
}
/**
* @brief print the Player_line
* @param void
* @retval void
*/
void print()
{
std::cout << this->display;
}
};
class Timer
{
public:
int countdown;
bool deducted;
/**
* @brief initialize countdown with the given time and deducted with false
* @param countdown intial countdown
*/
Timer(int countdown)
{
this->countdown = countdown;
this->deducted = false;
};
/**
* @brief print the countdown
* @param void
* @retval void
*/
void print()
{
std::cout << "COUNTDOWN: " << this->countdown;
};
};
class Status
{
public:
bool won;
bool end;
bool time_up;
/**
* @brief initialize Status to be all false
* @param void
*/
Status()
{
this->won = false;
this->end = false;
this->time_up = false;
}
};
void print_option(std::string str, bool at);
void print_menu(int now_at);
int menu();
void game();
void player();
void tick();
void init();
std::string rand_str(int l);
void print();
int update_word(char c);
void update();
void judge();
void destroy();
void record(std::string playerName, int level, int time);
#endif // __MAIN_H__