回 帖 发 新 帖 刷新版面

主题:星空模拟

'我这里没加注释
DECLARE FUNCTION Get.PicNober! (x1&, y1&, x2&, y2&)
DEFINT A-Z
SCREEN 12
RANDOMIZE TIMER
DIM MyName(560) AS LONG
FOR i = 0 TO 559: READ MyName(i): NEXT
DIM StarPic(4, 2) AS LONG
FOR i = 0 TO 1
   CIRCLE (10, 10), i, 15
   PAINT (10, 10), 15, 15
   GET (10 - i, 10 - i)-(10 + i, 10 + i), StarPic(0, i)
   LINE (0, 0)-(20, 20), 0, BF
NEXT

PUT (175, 100), MyName, PSET
ERASE MyName
count = 200
DIM Star&(count, 6)
Midx& = 320: Midy& = 240

FOR i = 0 TO count - 1
   Star&(i, 2) = RND * 10 + .3
   Star&(i, 3) = RND * 6 + .2
   N = INT(RND * 2004) MOD 2
   IF N = 0 THEN
         Star&(i, 4) = -1
       ELSE
         Star&(i, 4) = 1
   END IF
   N = INT(RND * 2004) MOD 2
   IF N = 0 THEN
         Star&(i, 5) = -1
       ELSE
         Star&(i, 5) = 1
   END IF
   Star&(i, 0) = Midx& + Star&(i, 2) * Star&(i, 4)
   Star&(i, 1) = Midy& + Star&(i, 3) * Star&(i, 5)
   PUT (Star&(i, 0), Star&(i, 1)), StarPic(0, 0)
NEXT

WHILE INKEY$ = ""
  FOR i = 0 TO count - 1
     NN = Get.PicNober(Midx&, Midy&, Star&(i, 0), Star&(i, 1))
     PUT (Star&(i, 0), Star&(i, 1)), StarPic(0, NN)
     
     Star&(i, 0) = Star&(i, 0) + Star&(i, 2) * Star&(i, 4)
     Star&(i, 1) = Star&(i, 1) + Star&(i, 3) * Star&(i, 5)
     IF Star&(i, 0) > 630 OR Star&(i, 0) < 0 OR Star&(i, 1) < 0 OR Star&(i, 1) > 470 THEN
        Star&(i, 2) = RND * 10 + .3
        Star&(i, 3) = RND * 6 + .2
        N = INT(RND * 2004) MOD 2
        IF N = 0 THEN
              Star&(i, 4) = -1
           ELSE
              Star&(i, 4) = 1
        END IF
        N = INT(RND * 2004) MOD 2
        IF N = 0 THEN
             Star&(i, 5) = -1
           ELSE
             Star&(i, 5) = 1
        END IF
        Star&(i, 0) = Midx& + Star&(i, 2) * Star&(i, 4)
        Star&(i, 1) = Midy& + Star&(i, 3) * Star&(i, 5)
     END IF

     NN = Get.PicNober(Midx&, Midy&, Star&(i, 0), Star&(i, 1))
     PUT (Star&(i, 0), Star&(i, 1)), StarPic(0, NN)
  NEXT
WEND
END

DATA 1048856,133120,1052689,1074266112,4096,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,34078720,269488384,134217728
DATA 1048640,0,0,0,0,0,130111,135271441,1075576832,63551
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,33308416,269750528,469762056,16269120,0,0,0,0
DATA 0,-25229280,-2012152289,1089470464,1006637088,0,283115544,2083535884,800824,8126588
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,2131238912,285089790,-268435320
DATA 1056832,60,-536864768,809241616,205011068,2080406528,37812287,1209143313,1074790400,1711296552
DATA 0,811597848,-971479528,1862764,12976326,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1090010880,303042818,268435528,5253184,102,1610618880,409344048,476867782
DATA -973027840,1149503520,1761483005,1141964800,-1040166876,0,811597824,101499440,3983046,393222
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,-2079842304,-31916732,285212776
DATA 5252164,194,1610612736,214052912,1019659782,100664832,806156351,672332819,1291649024,-1073704926
DATA -590947204,-60000712,202162224,7128774,393222,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,217595648,318509872,-50331608,9445964,-958628672,1819687132,213922044,1824966156
DATA 100664832,403701761,135661618,1343291392,-1073704926,1992713926,813091864,403488816,13424342,3932220
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,268435712,369635864,285212680
DATA 9445968,-966342976,1993087094,213921840,-858335720,1006648320,136316961,135985211,1077018624,-1073737695
DATA 1724278470,812043288,806142000,16701142,393222,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,537403648,452475656,838860808,1057088,-966342976,1724651622,213921840,-19474896
DATA 100664832,64575,137496662,1077411840,-1073737695,1623615174,812043288,1611448368,837318,393222
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,16531200,839407104,939524104
DATA 1057088,-966342976,1724651616,213921840,214353504,100664832,-130088927,148043859,-1605107712,-1040150494
DATA 1623615174,812043288,-1072905680,837318,393222,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1056973056,-755477512,1409286152,9446048,-966342974,1724651616,214052912,214353600
DATA 100664832,69697,1209155728,-1605369856,1711312930,1623615174,912706584,-971479528,403467372,12982470
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,17842432,306221056,1342177352
DATA 9446048,-966343066,1724651616,409344054,208432326,-971454952,129215,-2012021217,277938176,1006653476
DATA -260146052,484867132,-30393332,404633656,8132732,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,33079040,318643968,-1862270840,5252112,2122087484,-428065552,809241628,507001086
DATA 2081979416,65537,336805904,135331840,20520,417792,3072,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,16777472,322965504,285212692
DATA 5253128,106954752,786432,0,0,0,67175425,571650064,236060672,4656
DATA 811008,52224,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,17039616,313528324,301989922,1191950,207618048,13369344,0,0
DATA 0,-16777473,1112542737,68419584,2624,16314368,30720,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,-65792,1343099390,335544386
DATA 671748,-118489088,7864320,0,0,0,0,-2145385450,1572864,1664
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,537138688,402653312,425984,0,0,0,0

DEFSNG A-Z
FUNCTION Get.PicNober (x1&, y1&, x2&, y2&)
   x = ABS(x2& - x1&)
   y = ABS(y2& - y1&)
   N = SQR(x * x + y * y)
   IF N < 80 THEN Get.PicNober = 0
   IF N > 79 THEN Get.PicNober = 1
END FUNCTION

回复列表 (共12个回复)

沙发

不怎么象啊,风,再改改,程序怎么这么复杂啊,有简单点的吗?

板凳

哈,为了显示MYNAME,花了蛮大力嘛

3 楼

有空时我再改进一下

4 楼

我也做了一个,我感觉很好。
这是一个扫雷程序,它的封面是我做的星空模拟。
E-MAIL:guanqingpeng@sohu.com

************************************************************
int sl[23][33][3];
long ii=10,jj=15,bfzj=20;

#include<stdlib.h>
#include<stdio.h>
#include<graphics.h>


