扫雷源代码扫雷源代码
#include
#include #include
#include #include #include #include
#define NUM 9
typedef struct{
int click;
int bomb;
}space;
void table();
void mouse();
void bomb();
void over();
void start();
char name[15];
int a,b;
int Number=0,num=0,Score=0,Protecter=3,Sea...
扫雷源代码
#include
#include #include
#include #include #include #include
#define NUM 9
typedef struct{
int click;
int bomb;
}space;
void table();
void mouse();
void bomb();
void over();
void start();
char name[15];
int a,b;
int Number=0,num=0,Score=0,Protecter=3,Searcher=0;
char MINE[100];
char SCORE[200];
char PROTECTER[100];char SEARCHER[100];space ground[NUM][NUM];void main()
{
table();
bomb();
mouse();
getch();
closegraph();
}
void over()
{
setfillstyle( BLACK ) ;
bar(285,115,665,495) ;
setcolor( DARKGRAY ) ;
outtextxy( 432 , 304 , "您了,重新再来:输输输输输输输输输") ;}
void table()
{
initgraph(800,600);
HRGN rgn = CreateRectRgn(285,115,665,495);
setcliprgn(rgn);
setbkcolor(CYAN);
clearcliprgn();
setcliprgn(NULL);
setcolor(WHITE);
line(100,100,700,100);
line(100,100,100,500);
line(100,500,700,500);
line(700,100,700,500);
line(250,100,250,500);
line(100,350,250,350);
rectangle(130,250,220,290);
rectangle(130,200,220,240);
rectangle(130,160,220,190);
setcolor(WHITE);
setbkcolor(BLACK);
outtextxy(135,170,"finish");
outtextxy(135,270,"start");
outtextxy(185,360,name);
int i,j;
for(i=0; i<10; i=i++)
line(285,42*i+115,665,42*i+115);
for(j=0; j<10; j=j++)
line(42*j+285,115,42*j+285,495);
outtextxy(110,380,"bomb");
outtextxy(136,217,"pause");
outtextxy(185,380,MINE);
outtextxy(110,360,"name");
outtextxy(110,400,"life");
outtextxy(110,420,"searcher");
outtextxy(110,440,"score");
sprintf(PROTECTER,"%d",Protecter);
outtextxy(185,400,PROTECTER);
sprintf(SEARCHER,"%d",Searcher);
outtextxy(185,420,SEARCHER);
sprintf(SCORE,"%d",Score);
outtextxy(185,440,SCORE);
}
void start()
{
InputBox(name, 60, "输输入您的姓名");
outtextxy(185,360,name);
cleardevice();
clearcliprgn();
setcliprgn(NULL);
table();
bomb();
setcolor(WHITE);
Number=0;
Score=0;
Protecter=3;
Searcher=0;
sprintf(PROTECTER,"%d",Protecter);
outtextxy(185,400,PROTECTER);
sprintf(SEARCHER,"%d",Searcher);
outtextxy(185,420,SEARCHER);
sprintf(SCORE,"%d",Score);
outtextxy(185,440,SCORE);
}
void mouse()
{
MOUSEMSG m=GetMouseMsg();
char ch[20];
while (true){
if(MouseHit())
m=GetMouseMsg();
switch(m.uMsg){
case WM_MOUSEMOVE:
sprintf(ch,"x:%d y:%d",m.x,m.y);
outtextxy(700,565,ch);
break;
case WM_RBUTTONDOWN:
if(Searcher>0){
for(a=0;a=a*42+285 && m.x<(a+1)*42+285 && m.y>=b*42+115 && m.y<(b+1)*42+115){
Protecter++;
}
Searcher--;
}
}
}
else
continue;
case WM_LBUTTONDOWN:
for(a=0;a=a*42+285
&& m.x<(a+1)*42+285 && m.y>=b*42+115 && m.y<(b+1)*42+115){
if(ground[a][b].bomb==2){
Score+=10;
char Number[20];
if(ground[a-1][b-1].bomb==3)
num++;
if(ground[a][b-1].bomb == 3)
num++;
if(ground[a-1][b].bomb== 3)
num++;
if(ground[a+1][b].bomb== 3)
num++;
if(ground[a][b+1].bomb == 3)
num++;
if(ground[a+1]
[b+1].bomb==3)
num++;
if(ground[a+1][b-1].bomb==3)
num++;
if(ground[a-1][b+1].bomb==3)
num++;
ground[a][b].click=1;
sprintf(Number,"%d",num);
outtextxy(a*42+300,b*42+130,Number);
setfillstyle(GREEN);
floodfill(a*42+300,b*42+130,WHITE);
num=0;
}
else
if(ground[a][b].bomb==3){
outtextxy(a*42+300,b*42+130,"雷");
setfillstyle(RED);
floodfill(a*42+300,b*42+130,WHITE);
ground[a][b].click=1;
Score-=10;
Protecter--;
if(Protecter<0)
over();
}
if(ground[a][b].bomb==1){
outtextxy(a*42+300,b*42+130," +");
setfillstyle(GREEN);
floodfill(a*42+300,b*42+130,WHITE);
ground[a][b].click=1;
Protecter++;
Score+=10;
char Number[20];
if(ground[a-1][b-
1].bomb==3)
num++;
if(ground[a][b-
1].bomb == 3)
num++;
if(ground[a-1]
[b].bomb== 3)
num++;
if(ground[a+1]
[b].bomb== 3)
num++;
if(ground[a]
[b+1].bomb == 3)
num++;
if(ground[a+1]
[b+1].bomb==3)
num++;
if(ground[a+1][b-
1].bomb==3)
num++;
if(ground[a-1]
[b+1].bomb==3)
num++;
ground[a][b].click=1;
sprintf(Number,"%d",num);
outtextxy(a*42+300,b*42+130,Number);
setfillstyle(GREEN);
floodfill(a*42+300,b*42+130,WHITE);
num=0;
}
if(ground[a][b].bomb==0){
outtextxy(a*42+300,b*42+130," !");
setfillstyle(GREEN);
floodfill(a*42+300,b*42+130,WHITE);
ground[a][b].click=1;
Searcher++;
Score+=10;
char Number[20];
if(ground[a-1][b-
1].bomb==3)
num++;
if(ground[a][b-
1].bomb == 3)
num++;
if(ground[a-1]
[b].bomb== 3)
num++;
if(ground[a+1]
[b].bomb== 3)
num++;
if(ground[a]
[b+1].bomb == 3)
num++;
if(ground[a+1]
[b+1].bomb==3)
num++;
if(ground[a+1][b-
1].bomb==3)
num++;
if(ground[a-1]
[b+1].bomb==3)
num++;
ground[a][b].click=1;
sprintf(Number,"%d",num);
outtextxy(a*42+300,b*42+130,Number);
setfillstyle(GREEN);
floodfill(a*42+300,b*42+130,WHITE);
num=0;
}
setcolor(WHITE);
sprintf(PROTECTER,"%d",Protecter);
outtextxy(185,400,PROTECTER);
sprintf(SEARCHER,"%d",Searcher);
outtextxy(185,420,SEARCHER);
sprintf(SCORE,"%d",Score);
outtextxy(185,440,SCORE);
}
}
}
if(m.x<=220 && m.x>=130 && m.y<=190 && m.y>=160){
exit(1);
}
if(m.x>=130 && m.x<=220 && m.y>=260 && m.y<=290) {
start();
}
}
}
}
void bomb()
{
srand(time(NULL));
for(a=0;a
本文档为【扫雷源代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。