-
Notifications
You must be signed in to change notification settings - Fork 0
/
MINESWEPEER6.CPP
361 lines (328 loc) · 7 KB
/
MINESWEPEER6.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
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
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<stdio.h>
///
void clr(int x,int y);
void clr_ar(int x,int y); ///pak kardane kadr.
void ins_ar(int x,int y); ///keshidane kadr.
void pr(int x,int y,char ch);
///..............................................................................sar-a-sari
int enb[30][30]; ///enable
int bmb[30][30]; ///bomb
int bm_near[30][30]; ///tedade bomb-haye atrafe har khane.
int sz;
///....................................................................................
int main()
{
int exit=2;
randomize();
textcolor(6);
clrscr();
while(exit==2)
{
int bm_num,tx1,xx,yy,win,i,j,pos,x_pos,y_pos,emp;
int end=0;
win=1;
char name[100];
clrscr();
////
cout<<"\nWellcome to... \n\n";
delay(500);
cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
delay(500);
cout<<"@@ @@@@@ @@ @@ @@@@ @@ @@\n";
delay(500);
cout<<"@@ @ @@@ @ @@@@ @@@@ @ @@@ @@ @@@@@\n";
delay(500);
cout<<"@@ @@ @ @@ @@@@ @@@@ @@ @@ @@ @@\n";
delay(500);
cout<<"@@ @@@@@@@ @@@@ @@@@ @@@ @ @@ @@@@@\n";
delay(500);
cout<<"@@ @@@@@@@ @@ @@ @@@@ @@ @@\n";
delay(500);
cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
delay(500);
cout<<"\n Sweeeper!!\n";
delay(1000);
cout<<"\n Directed By "<<(char)2<<" *Sadegh Eftekhari*\n\n\n";
delay(2000);
cout<<"----------------------------------------------------\n";
cout<<" | Up ,Down ,Left ,Right : Move To Other Points.|\n";
cout<<" | Space : Select a Point. |\n";
cout<<" | Escape : Exit The Game. |\n";
cout<<"----------------------------------------------------\n\n\n";
cout<<" LOADING (10 s) :";
for(i=0;i<=20;i++){
cout<<">";
delay(500);
}
textcolor(4);
clrscr();
////
cout<<"\n"<<(char)2<<" : What Is Your Name ? ";
gets(name);
clrscr();
do
{
cout<<"\n"<<(char)2<<" : Hi "<<name<<", Enter a Size For Game(5-20) : ";
cin>>sz;
clrscr();
}while(sz>20 || sz<5);
do
{
cout<<"\n"<<(char)2<<" : Now Enter Number Of Mines (1-"<<(sz*sz)/3<<") : ";
cin>>bm_num;
clrscr();
}while(bm_num<1 || bm_num>(sz*sz)/3);
/// ijade khane-ha..............................................................................
for(xx=1;xx<=sz;xx++)
for(yy=1;yy<=sz;yy++)
{
enb[xx-1][yy-1]=1;
bmb[xx-1][yy-1]=0;
bm_near[xx-1][yy-1]=0;
}
///ijade bomb-ha.......................................................................................
i=1;
while(i<=bm_num)
{
xx=1+random(sz);
yy=1+random(sz);
if (bmb[xx-1][yy-1]==0){
bmb[xx-1][yy-1]=1;
i++;
}
}
////bomb-haye atraf......................................................................
for(xx=1;xx<=sz;xx++)
for(yy=1;yy<=sz;yy++)
{
for(i=xx-1;i<=xx+1;i++)
for(j=yy-1;j<=yy+1;j++)
{
if (i>=1 && i<=sz && j>=1 && j<=sz)
{
if (bmb[i-1][j-1]==1)
{
bm_near[xx-1][yy-1]++;
}
}
}
}
////chap...................................................................................
textcolor(3);
clrscr();
cout<<(char)2<<" : "<<name<<" Is Playing a Game With "<<bm_num<<" Mines.\n";
for(yy=1;yy<=2*sz;yy++) /// chape khane-ha...
{
for(xx=1;xx<=2*sz;xx++)
{
if (yy%2==0 && xx%2==0)
{
cout<<" #";
}
}
cout<<"\n";
}
///kelidha..................................................................................
x_pos=1;
y_pos=1;
ins_ar(x_pos,y_pos);
while(end==0)
{
char key;
key=getch();
if (key==0)
{
///..................................................................................................up
key=getch();
if (key==72) ///key up
{
if( y_pos>1)
{
clr_ar(x_pos,y_pos);
y_pos--;
ins_ar(x_pos,y_pos);
}
}
/////..........................................................................................................left
else if (key==75) ///key up
{
if( x_pos>1)
{
clr_ar(x_pos,y_pos);
x_pos--;
ins_ar(x_pos,y_pos);
}
}
/////..........................................................................................................down
else if (key==80) ///key up
{
if( y_pos<sz)
{
clr_ar(x_pos,y_pos);
y_pos++;
ins_ar(x_pos,y_pos);
}
}
/////..........................................................................................................right
else if (key==77) ///key up
{
if( x_pos<sz)
{
clr_ar(x_pos,y_pos);
x_pos++;
ins_ar(x_pos,y_pos);
}
}
///
}else if(key==32)
{
if (enb[x_pos-1][y_pos-1]==1)
{
if (bmb[x_pos-1][y_pos-1]==0)
{
if (bm_near[x_pos-1][y_pos-1]==0)
{
pr(x_pos*2,y_pos*2+1,'.');
enb[x_pos-1][y_pos-1]=0;
clr(x_pos,y_pos);
emp=0;
for(xx=1;xx<=sz;xx++){
for(yy=1;yy<=sz;yy++) {
if (enb[xx-1][yy-1]==1){
emp++;}}}
if (emp==bm_num)
end=1;
}else
{
gotoxy(x_pos*2,y_pos*2+1);
cout<<bm_near[x_pos-1][y_pos-1];
enb[x_pos-1][y_pos-1]=0;
emp=0;
for(xx=1;xx<=sz;xx++){
for(yy=1;yy<=sz;yy++) {
if (enb[xx-1][yy-1]==1){
emp++;}}}
if (emp==bm_num)
end=1;
}
}else
{
gotoxy(x_pos*2,y_pos*2+1);
cout<<(char)15;
cout<<(char)7;
end=1;win=0;
}
}
}else if (key==27){return 0;}
}
///
if (win==0)
{
gotoxy(1,2*sz+3);
cout<<"Sorry, You Lose!!\n";
}else
{
gotoxy(1,2*sz+3);
cout<<"\a YOU\n\n";
cout<<"#####################################\n";
cout<<"## ############# ## ## #### ## ##\n";
cout<<"## ############# #### #### ### ## ##\n";
cout<<"## ##### ##### #### #### # # ## ##\n";
cout<<"### ### ### ### ##### #### ### #####\n";
cout<<"#### ##### #### ## #### ## ##\n";
cout<<"#####################################\n";
}
///
cout<<"1-Exit.\n";
cout<<"2-Try Again.\n";
tx1=getch();
if (tx1==50)
exit=2;
else
exit=0;
///
} ///end do
return 0;
}
///tabe...........................................................................................................
void clr(int x,int y)
{
int i,j,sw;
///khane pooch ast!
for(i=x-1;i<=x+1;i++)
for(j=y-1;j<=y+1;j++)
{
if (i==x && j==y)
sw=0;
else
sw=1;
if (sw==1)
{
if (i>=1 && i<=sz && j>=1 && j<=sz)
{
if (enb[i-1][j-1]==1)
{
if (bmb[i-1][j-1]==0)
{
if (bm_near[i-1][j-1]==0)
{
enb[i-1][j-1]=0;
pr(i*2,j*2+1,'.');
clr(i,j);
}else
{
enb[i-1][j-1]=0;
gotoxy(i*2,j*2+1);
cout<<bm_near[i-1][j-1];
}
}
}
}
}
}
return;
}
///.................................................................................................
void clr_ar(int x,int y)
{
gotoxy(2*x-1,2*y);
cout<<' ';
gotoxy(2*x,2*y);
cout<<' ';
gotoxy(2*x+1,2*y);
cout<<' ';
gotoxy(2*x-1,2*y+1);
cout<<' ';
gotoxy(2*x+1,2*y+1);
cout<<' ';
gotoxy(2*x-1,2*y+2);
cout<<' ';
gotoxy(2*x,2*y+2);
cout<<' ';
gotoxy(2*x+1,2*y+2);
cout<<' ';
return;
}
///////..................................................................................
void ins_ar(int x,int y)
{
gotoxy(2*x,2*y);
cout<<(char)31;
gotoxy(2*x-1,2*y+1);
cout<<(char)16;
gotoxy(2*x+1,2*y+1);
cout<<(char)17;
gotoxy(2*x,2*y+2);
cout<<(char)30;
return;
}
///......................
void pr(int x,int y,char ch)
{
gotoxy(x,y);
cout<<ch;
}