void selfdefi()
{char *bmp,degn='\0';
int n=1;
cleardevice();
setcolor(3);
setlinestyle(0,0,3);
rectangle(243,148,397,332);
setfillstyle(1,1);
floodfill(300,300,3);
settextstyle(1,0,2);
setcolor(7);
outtextxy(261,151,"Self-defined");
setlinestyle(0,0,3);
setcolor(3);
line(245,175,395,175);
setlinestyle(0,0,1);
line(245,305,395,305);
settextstyle(3,0,2);
setcolor(7);
outtextxy(250,190,"MAX ROw:");
outtextxy(250,230,"MAX COL:");
outtextxy(250,270,"MINE NO:");
setcolor(15);
outtextxy(360,190,itoa(ii,bmp,10));
setcolor(7);
outtextxy(360,230,itoa(jj,bmp,10));
outtextxy(360,270,itoa(bfzj,bmp,10));
outtextxy(310,307,"OK");
fflush(stdin);
a:
if(kbhit()!=0)
{degn=getch();
if(degn=='\0')degn=getch();
}
if(degn!='H'&&degn!='M'&&degn!='K'&&degn!='P'&&degn!=13)goto a;
if(degn=='H'||degn=='P')
{
setcolor(7);
if(n==1){outtextxy(360,190,itoa(ii,bmp,10));}
if(n==2){outtextxy(360,230,itoa(jj,bmp,10));}
if(n==3){outtextxy(360,270,itoa(bfzj,bmp,10));}
if(n==4){outtextxy(310,307,"OK");}
if(degn=='H')n--;
if(degn=='P')n++;
if(n==0)n=4;
if(n==5)n=1;
setcolor(15);
if(n==1){outtextxy(360,190,itoa(ii,bmp,10));}
if(n==2){outtextxy(360,230,itoa(jj,bmp,10));}
if(n==3){outtextxy(360,270,itoa(bfzj,bmp,10));}
if(n==4){outtextxy(310,307,"OK");}
}
if(n==1&&(degn=='K'||degn=='M'))
{
setcolor(1);
outtextxy(360,190,itoa(ii,bmp,10));
if(degn=='K'){ii--;if(ii<6)ii=6;}
if(degn=='M'){ii++;if(ii>21)ii=21;}
setcolor(15);
outtextxy(360,190,itoa(ii,bmp,10));
}
if(n==2&&(degn=='K'||degn=='M'))
{
setcolor(1);
outtextxy(360,230,itoa(jj,bmp,10));
if(degn=='K'){jj--;if(jj<6)jj=6;}
if(degn=='M'){jj++;if(jj>31)jj=31;}
setcolor(15);
outtextxy(360,230,itoa(jj,bmp,10));
}
if(n==3&&(degn=='K'||degn=='M'))
{
setcolor(1);
outtextxy(360,270,itoa(bfzj,bmp,10));
if(degn=='K'){bfzj-=5;if(bfzj<5)bfzj=5;}
if(degn=='M'){bfzj+=5;if(bfzj>95)bfzj=95;}
setcolor(15);
outtextxy(360,270,itoa(bfzj,bmp,10));
}
if(n==4&&degn==13){return;}
degn='\0';
goto a;
}
void help()
{char str;
setfillstyle(1,1);
bar(245,150,395,330);
setcolor(3);
setlinestyle(0,0,1);
line(245,168,395,168);
settextstyle(2,0,6);
setcolor(15);
outtextxy(300,150,"HELP");
outtextxy(250,168,"          Up");
outtextxy(250,186,"          Down ");
outtextxy(250,204,"          Right");
outtextxy(250,222,"          Left");
outtextxy(250,240,"Esc       Menu");
outtextxy(250,258,"Ins       Ture");
outtextxy(250,276,"Space     Open");
outtextxy(250,294,"Enter     Quick");
outtextxy(250,312,"          Open");
line(255,170,255,182);
line(255,170,250,174);
line(255,170,260,174);
line(255,188,255,200);
line(255,200,250,196);
line(255,200,260,196);
line(251,230,261,230);
line(261,230,257,224);
line(261,230,257,236);
line(251,212,261,212);
line(251,212,255,207);
line(251,212,255,217);
for(;;)
if(kbhit()!=0)
  {str=getch();
  if(str==27)break;
  }
}
int dispmenu()
{ char degn,*menu[7],*quickkey[7];
int mn[7],k,i=1,iii;
menu[1]="Low-garde";
menu[2]="Middling";
menu[3]="High-garde";
menu[4]="Self-defined";
menu[5]="Help";
menu[6]="Quit";
quickkey[1]="L";
quickkey[2]="M";
quickkey[3]="I";
quickkey[4]="S";
quickkey[5]="E";
quickkey[6]="Q";
menu:
cleardevice();
setcolor(3);
setlinestyle(0,0,3);
rectangle(243,148,397,332);
setfillstyle(1,1);
bar(245,150,395,330);
setfillstyle(1,9);
bar(245,150+i*30-30,395,179+i*30-30);
setlinestyle(0,0,1);
setcolor(3);
for(iii=180;iii<=300;iii+=30)
line(245,iii,395,iii);
setcolor(7);
settextstyle(2,0,6);
outtextxy(250,180-24,menu[1]);
outtextxy(250,210-24,menu[2]);
outtextxy(250,240-24,"High-grade");
outtextxy(250,270-24,"Self-defined");
outtextxy(250,300-24,"Help");
outtextxy(250,330-24,"Quit");
setcolor(7);
outtextxy(370,180-24,"[ ]");
outtextxy(370,210-24,"[ ]");
outtextxy(370,240-24,"[ ]");
outtextxy(370,270-24,"[ ]") ;
outtextxy(370,300-24,"[ ]") ;
outtextxy(370,330-24,"[ ]") ;
setcolor(15);
outtextxy(378,180-24,"L");
outtextxy(378,210-24,"M");
outtextxy(378,240-24,"I");
outtextxy(378,270-24,"S") ;
outtextxy(378,300-24,"E") ;
outtextxy(378,330-24,"Q") ;
a:
if(kbhit()!=0){degn=getch();if(degn=='\0')degn=getch();}
if(degn=='l'||degn=='m'||degn=='i'||degn=='s'||degn=='e'||degn=='q')degn=degn+('Z'-'z');
if(degn!=13&&degn!='P'&&degn!='H'&&degn!='L'&&degn!='M'&&degn!='I'&&degn!='S'&&degn!='E'&&degn!='Q')goto a;
if(degn=='L'||degn=='M'||degn=='I'||degn=='S'||degn=='E'||degn=='Q')
{
mn[i]=0;
setfillstyle(1,1);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
if(degn=='L') i=1;
if(degn=='M') i=2;
if(degn=='I') i=3;
if(degn=='S') i=4;
if(degn=='E') i=5;
if(degn=='Q') i=6;
mn[i]=1;
setfillstyle(1,9);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
}
if(degn=='H'||degn=='P')
{mn[i]=0;
setfillstyle(1,1);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
if(degn=='H')i--;
if(degn=='P')i++;
if(i==0)i=6;
if(i==7)i=1;
mn[i]=1;
setfillstyle(1,9);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
}
if(degn==13)
{
degn='\0';
if(i==1){ii=8;jj=8;bfzj=(11*100/64);return(0)  ;}
if(i==2){ii=16;jj=16;bfzj=(43*100/(16*16));return(0);}
if(i==3){ii=16;jj=30;bfzj=(103*100/480);return(0);}
if(i==4){selfdefi();return(0);  }
if(i==5){help();i=5;goto menu;  }
if(i==6){return(1);  }
}
degn='\0';
goto a;
}
void picsl()
{
int colo;
setlinestyle(0,0,1);
setcolor(12  );
line(200,180,300,180);
line(200,180,200,255);
line(200,255,285,255);
line(285,255,285,305);
line(200,305,285,305);
line(200,305,200,320);
line(200,320,300,320);
line(300,320,300,240);
line(300,240,215,240);
line(215,240,215,195);
line(215,195,300,195);
line(300,195,300,180);
line(325,180,340,180);
line(325,180,325,320);
line(325,320,425,320);
line(425,320,425,305);
line(425,305,340,305);
line(340,305,340,180);
line(200,180,217,160);
line(300,180,317,160);
line(217,160,317,160);
line(300,195,317,175);
line(317,160,317,175);
line(232,220,232,195);
line(215,240,232,220);
line(232,220,317,220);
line(300,240,317,220);
line(300,320,317,300);
line(317,220,317,300);
line(200,305,217,285);
line(217,285,285,285);
line(325,180,342,160);
line(340,180,357,160);
line(342,160,357,160);
line(340,305,357,285);
line(357,160,357,285);
line(425,305,442,285);
line(357,285,442,285);
line(425,320,442,300);
line(442,285,442,300);
a:
colo=1;
setfillstyle(1,colo);
floodfill(250,187,12);
floodfill(260,170,12);
floodfill(310,175,12);
floodfill(225,220,12);
floodfill(265,230,12);
floodfill(310,270,12);
floodfill(245,295,12);
floodfill(375,315,12);
floodfill(335,170,12);
floodfill(345,240,12);
floodfill(380,295,12);
floodfill(428,310,12);
}
void feng()
{
int colo,tiao,lastdegn,i,a1[401][2],menu=0,tiao1=1,degn=0,tesu=1;
float a2[401][2][2],hl[401][2],lasthl[401][2],pp=0;
char aa;
int gdriver=DETECT,gmode=4;
initgraph(&gdriver,&gmode,"c:\tc");
for(i=0;i<401;i++)
{
a1[i][0]=i%8+1;
a:
a1[i][1]=rand()%14+2;
if(a1[i][1]==12)goto a;
a2[i][0][0]=rand()%6+1;
a2[i][0][1]=rand()%6+1;
a2[i][1][0]=(rand()%5+1)/10;
a2[i][1][1]=(rand()%5+1)/10;
if(a1[i][0]==1)
{hl[i][0]=rand()%240;hl[i][1]=rand()%160;}
if(a1[i][0]==2)
{hl[i][0]=rand()%240+200;hl[i][1]=rand()%240;}
if(a1[i][0]==3)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160;}
if(a1[i][0]==4)
{hl[i][0]=rand()%160;hl[i][1]=rand()%160+160;}
if(a1[i][0]==5)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+160;}
if(a1[i][0]==6)
{hl[i][0]=rand()%160;hl[i][1]=rand()%160+320;}
if(a1[i][0]==7)
{hl[i][0]=rand()%240+240;hl[i][1]=rand()%240+200;}
if(a1[i][0]==8)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+320;}
}
for(i=0;i<401;i++)
{
lasthl[i][0]=hl[i][0];
lasthl[i][1]=hl[i][1];
}
picsl();
for(;;)
{
for(i=0;i<401;i++)
{
if(kbhit()!=0){aa=getch();if(aa==27){return;}}
if(tiao1==1){tiao1=0;goto tiao1h;}
if(getpixel((int)(lasthl[i][0]),(int)(lasthl[i][1]))==1)goto tiao1h;
if(getpixel((int)(lasthl[i][0]),(int)(lasthl[i][1]))==12)goto tiao1h;
putpixel(lasthl[i][0],lasthl[i][1],0);
tiao1h:
lastdegn=degn;
if(getpixel((int)(hl[i][0]),(int)(hl[i][1]))==0)degn=1;else degn=0;
if(lastdegn==0&&degn==0)tiao=1;
if(degn==0)goto tiao3n;
putpixel((int)(hl[i][0]),(int)(hl[i][1]),a1[i][1]);
lasthl[i][1]=hl[i][1];
lasthl[i][0]=hl[i][0];
tiao3n:
a2[i][0][0]+=a2[i][1][0];
a2[i][0][1]+=a2[i][1][1];
if(a1[i][0]==1){hl[i][0]-=a2[i][0][0];hl[i][1]-=a2[i][0][1];}
if(a1[i][0]==2){hl[i][1]-=a2[i][0][1];}
if(a1[i][0]==3){hl[i][0]+=a2[i][0][0];hl[i][1]-=a2[i][0][1];}
if(a1[i][0]==4){hl[i][0]-=a2[i][0][0];}
if(a1[i][0]==5){hl[i][0]+=a2[i][0][0];}
if(a1[i][0]==6){hl[i][0]-=a2[i][0][0];hl[i][1]+=a2[i][0][1];}
if(a1[i][0]==7){hl[i][1]+=a2[i][0][1];}
if(a1[i][0]==8){hl[i][0]+=a2[i][0][0];hl[i][1]+=a2[i][0][1];}
if(hl[i][0]<=0||hl[i][0]>=640||hl[i][1]<=0||hl[i][1]>=480)
{
b:
a1[i][1]=rand()%14+2;
if(a1[i][1]==12)goto b;
a2[i][0][0]=rand()%6+1;
a2[i][0][1]=rand()%6+1;
a2[i][1][0]=(rand()%5+1)/100;
a2[i][1][1]=(rand()%5+1)/100;
if(a1[i][0]==1)
{hl[i][0]=rand()%240;hl[i][1]=rand()%160;}
if(a1[i][0]==2)
{hl[i][0]=rand()%240+200;hl[i][1]=rand()%240;}
if(a1[i][0]==3)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160;}
if(a1[i][0]==4)
{hl[i][0]=rand()%200;hl[i][1]=rand()%160+160;}
if(a1[i][0]==5)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+160;}
if(a1[i][0]==6)
{hl[i][0]=rand()%200;hl[i][1]=rand()%160+320;}
if(a1[i][0]==7)
{hl[i][0]=rand()%240+200;hl[i][1]=rand()%240+200;}
if(a1[i][0]==8)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+320;}
}
}
}
end:
;
}
int yingle()
{       int i,j,yesno;
for(i=1;i<=ii;i++)
for(j=1;j<=jj;j++)
if(sl[i][j][0]==1&&sl[i][j][2]!=2){yesno=0;goto end;}
yesno=1;
end:;
return(yesno);
}
void huacha(int i,int j)
{
setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
setlinestyle(0,0,3);
setcolor(4);
line((j-1)*20+4+5,(i-1)*20+42+5,j*20+2-5,i*20+40-5);
line(j*20+2-5,(i-1)*20+40+5, (j-1)*20+4+5,i*20+40-5) ;
}
void hualei(int i,int j,int ze)
{
if(ze==1)setfillstyle(1,6);else setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
setcolor(4);
circle((j-1)*20+3+10,(i-1)*20+41+10,7)                 ;
setfillstyle(1,4);
pieslice((j-1)*20+3+10,(i-1)*20+41+10,0,360,7);
}
void zero(int h, int s)
{ char str;
int i,j,h1,h2,s1,s2;
h1=h-1;h2=h+1;s1=s-1;s2=s+1;
if(h1<=0)h1=1;
if(h2>=ii+1)h2=ii;
if(s1<=0)s1=1;
if(s2>=jj+1)s2=jj;
for(i=h1;i<=h2;i++)
for(j=s1;j<=s2;j++)
{
if(i==h&&j==s)continue;
if(sl[i][j][2]==1)continue;
if(sl[i][j][1]==0)goto tiao5_1;
setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
settextstyle(2,0,7);
setcolor(sl[i][j][1]);outtextxy((j-1)*20+9,(i-1)*20+4+37,itoa(sl[i][j][1],str,10));
setlinestyle(0,0,1);
setcolor(7);
rectangle((j -1)*20+3+1,(i -1)*20+41+1,j *20+3-1,i *20+41-1);
sl[i][j][2]=1;
tiao5_1:
if(sl[i][j][1]==0&&sl[i][j][2]!=1)
{setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
setlinestyle(0,0,1);
setcolor(7);
rectangle((j -1)*20+3+1,(i -1)*20+41+1,j *20+3-1,i *20+41-1);
sl[i][j][2]=1;
zero(i,j);}
}
}
void huaqi(int qil,int qih)
{
setlinestyle(0,0,1);
setfillstyle(1,4);
bar(qil+6,qih+9,qil+5+7,qih+6+7);
setcolor(4);
line(qil+5+7,qih+6+7,qil+5+7,qih+20);
line(qil+11,qih+20,qil+13,qih+20);
}
void huawhy(int s,int h)
{
setfillstyle(1,7);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
settextstyle(0,0,2);
setcolor(13);
outtextxy(s*20+2-14,h*20+40-14,"?");
}
void leiqu(int ii, int jj)
{
int i;
setlinestyle(0,0,3);
setcolor(1);
rectangle(1,1,jj*20+5,ii*20+40+2);
setlinestyle(0,0,3);
line(1,39,jj*20+3,39);
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(4);
bar(3,41,jj*20+3,ii*20-1+40+2);
setcolor(0);
for(i=41;i<=ii*20+41;i+=20)
line(3,i,jj*20+3,i);
for(i=3;i<=jj*20+3;i+=20)
line(i,40,i,ii*20+40);
}
main()
{
char str;
int lie,kuan,kk1=0,col,kk,degn1,h1,h2,s1,s2,n,yesno,j,a,b,h=5,s=5,secon,iii,sign,jjj,hh=5,ss=5;
long i,leinum1,leinum=0,lei=0,nnn;
int gdriver=DETECT,gmode=4;
initgraph(&gdriver,&gmode,"c:\tc");
cleardevice();
feng();
menu:
closegraph();
initgraph(&gdriver,&gmode,"c:\tc");
h=5;s=5;hh=5;ss=5;leinum=0;kk1=0;lei=0;yesno=0;
if(dispmenu()==1)goto over;
cleardevice();
setviewport((640-jj*20+5)/2,(480-ii*20+40+2)/2,jj*20+5+(640-jj*20+5)/2,ii*20+40+2+(480-ii*20+40+2)/2,0);
leinum1=ii*jj*bfzj/100;
for(i=0;i<=ii+1;i++)
for(j=0;j<=jj+1;j++)
{sl[i][j][0]=0;sl[i][j][2]=0;}
for(i=1;i<=ii*jj*bfzj/100;i++)
{rands:
a=rand()%ii+1;
b=rand()%jj+1;
if(sl[a][b][0]==1)goto rands;else sl[a][b][0]=1;
}
for(i=1;i<=ii;i++)
{
for(j=1;j<=jj;j++)
{
for(iii=i-1;iii<=i+1;iii++)
for(jjj=j-1;jjj<=j+1;jjj++)
if(sl[iii][jjj][0]==1)lei++;
if(sl[i][j][0]==1)lei--;
sl[i][j][1]=lei;lei=0;}
}
leiqu(ii,jj);
setcolor(12);
circle( (jj*20+7)/2,20,16);
line((jj*20+7)/2-3,27,(jj*20+7)/2+3,27);
circle((jj*20+7)/2-7,15,1);
circle((jj*20+7)/2+7,15,1);
settextstyle(3,0,3);
setcolor(4);
outtextxy(20,10,itoa(sign=leinum1-leinum,str,10));
outtextxy(jj*20+5-15,10,"0");
nnn=0;secon=0;
for(;;)
{
gc:
if(kk1==1)nnn++;
if(nnn==41000)
{
settextstyle(3,0,3);
if(secon==9999||(jj<=7&&secon==999))goto tiaook;
if(secon<10)col=15;
if(secon>=10)col=30;
if(secon>=100)col=45;
if(secon>=1000)col=60;
setcolor(0);
outtextxy(jj*20+5-col,10,itoa(secon,str,10));
tiaook:
secon++;
if(jj<=7&&secon>999)goto asdf;
if(secon<10)col=15;
if(secon>=10)col=30;
if(secon>=100)col=45;
if(secon>=1000)col=60;
if(secon>10000)
{asdf:
settextstyle(0,0,5);
setcolor(12);
outtextxy(10,ii*10,"FOOL!");
for(;;)
if(kbhit()!=0)
{str=getch();
if(str==27)
break;}
goto menu;}
nnn=0;setcolor(4);outtextxy(jj*20+5-col,10,itoa(secon,str,10));}
sign='\0';
if( kbhit()!=0){sign=getch();if(sign=='\0')sign=getch();}
if(sign=='0')sign='R';
if(sign==27)goto menu;
if(sign!=13&&sign!='R'&&sign!='K'&&sign!='M'&&sign!=' '&&sign!='H'&&sign!='P'&&sign!=' ')goto gc;
if(sign=='K' && s-1<=0)goto gc;
if(sign=='M'&&s+1>=jj+1)goto gc;
if(sign=='H'&&h-1<=0)goto gc;
if(sign=='P'&&h+1>=ii+1)goto gc;
if(sign==13&&sl[h][s][2]!=1)goto gc;
if(sign==' '&&sl[h][s][2]!=0&&sl[h][s][2]==2)goto gc;
if(sign=='R'&&sl[h][s][2]==1)goto gc;
kk1=1;
if(sign=='R')
{
if(sl[h][s][2]==0)
{
  if(leinum>leinum1)lie=10;else lie=20;
  settextstyle(3,0,3);
  setcolor(0);
    outtextxy(lie,10,itoa(leinum1-leinum,str,10));
  leinum++;
   if(leinum>leinum1)lie=10;else lie=20;
  setcolor(4);
  outtextxy(lie,10,itoa(leinum1-leinum,str,10));
  sl[h][s][2]=2;
  huaqi(s*20-20+3,h*20+20-3);
  if(leinum==leinum1)yesno=yingle();
  if(yesno==1)
  {
  setlinestyle(0,0,1);
setcolor(0);
line((jj*20+7)/2-3,27,(jj*20+7)/2+3,27);
setcolor(12);
line((jj*20+7)/2-7-3,12,(jj*20+7)/2-7+3,15);
line((jj*20+7)/2-7+3,12,(jj*20+7)/2-7-3,15);
line((jj*20+7)/2+7+3,12,(jj*20+7)/2+7-3,15);
line((jj*20+7)/2+7-3,12,(jj*20+7)/2+7+3,15);
ellipse((jj*20+7)/2,20,240,300,6,10);
  getch();
  for(;;)
  if(kbhit()!=0)
  {str=getch();
  if(str==27)break;
  }
  goto menu;
  }
  goto zhuan;
  }
if(sl[h][s][2]==2)
  {
   settextstyle(3,0,3);
  setcolor(0);
    if(leinum>leinum1)lie=10;else lie=20;
    outtextxy(lie,10,itoa(leinum1-leinum,str,10));
  leinum--;
  if(leinum>leinum1)lie=10;else lie=20;
  setcolor(4);
    outtextxy(lie,10,itoa(leinum1-leinum,str,10));
      sl[h][s][2]=3;
  huawhy(s,h);
  goto zhuan;
  }
if(sl[h][s][2]==3)
  {
  sl[h][s][2]=0;
  setfillstyle(1,7);
  bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
  goto zhuan;
  }
}
zhuan:
if(sign==13)
{degn1=0;
h1=h-1;h2=h+1;s1=s-1;s2=s+1;
if(h1<=0)h1=1;
if(h2>=ii+1)h2=ii;
if(s1<=0)s1=1;
if(s2>=jj+1)s2=jj;
for(i=h1;i<=h2;i++)
for(j=s1;j<=s2;j++)
{
if(i==h&&j==s)continue;
if(sl[i][j][0]==1&&sl[i][j][2]!=2)degn1=1;
if(sl[i][j][0]==0&&sl[i][j][2]==2)degn1=1;
}
if(degn1==1)goto gc;
for(i=h1;i<=h2;i++)
for(j=s1;j<=s2;j++)
{ if(sl[i][j][2]==1)continue;
if(sl[i][j][2]==2)continue;
setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
settextstyle(2,0,7);
if(sl[i][j][1]!=0){setcolor(sl[i][j][1]);outtextxy((j-1)*20+9,(i-1)*20+4+37,itoa(sl[i][j][1],str,10));}else{sl[i][j][2]=1;zero(i,j);}
setlinestyle(0,0,1);
setcolor(7);
rectangle((j -1)*20+3+1,(i -1)*20+41+1,j *20+3-1,i *20+41-1);
sl[i][j][2]=1;
}
}
if(sign==' ')
{
if(sl[h][s][0]==1)
{
setfillstyle(1,13);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
for(i=1;i<=ii;i++)
for(j=1;j<=jj;j++)
{ if(i==h&&j==s)kk=1;else kk=0;
if(sl[i][j][0]==0&&sl[i][j][2]==2)huacha(i,j);
if(sl[i][j][0]==1&&sl[i][j][2]!=2)hualei(i,j,kk);
}
fflush(stdin);
setlinestyle(0,0,3);
setcolor(0);
line((jj*20+7)/2-3,27,(jj*20+7)/2+3,27);
for(;;)
{
setcolor(12);
setlinestyle(0,0,kuan);
line((jj*20+7)/2-7-3,12,(jj*20+7)/2-7+3,18);
line((jj*20+7)/2-7+3,12,(jj*20+7)/2-7-3,18);
line((jj*20+7)/2+7+3,12,(jj*20+7)/2+7-3,18);
line((jj*20+7)/2+7-3,12,(jj*20+7)/2+7+3,18);
circle( (jj*20+7)/2,20,16);
ellipse((jj*20+7)/2,37,60,120,6,10);
circle((jj*20+7)/2-7,15,1);
circle((jj*20+7)/2+7,15,1);
if(kbhit()!=0)
{str=getch();
if(str==27){fflush(stdin);break;}}
}
goto menu;
}
if(sl[h][s][1]==0)goto tiao4;
setfillstyle(1,8);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
settextstyle(2,0,7);
setcolor(sl[h][s][1]);outtextxy((s-1)*20+9,(h-1)*20+4+37,itoa(sl[h][s][1],str,10));
tiao4:
if(sl[h][s][1]==0)
{setfillstyle(1,8);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
sl[h][s][2]=1;
zero(h,s);
}
sl[h][s][2]=1;
goto aa;
}
if(sign=='K'){s--;ss=s+1;hh=h;goto aa;}
if(sign=='M'){s++;ss=s-1;hh=h;goto aa;  }
if(sign=='H'){h--;hh=h+1;ss=s;goto aa;   }
if(sign=='P'){h++;hh=h-1;ss=s;goto aa;    }
aa:
sign='\0';
setlinestyle(0,0,1);
setcolor(7);
rectangle((ss-1)*20+3+1,(hh-1)*20+41+1,ss*20+3-1,hh*20+41-1);
setlinestyle(4,0xc132db6d,1);
setcolor(11);
rectangle((s-1)*20+3+1,(h-1)*20+41+1,s*20+3-1,h*20+41-1);
}
over:
cleardevice();
settextstyle(0,0,9);
setcolor(13);
outtextxy(40,190,"Goodbye!");
settextstyle(0,0,1);
setcolor(8);
outtextxy(500,450,"Writer : Tube");
getch();
closegraph();
}


