-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumberGame.cpp
More file actions
275 lines (219 loc) · 10.6 KB
/
numberGame.cpp
File metadata and controls
275 lines (219 loc) · 10.6 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
cout << "\n\t\t-----------------------------------------------------" << endl
<< "\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl
<< "\t\t-----------------------------------------------------" << endl
<< "\n\t\t\t~WELCOME TO NUMBER GUESSING GAME~" << endl //Startring UI
<< "\n\t\t-----------------------------------------------------" << endl
<< "\t\t$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl
<< "\t\t-----------------------------------------------------" << endl
<< "\n\n\nGuess a number between 1 and 100. Good Luck! " << endl;
int optioGame,option; // Addon by myself:
cout << "\nCHOOSE OPTION TO PLAY\n" << endl << endl
<< " 1. Play with Limited chances!\t" << "\t 2. Play with unlimited chances!" << endl
<< "\nEnter option to start: ";
cin >> option;
if (option== 1)
{
while (true)
{
cout << "\nChoose the difficulty level: \n" << "Enter 1. Easy!\t\t"
<< "Enter 2. Medium!\t" << "Enter 3. hard!\t\t"
<< "Enter 0. Quit!\n\n\n";
int levelChoice; // Players input of difficulty:
cout << "Enter your desired Level to play : ";
cin >> levelChoice;
srand(time(0)); // code to generate random number between 1 and 100:
int randomNumber = 1 + (rand() % 100);
int playerInput;
if (levelChoice == 1)
{
cout << "\nYou have 5 chances for finding the Random number between 1 and 100.";
int chancesLeft = 5;
for (int i = 1; i <= 5; i++)
{
cout << "\n\nEnter the number: "; // player to enter the number they have guessed:
cin >> playerInput;
cout << endl;
if (playerInput == randomNumber) // checking if the playerInput matches:
{
cout << "Well played! You won, " << playerInput << " is the Random number" << endl
<< "\t\t\t Thanks for playing......" << endl << "Play the game again with us!!!\n "
"-----------------------------" << endl;
break;
}
else
{
cout << "-----------------------------------------------\n"
<< "Opps!!!, " << playerInput << " is not the right number\n";
int difference = abs(playerInput - randomNumber);
if (difference <= 10)
{
cout << "You're very close to the number!\n";
}
else if (playerInput > randomNumber)
{
cout << "Your Guess is too high!!!\n";
}
else
{
cout <<"Your Guess is too low!!!\n";
}
chancesLeft--;
cout << "Attention ! " << chancesLeft << " chances left. " << endl
<< "-----------------------------------------------\n";
if (chancesLeft == 0)
{
cout << "You couldn't find the Random number, it was " << randomNumber
<< ", Better Luck Next Time !\n\n" << "Play the game again to win (*_*)\n"
<< "-----------------------------" << endl;
}
}
}
}
else if (levelChoice == 2) // for level 2:
{
cout << "\nYou have 3 chances for finding the Random number between 1 and 100.";
int chancesLeft = 3;
for (int i = 1; i <= 3; i++)
{
cout << "\n\nEnter the number: "; // player to guess the randomNumber:
cin >> playerInput;
cout << endl;
if (playerInput == randomNumber) // determining if the playerInput matches randomNumber:
{
cout << "Well played! You won, " << playerInput
<< " is the Random number" << endl << "\t\t\t Thanks for playing...."
<< "-----------------------------"<<endl;
break;
}
else
{
cout << "-----------------------------------------------\n"
<< "Opps!!!, " << playerInput << " is not the right number\n";
int difference = abs(playerInput - randomNumber);
if (difference <= 10)
{
cout << "You're very close to the number!\n";
}
else if (playerInput > randomNumber)
{
cout << "Your Guess is too high!!!\n";
}
else
{
cout << "Your Guess is too low!!!\n";
}
chancesLeft--;
cout<< "Attention ! " << chancesLeft << " chance left. " << endl
<< "-----------------------------------------------\n";
if (chancesLeft == 0)
{
cout << "You couldn't find the Random number, it was "
<< randomNumber << ", Better Luck Next Time !\n\n"
<< "Play the game again to win (*_*)\n"
<< "-----------------------------" << endl;
}
}
}
}
else if (levelChoice == 3) // Difficulty level : Medium
{
cout << "\nYou have 2 chances for finding the Random number between 1 and 100.";
int chancesLeft = 2;
for (int i = 1; i <= 2; i++)
{
cout << "\n\nEnter the number: "; // prompting the player to guess the Random number:
cin >> playerInput;
cout << endl;
if (playerInput == randomNumber) // determining if the playerInput matches Random number:
{
cout << "Well played! You won....." << playerInput << " is the Random number" << endl
<< "\t\t\t Thanks for playing...." << endl << "Play the game again with us!!"<<endl
<<"-----------------------------"<< endl;
break;
}
else
{
cout << "-----------------------------------------------\n";
cout << "Opps!!!, " << playerInput << " is not the right number\n";
int difference = abs(playerInput - randomNumber);
if (difference <= 10)
{
cout << "You're very close to the number!\n";
}
else if (playerInput > randomNumber)
{
cout << "Your Guess is too high!!!\n";
}
else
{
cout << "Your Guess is too low!!!\n";
}
chancesLeft--;
cout << "Attention ! " << chancesLeft << " chances left. " << endl
<< "-----------------------------------------------\n";
if (chancesLeft == 0)
{
cout << "You couldn't find the Random number, it was " << randomNumber
<< ", better luck next time !\n\n" << "Play the game again to win (*_*)\n"
<< "-----------------------------" << endl;
}
}
}
}
else if (levelChoice == 0) // to quit:
{
cout << "\n\t\t ~|G|A|M|E| |O|V|E|R|~";
exit(0);
}
else
{
cout << "Wrong Level selection, You can only choose the levels given above or Choose to Quit!" << endl;
}
}
}
else if (option == 2)
{
srand(time(0)); // random number generation
int randomNumber1 = 1 + (rand() % 100);
int playerGuess;
int chances = 1;
do
{
cout << "\n\n Enter you Guess: ";
cin >> playerGuess;
int difference1 = abs(playerGuess - randomNumber1);
cout << "-----------------------------------------------\n";
cout << "Opps!!!, " << playerGuess << " is not the right number\n";
if (difference1 <= 20)
{
cout << "You're very close to the number!\n";
}
else if (playerGuess > randomNumber1){
cout << "Your Guess is too high!!!\n";
}
else
{
cout<< "Your Guess is too low!!!\n";
}
cout <<chances<<" chance " <<endl
<<"-----------------------------------------------\n";
chances++;
}
while (playerGuess != randomNumber1);
{
cout << "\t\t CONGRATULATIONS YOU WON!" << endl
<< "\n\t\t ~|G|A|M|E| |O|V|E|R|~";
}
}
else
cout << " WRONG OPTION SELECTED! " << endl
<<"You can only choose 1 or 2: "<<endl
<<"\n\t\t ~OUT OF GAME~";
return 0;
}