-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMINIGAME.cpp
More file actions
290 lines (277 loc) · 5.94 KB
/
MINIGAME.cpp
File metadata and controls
290 lines (277 loc) · 5.94 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// MINIGAME.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "password.h"
#include "console.h"
#include "game.h"
void renderheader();
void renderauthenticator();
void rendergame(int level);
void rendersettings();
bool processmenu();
void addmenuitem(char*,bool,bool);
void rendermenu();
void renderaboutpage();
void renderheader()
{
console::textcolor(4|2);
system("cls"); //used instead of clrscr()
cout<<"********************************************************************************";
cout<<"************************************MINIGAME************************************";
cout<<"********************************************************************************";
}
void renderauthenticator()
{
char input[max];
int chance=1;
bool correct=FALSE;
cout<<endl<<endl<<endl<<"Note:-You will be given only three chances to enter the valid password.And in case you are using this software for the first time,the password is - robin"<<endl<<endl;
while(chance<=3)
{
console::textcolor(4|2);
cout<<"\nENTER THE PASSWORD"<<endl;
console::textcolor(1|2);
for (int i=0;i<max-1;i++)
{
if (i<0) i=0;
input[i]=getch();
if (input[i]=='\b')
{
i-=2;
console::gotoxy(console::getcursorx()-1,console::getcursory());
cout.put(' ');
console::gotoxy(console::getcursorx()-1,console::getcursory());
continue;
}
if (input[i]=='\r')
{
input[i]=0;
break;
}
cout<<"*";
Beep(800,100);
input[i+1]=0;
}
if (password::check(input)==TRUE)
{
correct=TRUE;
break;
}
else
{
console::textcolor(4);
chance++;
cout<<endl<<"\nYou have entered an incorrect password. "<<"You have "<<4-chance<<" chances left.\n";
Beep(2000,200);
}
}
if (correct==FALSE)
{
console::textcolor(4);
cout<<"\n\nAll your three chances are lost"<<endl<<"\nThe program will be terminated now."<<endl<<"\nPress any key to exit";
getch();
exit(0);
}
}
void addmenuitem(char* item,bool header=FALSE,bool footer=FALSE)
{
console::gotoxy(20,console::getcursory());
console::drawHline(console::getcursorx(),60);
console::gotoxy(20,console::getcursory()+1);
cout<<"|";
if (header==TRUE) console::gotoxy(38,console::getcursory());
else console::gotoxy(25,console::getcursory());
cout<<item;
if (footer)
{
int inpx=console::getcursorx();
int inpy=console::getcursory();
console::gotoxy(60,console::getcursory());
cout<<"|";
cout<<"\n";
console::gotoxy(20,console::getcursory());
console::drawHline(console::getcursorx(),60);
console::gotoxy(inpx,inpy);
}
else
{
console::gotoxy(60,console::getcursory());
cout<<"|";
cout<<"\n";
}
}
void rendermenu()
{
system("cls");
renderheader();
console::textcolor(4|2);
cout<<"\n\n\n";
addmenuitem("MENU",TRUE);
addmenuitem("1) VERY EASY LEVEL");
addmenuitem("2) EASY LEVEL");
addmenuitem("3) BEGINNER LEVEL");
addmenuitem("4) INTERMEDIATE LEVEL");
addmenuitem("5) ADVANCED LEVEL");
addmenuitem("6) CHANGE SETTINGS");
addmenuitem("7) ABOUT THE DEVELOPER");
addmenuitem("8) QUIT APPLICATION");
addmenuitem("ENTER OPTION : ",FALSE,TRUE);
while(!processmenu());
}
bool processmenu()
{
console::textcolor(4|2);
bool validchoice=TRUE;
switch (char option=getche())
{
case '1':
Beep(800,100);
game::init(1);
rendermenu();
break;
case '2':
Beep(800,100);
game::init(2);
rendermenu();
break;
case '3':
Beep(800,100);
game::init(3);
rendermenu();
break;
case '4':
Beep(800,100);
game::init(4);
rendermenu();
break;
case '5':
Beep(800,100);
game::init(5);
rendermenu();
break;
case '6':
Beep(800,100);
rendersettings();
break;
case '7':
Beep(800,100);
renderaboutpage();
break;
case '8':
Beep(800,100);
exit(0);
break;
default:
Beep(2000,200);
int inpx=console::getcursorx();
int inpy=console::getcursory();
console::textcolor(4);
cout<<"\n\n\n Please select a valid option. Valid options are; 1,2,3,4,5,6,7,8.";
console::gotoxy(inpx-1,inpy);
validchoice=FALSE;
}
return validchoice;
}
void rendersettings()
{
char oldinput[max],newinput[max];
system("CLS");
renderheader();
cout<<"\n\n\n";
cout<<"Enter the old password\n";
console::textcolor(1|2);
for (int i=0;i<max-1;i++)
{
if (i<0) i=0;
oldinput[i]=getch();
if (oldinput[i]=='\b')
{
i-=2;
console::gotoxy(console::getcursorx()-1,console::getcursory());
cout.put(' ');
console::gotoxy(console::getcursorx()-1,console::getcursory());
continue;
}
if (oldinput[i]=='\r')
{
oldinput[i]=0;
break;
}
cout<<"*";
Beep(800,100);
oldinput[i+1]=0;
}
console::textcolor(4|2);
if (password::check(oldinput))
{
cout<<"\nEnter new password\n";
console::textcolor(1|2);
for (int i=0;i<max-1;i++)
{
if (i<0) i=0;
newinput[i]=getch();
if (newinput[i]=='\b')
{
i-=2;
console::gotoxy(console::getcursorx()-1,console::getcursory());
cout.put(' ');
console::gotoxy(console::getcursorx()-1,console::getcursory());
continue;
}
if (newinput[i]=='\r')
{
newinput[i]=0;
break;
}
cout<<"*";
Beep(800,100);
newinput[i+1]=0;
}
console::textcolor(4|2);
if (password::change(newinput)) cout<<"\n\nPassword has been changed successfully\n\n\nPress any key to continue\n";
else cout<<"There was an error saving the new password\n\n\nPress any key to continue\n";
}
else
{
Beep(2000,200);
console::textcolor(4);
cout<<"\n\n\nWrong password entered\n\n";
console::textcolor(4|2);
cout<<"\nPress any key to continue\n";
}
getch();
rendermenu();
}
void renderaboutpage()
{
char tmp[1000];
system("cls");
renderheader();
ifstream in("robin.rob");
if (!in)
{
cout<<"Error in processing file";
}
else
{
cout<<"\n\n\n\n\n";
console::textcolor(4);
while(!in.eof())
{
char ch;
in.get(ch);
cout.put(ch);
}
}
console::textcolor(4|2);
cout<<"\n\n\n\n\n\nPress any key to continue\n";
getch();
rendermenu();
}
void _tmain(int argc, _TCHAR* argv[])
{
renderheader();
renderauthenticator();
rendermenu();
getch();
}