5 楼

我也做了一个,我感觉很好。
这是一个扫雷程序,它的封面是我做的星空模拟。
E-MAIL:guanqingpeng@sohu.com

************************************************************
int sl[23][33][3];
long ii=10,jj=15,bfzj=20;

#include<stdlib.h>
#include<stdio.h>
#include<graphics.h>


void selfdefi()
{char *bmp,degn='\0';
int n=1;
cleardevice();
setcolor(3);
setlinestyle(0,0,3);
rectangle(243,148,397,332);
setfillstyle(1,1);
floodfill(300,300,3);
settextstyle(1,0,2);
setcolor(7);
outtextxy(261,151,"Self-defined");
setlinestyle(0,0,3);
setcolor(3);
line(245,175,395,175);
setlinestyle(0,0,1);
line(245,305,395,305);
settextstyle(3,0,2);
setcolor(7);
outtextxy(250,190,"MAX ROw:");
outtextxy(250,230,"MAX COL:");
outtextxy(250,270,"MINE NO:");
setcolor(15);
outtextxy(360,190,itoa(ii,bmp,10));
setcolor(7);
outtextxy(360,230,itoa(jj,bmp,10));
outtextxy(360,270,itoa(bfzj,bmp,10));
outtextxy(310,307,"OK");
fflush(stdin);
a:
if(kbhit()!=0)
{degn=getch();
if(degn=='\0')degn=getch();
}
if(degn!='H'&&degn!='M'&&degn!='K'&&degn!='P'&&degn!=13)goto a;
if(degn=='H'||degn=='P')
{
setcolor(7);
if(n==1){outtextxy(360,190,itoa(ii,bmp,10));}
if(n==2){outtextxy(360,230,itoa(jj,bmp,10));}
if(n==3){outtextxy(360,270,itoa(bfzj,bmp,10));}
if(n==4){outtextxy(310,307,"OK");}
if(degn=='H')n--;
if(degn=='P')n++;
if(n==0)n=4;
if(n==5)n=1;
setcolor(15);
if(n==1){outtextxy(360,190,itoa(ii,bmp,10));}
if(n==2){outtextxy(360,230,itoa(jj,bmp,10));}
if(n==3){outtextxy(360,270,itoa(bfzj,bmp,10));}
if(n==4){outtextxy(310,307,"OK");}
}
if(n==1&&(degn=='K'||degn=='M'))
{
setcolor(1);
outtextxy(360,190,itoa(ii,bmp,10));
if(degn=='K'){ii--;if(ii<6)ii=6;}
if(degn=='M'){ii++;if(ii>21)ii=21;}
setcolor(15);
outtextxy(360,190,itoa(ii,bmp,10));
}
if(n==2&&(degn=='K'||degn=='M'))
{
setcolor(1);
outtextxy(360,230,itoa(jj,bmp,10));
if(degn=='K'){jj--;if(jj<6)jj=6;}
if(degn=='M'){jj++;if(jj>31)jj=31;}
setcolor(15);
outtextxy(360,230,itoa(jj,bmp,10));
}
if(n==3&&(degn=='K'||degn=='M'))
{
setcolor(1);
outtextxy(360,270,itoa(bfzj,bmp,10));
if(degn=='K'){bfzj-=5;if(bfzj<5)bfzj=5;}
if(degn=='M'){bfzj+=5;if(bfzj>95)bfzj=95;}
setcolor(15);
outtextxy(360,270,itoa(bfzj,bmp,10));
}
if(n==4&&degn==13){return;}
degn='\0';
goto a;
}
void help()
{char str;
setfillstyle(1,1);
bar(245,150,395,330);
setcolor(3);
setlinestyle(0,0,1);
line(245,168,395,168);
settextstyle(2,0,6);
setcolor(15);
outtextxy(300,150,"HELP");
outtextxy(250,168,"          Up");
outtextxy(250,186,"          Down ");
outtextxy(250,204,"          Right");
outtextxy(250,222,"          Left");
outtextxy(250,240,"Esc       Menu");
outtextxy(250,258,"Ins       Ture");
outtextxy(250,276,"Space     Open");
outtextxy(250,294,"Enter     Quick");
outtextxy(250,312,"          Open");
line(255,170,255,182);
line(255,170,250,174);
line(255,170,260,174);
line(255,188,255,200);
line(255,200,250,196);
line(255,200,260,196);
line(251,230,261,230);
line(261,230,257,224);
line(261,230,257,236);
line(251,212,261,212);
line(251,212,255,207);
line(251,212,255,217);
for(;;)
if(kbhit()!=0)
  {str=getch();
  if(str==27)break;
  }
}
int dispmenu()
{ char degn,*menu[7],*quickkey[7];
int mn[7],k,i=1,iii;
menu[1]="Low-garde";
menu[2]="Middling";
menu[3]="High-garde";
menu[4]="Self-defined";
menu[5]="Help";
menu[6]="Quit";
quickkey[1]="L";
quickkey[2]="M";
quickkey[3]="I";
quickkey[4]="S";
quickkey[5]="E";
quickkey[6]="Q";
menu:
cleardevice();
setcolor(3);
setlinestyle(0,0,3);
rectangle(243,148,397,332);
setfillstyle(1,1);
bar(245,150,395,330);
setfillstyle(1,9);
bar(245,150+i*30-30,395,179+i*30-30);
setlinestyle(0,0,1);
setcolor(3);
for(iii=180;iii<=300;iii+=30)
line(245,iii,395,iii);
setcolor(7);
settextstyle(2,0,6);
outtextxy(250,180-24,menu[1]);
outtextxy(250,210-24,menu[2]);
outtextxy(250,240-24,"High-grade");
outtextxy(250,270-24,"Self-defined");
outtextxy(250,300-24,"Help");
outtextxy(250,330-24,"Quit");
setcolor(7);
outtextxy(370,180-24,"[ ]");
outtextxy(370,210-24,"[ ]");
outtextxy(370,240-24,"[ ]");
outtextxy(370,270-24,"[ ]") ;
outtextxy(370,300-24,"[ ]") ;
outtextxy(370,330-24,"[ ]") ;
setcolor(15);
outtextxy(378,180-24,"L");
outtextxy(378,210-24,"M");
outtextxy(378,240-24,"I");
outtextxy(378,270-24,"S") ;
outtextxy(378,300-24,"E") ;
outtextxy(378,330-24,"Q") ;
a:
if(kbhit()!=0){degn=getch();if(degn=='\0')degn=getch();}
if(degn=='l'||degn=='m'||degn=='i'||degn=='s'||degn=='e'||degn=='q')degn=degn+('Z'-'z');
if(degn!=13&&degn!='P'&&degn!='H'&&degn!='L'&&degn!='M'&&degn!='I'&&degn!='S'&&degn!='E'&&degn!='Q')goto a;
if(degn=='L'||degn=='M'||degn=='I'||degn=='S'||degn=='E'||degn=='Q')
{
mn[i]=0;
setfillstyle(1,1);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
if(degn=='L') i=1;
if(degn=='M') i=2;
if(degn=='I') i=3;
if(degn=='S') i=4;
if(degn=='E') i=5;
if(degn=='Q') i=6;
mn[i]=1;
setfillstyle(1,9);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
}
if(degn=='H'||degn=='P')
{mn[i]=0;
setfillstyle(1,1);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
if(degn=='H')i--;
if(degn=='P')i++;
if(i==0)i=6;
if(i==7)i=1;
mn[i]=1;
setfillstyle(1,9);
bar(245,(151+i*30-30),395,(179+i*30-30));
setcolor(7);
outtextxy(370,180+i*30-30-24,"[ ]");
outtextxy(250,180+i*30-30-24,menu[i]);
setcolor(15);
outtextxy(378,180+i*30-30-24,quickkey[i]);
}
if(degn==13)
{
degn='\0';
if(i==1){ii=8;jj=8;bfzj=(11*100/64);return(0)  ;}
if(i==2){ii=16;jj=16;bfzj=(43*100/(16*16));return(0);}
if(i==3){ii=16;jj=30;bfzj=(103*100/480);return(0);}
if(i==4){selfdefi();return(0);  }
if(i==5){help();i=5;goto menu;  }
if(i==6){return(1);  }
}
degn='\0';
goto a;
}
void picsl()
{
int colo;
setlinestyle(0,0,1);
setcolor(12  );
line(200,180,300,180);
line(200,180,200,255);
line(200,255,285,255);
line(285,255,285,305);
line(200,305,285,305);
line(200,305,200,320);
line(200,320,300,320);
line(300,320,300,240);
line(300,240,215,240);
line(215,240,215,195);
line(215,195,300,195);
line(300,195,300,180);
line(325,180,340,180);
line(325,180,325,320);
line(325,320,425,320);
line(425,320,425,305);
line(425,305,340,305);
line(340,305,340,180);
line(200,180,217,160);
line(300,180,317,160);
line(217,160,317,160);
line(300,195,317,175);
line(317,160,317,175);
line(232,220,232,195);
line(215,240,232,220);
line(232,220,317,220);
line(300,240,317,220);
line(300,320,317,300);
line(317,220,317,300);
line(200,305,217,285);
line(217,285,285,285);
line(325,180,342,160);
line(340,180,357,160);
line(342,160,357,160);
line(340,305,357,285);
line(357,160,357,285);
line(425,305,442,285);
line(357,285,442,285);
line(425,320,442,300);
line(442,285,442,300);
a:
colo=1;
setfillstyle(1,colo);
floodfill(250,187,12);
floodfill(260,170,12);
floodfill(310,175,12);
floodfill(225,220,12);
floodfill(265,230,12);
floodfill(310,270,12);
floodfill(245,295,12);
floodfill(375,315,12);
floodfill(335,170,12);
floodfill(345,240,12);
floodfill(380,295,12);
floodfill(428,310,12);
}
void feng()
{
int colo,tiao,lastdegn,i,a1[401][2],menu=0,tiao1=1,degn=0,tesu=1;
float a2[401][2][2],hl[401][2],lasthl[401][2],pp=0;
char aa;
int gdriver=DETECT,gmode=4;
initgraph(&gdriver,&gmode,"c:\tc");
for(i=0;i<401;i++)
{
a1[i][0]=i%8+1;
a:
a1[i][1]=rand()%14+2;
if(a1[i][1]==12)goto a;
a2[i][0][0]=rand()%6+1;
a2[i][0][1]=rand()%6+1;
a2[i][1][0]=(rand()%5+1)/10;
a2[i][1][1]=(rand()%5+1)/10;
if(a1[i][0]==1)
{hl[i][0]=rand()%240;hl[i][1]=rand()%160;}
if(a1[i][0]==2)
{hl[i][0]=rand()%240+200;hl[i][1]=rand()%240;}
if(a1[i][0]==3)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160;}
if(a1[i][0]==4)
{hl[i][0]=rand()%160;hl[i][1]=rand()%160+160;}
if(a1[i][0]==5)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+160;}
if(a1[i][0]==6)
{hl[i][0]=rand()%160;hl[i][1]=rand()%160+320;}
if(a1[i][0]==7)
{hl[i][0]=rand()%240+240;hl[i][1]=rand()%240+200;}
if(a1[i][0]==8)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+320;}
}
for(i=0;i<401;i++)
{
lasthl[i][0]=hl[i][0];
lasthl[i][1]=hl[i][1];
}
picsl();
for(;;)
{
for(i=0;i<401;i++)
{
if(kbhit()!=0){aa=getch();if(aa==27){return;}}
if(tiao1==1){tiao1=0;goto tiao1h;}
if(getpixel((int)(lasthl[i][0]),(int)(lasthl[i][1]))==1)goto tiao1h;
if(getpixel((int)(lasthl[i][0]),(int)(lasthl[i][1]))==12)goto tiao1h;
putpixel(lasthl[i][0],lasthl[i][1],0);
tiao1h:
lastdegn=degn;
if(getpixel((int)(hl[i][0]),(int)(hl[i][1]))==0)degn=1;else degn=0;
if(lastdegn==0&&degn==0)tiao=1;
if(degn==0)goto tiao3n;
putpixel((int)(hl[i][0]),(int)(hl[i][1]),a1[i][1]);
lasthl[i][1]=hl[i][1];
lasthl[i][0]=hl[i][0];
tiao3n:
a2[i][0][0]+=a2[i][1][0];
a2[i][0][1]+=a2[i][1][1];
if(a1[i][0]==1){hl[i][0]-=a2[i][0][0];hl[i][1]-=a2[i][0][1];}
if(a1[i][0]==2){hl[i][1]-=a2[i][0][1];}
if(a1[i][0]==3){hl[i][0]+=a2[i][0][0];hl[i][1]-=a2[i][0][1];}
if(a1[i][0]==4){hl[i][0]-=a2[i][0][0];}
if(a1[i][0]==5){hl[i][0]+=a2[i][0][0];}
if(a1[i][0]==6){hl[i][0]-=a2[i][0][0];hl[i][1]+=a2[i][0][1];}
if(a1[i][0]==7){hl[i][1]+=a2[i][0][1];}
if(a1[i][0]==8){hl[i][0]+=a2[i][0][0];hl[i][1]+=a2[i][0][1];}
if(hl[i][0]<=0||hl[i][0]>=640||hl[i][1]<=0||hl[i][1]>=480)
{
b:
a1[i][1]=rand()%14+2;
if(a1[i][1]==12)goto b;
a2[i][0][0]=rand()%6+1;
a2[i][0][1]=rand()%6+1;
a2[i][1][0]=(rand()%5+1)/100;
a2[i][1][1]=(rand()%5+1)/100;
if(a1[i][0]==1)
{hl[i][0]=rand()%240;hl[i][1]=rand()%160;}
if(a1[i][0]==2)
{hl[i][0]=rand()%240+200;hl[i][1]=rand()%240;}
if(a1[i][0]==3)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160;}
if(a1[i][0]==4)
{hl[i][0]=rand()%200;hl[i][1]=rand()%160+160;}
if(a1[i][0]==5)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+160;}
if(a1[i][0]==6)
{hl[i][0]=rand()%200;hl[i][1]=rand()%160+320;}
if(a1[i][0]==7)
{hl[i][0]=rand()%240+200;hl[i][1]=rand()%240+200;}
if(a1[i][0]==8)
{hl[i][0]=rand()%200+440;hl[i][1]=rand()%160+320;}
}
}
}
end:
;
}
int yingle()
{       int i,j,yesno;
for(i=1;i<=ii;i++)
for(j=1;j<=jj;j++)
if(sl[i][j][0]==1&&sl[i][j][2]!=2){yesno=0;goto end;}
yesno=1;
end:;
return(yesno);
}
void huacha(int i,int j)
{
setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
setlinestyle(0,0,3);
setcolor(4);
line((j-1)*20+4+5,(i-1)*20+42+5,j*20+2-5,i*20+40-5);
line(j*20+2-5,(i-1)*20+40+5, (j-1)*20+4+5,i*20+40-5) ;
}
void hualei(int i,int j,int ze)
{
if(ze==1)setfillstyle(1,6);else setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
setcolor(4);
circle((j-1)*20+3+10,(i-1)*20+41+10,7)                 ;
setfillstyle(1,4);
pieslice((j-1)*20+3+10,(i-1)*20+41+10,0,360,7);
}
void zero(int h, int s)
{ char str;
int i,j,h1,h2,s1,s2;
h1=h-1;h2=h+1;s1=s-1;s2=s+1;
if(h1<=0)h1=1;
if(h2>=ii+1)h2=ii;
if(s1<=0)s1=1;
if(s2>=jj+1)s2=jj;
for(i=h1;i<=h2;i++)
for(j=s1;j<=s2;j++)
{
if(i==h&&j==s)continue;
if(sl[i][j][2]==1)continue;
if(sl[i][j][1]==0)goto tiao5_1;
setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
settextstyle(2,0,7);
setcolor(sl[i][j][1]);outtextxy((j-1)*20+9,(i-1)*20+4+37,itoa(sl[i][j][1],str,10));
setlinestyle(0,0,1);
setcolor(7);
rectangle((j -1)*20+3+1,(i -1)*20+41+1,j *20+3-1,i *20+41-1);
sl[i][j][2]=1;
tiao5_1:
if(sl[i][j][1]==0&&sl[i][j][2]!=1)
{setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
setlinestyle(0,0,1);
setcolor(7);
rectangle((j -1)*20+3+1,(i -1)*20+41+1,j *20+3-1,i *20+41-1);
sl[i][j][2]=1;
zero(i,j);}
}
}
void huaqi(int qil,int qih)
{
setlinestyle(0,0,1);
setfillstyle(1,4);
bar(qil+6,qih+9,qil+5+7,qih+6+7);
setcolor(4);
line(qil+5+7,qih+6+7,qil+5+7,qih+20);
line(qil+11,qih+20,qil+13,qih+20);
}
void huawhy(int s,int h)
{
setfillstyle(1,7);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
settextstyle(0,0,2);
setcolor(13);
outtextxy(s*20+2-14,h*20+40-14,"?");
}
void leiqu(int ii, int jj)
{
int i;
setlinestyle(0,0,3);
setcolor(1);
rectangle(1,1,jj*20+5,ii*20+40+2);
setlinestyle(0,0,3);
line(1,39,jj*20+3,39);
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(4);
bar(3,41,jj*20+3,ii*20-1+40+2);
setcolor(0);
for(i=41;i<=ii*20+41;i+=20)
line(3,i,jj*20+3,i);
for(i=3;i<=jj*20+3;i+=20)
line(i,40,i,ii*20+40);
}
main()
{
char str;
int lie,kuan,kk1=0,col,kk,degn1,h1,h2,s1,s2,n,yesno,j,a,b,h=5,s=5,secon,iii,sign,jjj,hh=5,ss=5;
long i,leinum1,leinum=0,lei=0,nnn;
int gdriver=DETECT,gmode=4;
initgraph(&gdriver,&gmode,"c:\tc");
cleardevice();
feng();
menu:
closegraph();
initgraph(&gdriver,&gmode,"c:\tc");
h=5;s=5;hh=5;ss=5;leinum=0;kk1=0;lei=0;yesno=0;
if(dispmenu()==1)goto over;
cleardevice();
setviewport((640-jj*20+5)/2,(480-ii*20+40+2)/2,jj*20+5+(640-jj*20+5)/2,ii*20+40+2+(480-ii*20+40+2)/2,0);
leinum1=ii*jj*bfzj/100;
for(i=0;i<=ii+1;i++)
for(j=0;j<=jj+1;j++)
{sl[i][j][0]=0;sl[i][j][2]=0;}
for(i=1;i<=ii*jj*bfzj/100;i++)
{rands:
a=rand()%ii+1;
b=rand()%jj+1;
if(sl[a][b][0]==1)goto rands;else sl[a][b][0]=1;
}
for(i=1;i<=ii;i++)
{
for(j=1;j<=jj;j++)
{
for(iii=i-1;iii<=i+1;iii++)
for(jjj=j-1;jjj<=j+1;jjj++)
if(sl[iii][jjj][0]==1)lei++;
if(sl[i][j][0]==1)lei--;
sl[i][j][1]=lei;lei=0;}
}
leiqu(ii,jj);
setcolor(12);
circle( (jj*20+7)/2,20,16);
line((jj*20+7)/2-3,27,(jj*20+7)/2+3,27);
circle((jj*20+7)/2-7,15,1);
circle((jj*20+7)/2+7,15,1);
settextstyle(3,0,3);
setcolor(4);
outtextxy(20,10,itoa(sign=leinum1-leinum,str,10));
outtextxy(jj*20+5-15,10,"0");
nnn=0;secon=0;
for(;;)
{
gc:
if(kk1==1)nnn++;
if(nnn==41000)
{
settextstyle(3,0,3);
if(secon==9999||(jj<=7&&secon==999))goto tiaook;
if(secon<10)col=15;
if(secon>=10)col=30;
if(secon>=100)col=45;
if(secon>=1000)col=60;
setcolor(0);
outtextxy(jj*20+5-col,10,itoa(secon,str,10));
tiaook:
secon++;
if(jj<=7&&secon>999)goto asdf;
if(secon<10)col=15;
if(secon>=10)col=30;
if(secon>=100)col=45;
if(secon>=1000)col=60;
if(secon>10000)
{asdf:
settextstyle(0,0,5);
setcolor(12);
outtextxy(10,ii*10,"FOOL!");
for(;;)
if(kbhit()!=0)
{str=getch();
if(str==27)
break;}
goto menu;}
nnn=0;setcolor(4);outtextxy(jj*20+5-col,10,itoa(secon,str,10));}
sign='\0';
if( kbhit()!=0){sign=getch();if(sign=='\0')sign=getch();}
if(sign=='0')sign='R';
if(sign==27)goto menu;
if(sign!=13&&sign!='R'&&sign!='K'&&sign!='M'&&sign!=' '&&sign!='H'&&sign!='P'&&sign!=' ')goto gc;
if(sign=='K' && s-1<=0)goto gc;
if(sign=='M'&&s+1>=jj+1)goto gc;
if(sign=='H'&&h-1<=0)goto gc;
if(sign=='P'&&h+1>=ii+1)goto gc;
if(sign==13&&sl[h][s][2]!=1)goto gc;
if(sign==' '&&sl[h][s][2]!=0&&sl[h][s][2]==2)goto gc;
if(sign=='R'&&sl[h][s][2]==1)goto gc;
kk1=1;
if(sign=='R')
{
if(sl[h][s][2]==0)
{
  if(leinum>leinum1)lie=10;else lie=20;
  settextstyle(3,0,3);
  setcolor(0);
    outtextxy(lie,10,itoa(leinum1-leinum,str,10));
  leinum++;
   if(leinum>leinum1)lie=10;else lie=20;
  setcolor(4);
  outtextxy(lie,10,itoa(leinum1-leinum,str,10));
  sl[h][s][2]=2;
  huaqi(s*20-20+3,h*20+20-3);
  if(leinum==leinum1)yesno=yingle();
  if(yesno==1)
  {
  setlinestyle(0,0,1);
setcolor(0);
line((jj*20+7)/2-3,27,(jj*20+7)/2+3,27);
setcolor(12);
line((jj*20+7)/2-7-3,12,(jj*20+7)/2-7+3,15);
line((jj*20+7)/2-7+3,12,(jj*20+7)/2-7-3,15);
line((jj*20+7)/2+7+3,12,(jj*20+7)/2+7-3,15);
line((jj*20+7)/2+7-3,12,(jj*20+7)/2+7+3,15);
ellipse((jj*20+7)/2,20,240,300,6,10);
  getch();
  for(;;)
  if(kbhit()!=0)
  {str=getch();
  if(str==27)break;
  }
  goto menu;
  }
  goto zhuan;
  }
if(sl[h][s][2]==2)
  {
   settextstyle(3,0,3);
  setcolor(0);
    if(leinum>leinum1)lie=10;else lie=20;
    outtextxy(lie,10,itoa(leinum1-leinum,str,10));
  leinum--;
  if(leinum>leinum1)lie=10;else lie=20;
  setcolor(4);
    outtextxy(lie,10,itoa(leinum1-leinum,str,10));
      sl[h][s][2]=3;
  huawhy(s,h);
  goto zhuan;
  }
if(sl[h][s][2]==3)
  {
  sl[h][s][2]=0;
  setfillstyle(1,7);
  bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
  goto zhuan;
  }
}
zhuan:
if(sign==13)
{degn1=0;
h1=h-1;h2=h+1;s1=s-1;s2=s+1;
if(h1<=0)h1=1;
if(h2>=ii+1)h2=ii;
if(s1<=0)s1=1;
if(s2>=jj+1)s2=jj;
for(i=h1;i<=h2;i++)
for(j=s1;j<=s2;j++)
{
if(i==h&&j==s)continue;
if(sl[i][j][0]==1&&sl[i][j][2]!=2)degn1=1;
if(sl[i][j][0]==0&&sl[i][j][2]==2)degn1=1;
}
if(degn1==1)goto gc;
for(i=h1;i<=h2;i++)
for(j=s1;j<=s2;j++)
{ if(sl[i][j][2]==1)continue;
if(sl[i][j][2]==2)continue;
setfillstyle(1,8);
bar((j-1)*20+4,(i-1)*20+42,j*20+2,i*20+40);
settextstyle(2,0,7);
if(sl[i][j][1]!=0){setcolor(sl[i][j][1]);outtextxy((j-1)*20+9,(i-1)*20+4+37,itoa(sl[i][j][1],str,10));}else{sl[i][j][2]=1;zero(i,j);}
setlinestyle(0,0,1);
setcolor(7);
rectangle((j -1)*20+3+1,(i -1)*20+41+1,j *20+3-1,i *20+41-1);
sl[i][j][2]=1;
}
}
if(sign==' ')
{
if(sl[h][s][0]==1)
{
setfillstyle(1,13);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
for(i=1;i<=ii;i++)
for(j=1;j<=jj;j++)
{ if(i==h&&j==s)kk=1;else kk=0;
if(sl[i][j][0]==0&&sl[i][j][2]==2)huacha(i,j);
if(sl[i][j][0]==1&&sl[i][j][2]!=2)hualei(i,j,kk);
}
fflush(stdin);
setlinestyle(0,0,3);
setcolor(0);
line((jj*20+7)/2-3,27,(jj*20+7)/2+3,27);
for(;;)
{
setcolor(12);
setlinestyle(0,0,kuan);
line((jj*20+7)/2-7-3,12,(jj*20+7)/2-7+3,18);
line((jj*20+7)/2-7+3,12,(jj*20+7)/2-7-3,18);
line((jj*20+7)/2+7+3,12,(jj*20+7)/2+7-3,18);
line((jj*20+7)/2+7-3,12,(jj*20+7)/2+7+3,18);
circle( (jj*20+7)/2,20,16);
ellipse((jj*20+7)/2,37,60,120,6,10);
circle((jj*20+7)/2-7,15,1);
circle((jj*20+7)/2+7,15,1);
if(kbhit()!=0)
{str=getch();
if(str==27){fflush(stdin);break;}}
}
goto menu;
}
if(sl[h][s][1]==0)goto tiao4;
setfillstyle(1,8);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
settextstyle(2,0,7);
setcolor(sl[h][s][1]);outtextxy((s-1)*20+9,(h-1)*20+4+37,itoa(sl[h][s][1],str,10));
tiao4:
if(sl[h][s][1]==0)
{setfillstyle(1,8);
bar((s-1)*20+4,(h-1)*20+42,s*20+2,h*20+40);
sl[h][s][2]=1;
zero(h,s);
}
sl[h][s][2]=1;
goto aa;
}
if(sign=='K'){s--;ss=s+1;hh=h;goto aa;}
if(sign=='M'){s++;ss=s-1;hh=h;goto aa;  }
if(sign=='H'){h--;hh=h+1;ss=s;goto aa;   }
if(sign=='P'){h++;hh=h-1;ss=s;goto aa;    }
aa:
sign='\0';
setlinestyle(0,0,1);
setcolor(7);
rectangle((ss-1)*20+3+1,(hh-1)*20+41+1,ss*20+3-1,hh*20+41-1);
setlinestyle(4,0xc132db6d,1);
setcolor(11);
rectangle((s-1)*20+3+1,(h-1)*20+41+1,s*20+3-1,h*20+41-1);
}
over:
cleardevice();
settextstyle(0,0,9);
setcolor(13);
outtextxy(40,190,"Goodbye!");
settextstyle(0,0,1);
setcolor(8);
outtextxy(500,450,"Writer : Tube");
getch();
closegraph();
}


6 楼

我是新来的!

7 楼

不知楼上的注意到没有,这里是QB区,呵呵,路过,随便说说
小弟也想学C,不知楼上的朋友是否愿意教我?

8 楼

扫雷是用QB编的吗?    

9 楼

哈,你想用QB编写一个,也没人拦你啊!

10 楼

很好1

我来回复

您尚未登录,请登录后再回复。点此登录或注册