-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstudyingGame.cpp
150 lines (148 loc) · 4.24 KB
/
studyingGame.cpp
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
#include "studyingGame.h"
// #include <unistd.h> // 맥
#include <windows.h> // 윈도우
#include <algorithm>
#include <random>
using namespace std;
StudyingGame::StudyingGame()
{
score = 100;
words = {{"cat", {"This is an animal.", "It's fluffy.", "It's a popular pet."}},
{"kimchi", {"It's food.", "Its color is red.", "It's korean traditional food."}},
{"rainbow", {"People usually take pictures when they see it.", "It can be seen after raining.", "Some people say it consists of 7 colors."}}};
}
int StudyingGame::selectTargetWord()
{
random_device rd;
default_random_engine rng(rd());
vector<int> options;
for (int i = 0; i < words.size(); i++)
options.push_back(i);
shuffle(options.begin(), options.end(), rng);
cout << options[0];
return options[0];
}
int StudyingGame::startGame(int index)
{
string answer = words[index].word;
cout << "Please Guess a word. We'll give you 3 chances !\n";
Sleep(1000);
// sleep(1);
cout << "First hint!\n";
Sleep(1000);
// sleep(1);
cout << "\n"
<< words[index].hints[0] << "\n\n";
Sleep(1000);
// sleep(1);
cout << "Can you guess the word? \n";
Sleep(1000);
// sleep(1);
cout << "Please enter your answer\n>>";
string user_input;
cin >> user_input;
if (user_input == answer)
{
Sleep(1000);
// sleep(1);
cout << "You got the answer!! \n";
Sleep(1000);
// sleep(1);
cout << "As you got the answer right away, there's no deduction !\n\n";
Sleep(1000);
// sleep(1);
return 0;
}
else
{
Sleep(1000);
// sleep(1);
cout << "That's not the answer :( \n";
Sleep(1000);
// sleep(1);
cout << "We'll give you a second hint \n";
Sleep(1000);
// sleep(1);
cout << "\n"
<< words[index].hints[1] << "\n\n";
Sleep(1000);
// sleep(1);
cout << "Can you guess the word? \n";
Sleep(1000);
// sleep(1);
cout << "Please enter your answer\n>>";
cin >> user_input;
if (user_input == answer)
{
Sleep(1000);
// sleep(1);
cout << "You got the answer!! \n";
Sleep(1000);
// sleep(1);
cout << "As you got the answer in second try, there's only 30 points deduction !\n\n";
Sleep(1000);
// sleep(1);
decreaseScore(30);
return 0;
}
else
{
Sleep(1000);
// sleep(1);
cout << "Well This is the last chance. \n";
Sleep(1000);
// sleep(1);
cout << "We'll give you the last hint \n";
Sleep(1000);
// sleep(1);
cout << "\n"
<< words[index].hints[2] << "\n\n";
Sleep(1000);
// sleep(1);
cout << "Can you guess the word? \n";
Sleep(1000);
// sleep(1);
cout << "Please enter your answer\n>>";
string user_input;
cin >> user_input;
if (user_input == answer)
{
Sleep(1000);
// sleep(1);
cout << "You got the answer!! \n";
Sleep(1000);
// sleep(1);
cout << "As you gained 50 points !\n\n";
Sleep(1000);
// sleep(1);
decreaseScore(50);
return 0;
}
else
{
Sleep(1000);
// sleep(1);
cout << "You lost the game :( ... \n";
Sleep(1000);
// sleep(1);
cout << "The answer was " << answer << " \n";
Sleep(1000);
// sleep(1);
cout << "As you didn't get the answer you only get 30 points !\n\n";
Sleep(1000);
// sleep(1);
decreaseScore(70);
return 0;
}
}
}
}
void StudyingGame::decreaseScore(int deduction)
{
score -= deduction;
}
int StudyingGame::getScore()
{
cout << "Your final score is " << score << "\n";
return score;
}