#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<graphics.h>
#include<dos.h>
#define LEFT 1
#define RIGHT 2
struct bomb
{int x;
int y;
int bomb;
int mark;
int lclick;
}bomb[18][18];
void instruction(int *bnum);
void desk(int bnum);
void getmouse(void);
void ReadMouse(int *click,int *x,int *y);
void play(void);
void bombfind(void);
void search(int getx,int gety,int click,int *found);
void leftclick(int x,int y);
void ShowMouse(void);
void ErrMsg(void);
int InitMouse(void);
void str(int num,int *str);
main()
{int gdiver=VGA,gmode=VGAHI;
initgraph(&gdiver,&gmode,"");
paly();
}
void Play(void)
{int getx,gety,click,x,y,found=0,bnum=0,restart=0,stop=0,dt;
char st1[4];
time_t bt=time(NULL);
instruction(&bnum);
desk(bnum);
while((!restart)&&(!stop)&&(found!=bnum))
{dt=(int)difftime(time(NULL),bt);
str(dt,st1);
outtextxy(0,60,st1);
ReadMouse(&click,&getx,&gety);
if((getx>=543)&&(getx<=623)&&(gety>=207)&&(gety<=255))
play();
if((getx>=543)&&(getx<=623)&&(gety>=351)&&(gety<=399))
{closegraph();
exit(1);
}
if((getx>=95)&&(getx<=527)&&(gety>=16)&&(gety<=447))
search(getx,gety,click,&found);
}
if(found==bnum)
{outtextxy(16,304,"YOU WIN!");
delay(10000);
play();
}
}
void instruction(int *bnum)
{int getx,gety,click;
getmouse();
setbkcolor(12);
setcolor(0);
outtextxy(240,64,"This is a game of ");
outtextxy(240,112,"Searching bomb 1.1");
outtextxy(240,160,"Expored by XuBin");
outtextxy(240,208,"2004.6");
outtextxy(240,256,"Please choose th number of bombs:");
outtextxy(240,304,"30");
outtextxy(240,352,"60");
outtextxy(240,400,"160");
setfillstyle(1,11);
bar(336,304,432,336);
bar(336,352,432,385);
bar(336,400,432,432);
while(!(*bnum))
{ReadeMouse(&click,&getx,&gety);
delay(300);
if(getx>=336&&getx<=432&&gety>=304&&gety<=336&&(click!=0))
*bnum=30;
if(getx>=336&&getx<=432&&gety>=352&&gety<=385&&(click!=0))
*bnum=60;
if(getx>=336&&getx<=432&&gety>=400&&gety<=432&&(click!=0))
*bnum=160;
}
cleardevice();
}
void desk(int bnum)
{int x,y,xx=71,yy=-8,g;
char st2[4];
setbkcolor(2);
setcolor(14);
setfillstyle(11,1);
setlinestyle(0,0,1);
for(y=0;y<18;y++)
{yy+=24;
if(y!=17) line(79,yy+24,543,yy+24);
for(x=0;x<18;x++)
{bomb[x][y].x=(xx+=24);
bomb[x][y].y=yy;
bomb[x][y].bomb=0;
bomb[x][y].mark=0;
bomb[x][y].lclick=0;
if((y==17)&&(x!=17))
line(xx+24,3,xx+24,463);
bar(bomb[x][y].x+1,bomb[x][y].y+1,bomb[x][y].x+23,bomb[x][y].y+23);
}
}
retangle(95,16,527,447);
setlinestyle(0,0,3)
retangle(79,3,543,463);
randomize();
for(g=0;g<bnum;g++)
{x=rand()%18; y=rand()%18;
if(bomb[x][y].bomb==0)
bomb[x][y].bomb=1;
else
g--;
}
setfillstyle(11,3);
bar(560,207,623,255);
bar(560,35,623,399);
outtextxy(16,16," TIME:");
outtextxy(16,112," BOMB:");
str(bnum,st2);
outtextxy(16,160,st2);
outtextxy(16,208," FOUND:");
outtextxy(560,64," SEARCH BOMB 1.0");
outtextxy(560,160," RESTART");
outtextxy(560,304," STOP");
}
void getmouse(void)
{if(!InitMouse())
ErrMsg();
ShowMouse();
}
int InitMouse(void)
{ union REGS Inr,Outr;
Inr.x.ax=0;
int86(0x33,&Inr,&Outr);
return Outr.x.ax;
}
void ShowMouse(void)
{ union REGS Inr,Outr;
Inr.x.ax=1;
int86(0x33,&Inr,&Inr);
}
void ReadMouse(int *f,int *x, int *y)
{union REGS Inr,Outr;
Inr.x.ax=3;
int86(0x33,&Inr,&Outr);
*f=Outr.x.bx;
*x=Outr.x.cx;
*y=Outr.x.dx;
}
void ErrMsg(void)
{outtextxy(0,0,"No Mouse Error!");
getch();
exit(1);
}
void bombfind(void)
{int x,y;
setfillstyle(1,0);
for(x=0;x<18;x++)
for(y=0;y<18;y++)
if(bomb[x][y].bomb==1)
bar(bomb[x][y].x+1,bomb[x][y].y+1;bomb[x][y].x+23,bomb[x][y].y+23);
closegraph();
exit(1);
}
void search(int getx,int gety,int click,int *found)
{int x=-1,y=-1,a;
for(a=-8;a<448;a+=24)
{y+=1;
if((gety>a)&&(gety<(a+24)))
break;
}
for(a=71;a<527;a+=24)
{x+=1;
if((getx>a)&&(getx<(a+24)))
break;
}
if(click==RIGHT&&bomb[x][y].lclick==0)
{if(bomb[x][y].mark==1)
{bomb[x][y].mark=0;
if(bomb[x][y].bomb==0)
(*found)+=1;
else
(*found)-=1;
setfillstyle(11,1);
bar(bomb[x][y].x+1,bomb[x][y].y+1,bomb[x][y].x+23,bomb[x][y].y+23);
}
else
{bomb[x][y].mark=1;
if(bomb[x][y].bomb==0)
(*found)-=1;
esle
(*found)+=1;
setfillstyle(1,RED);
bar(bomb[x][y].x+1,bomb[x][y].y+1,bomb[x][y].x+9,bomb[x][y].y+9);
}
}
if(click==LEFT&&bomb[x][y].click==0&&bomb[x][y].mark==0)
{if(bomb[x][y].bomb==1)
{outtextxy(16,304,"FALL");
bombfind();
}
leftclick(x,y);
}
}
void leftclick(int x,int y)
{int count=0,a,b,c,d;
char st3[4];
if(x>=18&&y>=18&&x<0&&y<0&&bomb[x][y].click==1)
return;
bomb[x][y].lclick=1;
a=0>(x-1)? 0:(x-1);
b=17>(x+1)? (x+1):17;
c=0>(y-1)? 0:(y-1);
d=17>(y+1)? (y+1):17;
for(;a<=b;a++)
for(;c<=d;c++)
if(bomb[x][y].bomb==1)
count++;
if(count!=1)
{str(count,st3);
outtextxy(bomb[x][y].x,bomb[x][y].y,st3);
}
leftclick(x+1,y);
leftclick(x-1,y);
leftclick(x,y+1);
leftclick(x,y-1);
}
void str(int num,int *st)
{int x,y,z;
x=num%100;
y=(num-100*x)%10;
z=num-100*x-10*y;
st[0]=x+48;
st[1]=y+48;
st[2]=z+48;
st[3]='\0';
}
温馨提示:内容为网友见解,仅供参考