基於C說話完成的掃雷游戲代碼。本站提示廣大學習愛好者:(基於C說話完成的掃雷游戲代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是基於C說話完成的掃雷游戲代碼正文
本文具體講述了基於C說話完成的掃雷游戲代碼,代碼中備有比擬具體的正文,便於讀者浏覽和懂得。願望對進修游戲開辟的同伙能有一點自創價值。
完全的實例代碼以下:
/* 模仿掃雷游戲 */ #include <graphics.h> #include <math.h> #include <stdio.h> #include <dos.h> #include <stdlib.h> #include <conio.h> #include <alloc.h> union REGS regs; int size=15;/*用於表現每一個方塊的年夜小(正方形的邊長)*/ int pix,piy=50;/*pix,piy是矩陣的偏移量*/ char b[2]="1";/*用於顯示方格四周的雷的個數*/ int pan[30][16];/*用於記載盤面的情形:0:沒有、9:有雷、1~8:四周雷的個數*/ int pan1[30][16];/*pan1[][]記載以後的挖雷情形,0:沒有操作、1:翻開了、2:標志了*/ int tt;/*記載時光參數*/ int Eflags;/*用於標志鼠標按鈕的有用性,0:有用,1:有效,2:這是鼠標的隨意率性鍵等於從新開端*/ int Msinit(); void Draw(int x,int y,int sizex,int sizey); void Facedraw(int x,int y,int sizel,int k); void Dead(int sizel,int x,int y); void Setmouse(int xmax,int ymax,int x,int y); int Msread(int *xp,int *yp,int *bup,struct time t1,int k); void Draw1(int x,int y); int Open(int x,int y); float Random(); void Have(int sum,int x,int y,int xx,int yy); void Help(); void Coread(); void Ddraw2(int x,int y); /*上面是主函數*/ main() { int mode=VGAHI,devices=VGA;/*圖形形式初始化的變量*/ char ams; /*鼠標操作中的標記變量*/ int xms,yms,bms; /*鼠標的狀況變量*/ int i,j,k,k1=0; /*i,j,k是輪回變量*/ int x=9,y=9,flags=0; /*x,y矩陣的年夜小*/ int sum=10; /*sum 盤面的雷的總數量,是個x,y的函數*/ int x1=0,y1=0; /*用於記載光標以後的地位*/ int x11=0,y11=0; /*臨時保留鼠標地位的值*/ int sizel=10; /*臉的年夜小*/ int cflags=1; /*這是菜單操作標記變量,沒有彈出1,彈出0*/ struct time t1={0,0,0,0}; /*時光構造體,頭文件已界說*/ int co[3]; /*臨時記載汗青記載*/ void far *Map; /*用於保留鼠標圖片*/ char name[3][20]; /*名字字符串,用於記載名字*/ FILE * p; /*文件指針用於文件操作*/ Msinit(); /*鼠標初始化*/ /*registerbgidriver(EGAVGA_driver);*/ initgraph(&devices,&mode,"C:\\tc"); /*圖形形式初始化*/ /*為圖片指針分派內存*/ if((Map=farmalloc(imagesize(0,0,20,20)))==NULL)/*圖片的年夜小是20*20*/ { printf("Memory ererr!\n"); printf("Press any key to out!\n"); exit(1); } /*用於磨練文件能否完全*/ while((p = fopen("score.dat", "r")) == NULL) /*假如不克不及翻開就新建一個*/ { if((p = fopen("score.dat", "w")) == NULL)/*假如不克不及新建就提醒毛病並推出*/ { printf("The file cannot open!\n"); printf("Presss any key to exit!\n"); getch(); exit(1); } /*寫入初始內容*/ fprintf(p,"%d %d %d,%s\n%s\n%s\n",999,999,999,"xiajia","xiajia","xiajia"); fclose(p); } /*臨時讀出汗青記載。並用co[3]記載*/ fscanf(p,"%d %d %d,",&co[0],&co[1],&co[2]); for(i=0;i<3;i++) fscanf(p,"%s\n",name[i]); fclose(p); Setmouse(1,1,615,460); /*設置鼠標的運動規模*/ pix=250-x*size/2; /*盤算地雷按鈕矩陣的右邊*/ bss: b[0]='1'; /*游戲開端和重來的切入點*/ flags=0; /*測試中這個變量似乎沒有感化,然則為了邏輯的完全性臨時保存*/ k=0; Eflags=0; tt=0; cleardevice();/*清屏*/ setbkcolor(LIGHTCYAN); for(i=0;i<30;i++) /*盤面初始化*/ for(j=0;j<16;j++) { pan[i][j]=0; pan1[i][j]=0; } for(;;) /*用於生成雷的盤面情形*/ { i=(int)(x*Random()); j=(int)(y*Random()); if(pan[i][j]==0) { pan[i][j]=9; k=k+1; } if(k==sum) break; } for(i=0;i<x;i++)/*用於統計各點的周邊情形*/ for(j=0;j<y;j++) { if(pan[i][j]==0)/*只要沒有雷的才須要處置*/ { if(i-1>=0 && j-1>=0 && pan[i-1][j-1]==9) pan[i][j]++; if(j-1>=0 && pan[i][j-1]==9) pan[i][j]++; if(i+1<x && j-1>=0 && pan[i+1][j-1]==9) pan[i][j]++; if(i-1>=0 && pan[i-1][j]==9) pan[i][j]++; if(i+1<x && pan[i+1][j]==9) pan[i][j]++; if(i-1>=0 && j+1<y && pan[i-1][j+1]==9) pan[i][j]++; if(j+1<y && pan[i][j+1]==9) pan[i][j]++; if(i+1<x && j+1<y && pan[i+1][j+1]==9) pan[i][j]++; } } if(sum==10)/*畫底座*/ { Draw(170,1,162,200); setcolor(1); outtextxy(175,5,"Game( )"); setcolor(4); outtextxy(175,5," G"); }/*小*/ else if(sum==40) { Draw(115,1,272,307); setcolor(1); outtextxy(120,5,"Game(G)"); setcolor(4); outtextxy(120,5," G"); }/*中*/ else if(sum==99) { Draw(40,1,470,307); setcolor(1); outtextxy(45,5,"Game(G)"); setcolor(4); outtextxy(45,5," G"); }/*年夜*/ setcolor(1);/*顯示提醒信息*/ outtextxy(100,350," : Help."); setcolor(4); outtextxy(100,350,"H"); setcolor(1); outtextxy(200,350," / : exit."); setcolor(4); outtextxy(200,350,"Q"); outtextxy(220,350,"ESC"); setcolor(1); outtextxy(330,350," : cores."); setcolor(4); outtextxy(330,350,"R"); Facedraw(250,30,sizel,2);/*顯示掌握按鈕,臉型*/ for(i=0;i<x;i++)/*這一段用於描寫盤面*/ for(j=0;j<y;j++) { Draw(i*size+pix,j*size+piy,size,size); } Have(sum,pix+20,30,x,y);/*各項的初始顯示*/ k=0; setfillstyle(1, 0); bar(460-pix,25,490-pix,40); setcolor(4); outtextxy(465-pix,30,"000"); /*上面這一段用於吸收用戶的掌握,並做出反響*/ for(;;) { ams=Msread(&xms,&yms,&bms,t1,k);/*讀取鼠標狀況*/ /*上面一段用於保留並記載鼠標圖片*/ if(flags!=0) { putimage(x11,y11,Map,COPY_PUT); } x11=xms; y11=yms; flags=1; /*這裡拔出菜單操作*/ if((xms>=pix-10 && xms<=pix+26 && yms>=2 && yms<=14 && bms==1) || ams=='g' || ams=='G')/*點中菜單的斷定*/ { Draw(pix-10,14,100,88); /*畫菜單*/ cflags=0; setcolor(1);/*上面顯示菜單項*/ outtextxy(pix-4,19,"Restar(R)"); setcolor(4); outtextxy(pix-4,19," R"); setcolor(1);/*上面顯示菜單項*/ outtextxy(pix-4,30,"Easy(E)"); setcolor(4); outtextxy(pix-4,30," E"); setcolor(1);/*上面顯示菜單項*/ outtextxy(pix-4,41,"Nomall(N)"); setcolor(4); outtextxy(pix-4,41," N"); setcolor(1);/*上面顯示菜單項*/ outtextxy(pix-4,52,"Hard(H)"); setcolor(4); outtextxy(pix-4,52," H"); setcolor(1);/*上面顯示菜單項*/ outtextxy(pix-4,63,"Corse(C)"); setcolor(4); outtextxy(pix-4,63," C"); setcolor(1);/*上面顯示菜單項*/ outtextxy(pix-4,74,"Help(L)"); setcolor(4); outtextxy(pix-4,74," L"); setcolor(1);/*上面顯示菜單項*/ outtextxy(pix-4,85,"Quit(Q)"); setcolor(4); outtextxy(pix-4,85," Q"); bms=0; }/*完成菜單的描寫*/ /*這裡是為了完整完成鼠標掌握才參加的內容*/ if(Eflags==2 && (bms!=0 || ams!=-1)) { goto bss; } /*上面完成菜單的功效,每項呼應一個菜單項*/ if(cflags==0) { if((xms>=pix-6 && xms<=pix+85 && yms>=17 && yms<=28 && bms==1)|| (ams=='r' || ams=='R'))/*上面順次呼應菜單中各項*/ { cflags=1; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=28 && yms<=39 && bms==1) || ams=='e' || ams=='E') { cflags=1; x=9; y=9; sum=10; pix=250-x*size/2; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=39 && yms<=50 && bms==1) || ams=='n' || ams=='N') { cflags=1; x=16; y=16; sum=40; pix=250-x*size/2; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=50 && yms<=61 && bms==1) || ams=='h' || ams=='H') { cflags=1; x=30; y=16; sum=99; pix=250-x*size/2+25; goto bss; } else if((xms>=pix-6 && xms<=pix+85 && yms>=61 && yms<=72 && bms==1) || ams=='c' || ams=='C') { cflags=1; Coread(); } else if((xms>=pix-6 && xms<=pix+85 && yms>=72 && yms<=83 && bms==1) || ams=='l' || ams=='L') { cflags=1; Help(); } else if((xms>=pix-6 && xms<=pix+85 && yms>=83 && yms<=94 && bms==1) || ams=='q' || ams=='Q' || ams==27) { cflags=1; fclose(p); closegraph(); farfree(Map); exit(1); } else if(bms!=0) { cflags=1; goto bss; } }/*停止菜單功效的完成*/ /*在笑容按鈕處單擊時從新開端*/ if(cflags!=0 && xms >=250-sizel-2 && yms >= 30-sizel-2 && xms<=250+sizel+2 && yms<=30+sizel+2 && bms==1 ) { goto bss; } if(Eflags==0 && cflags!=0 && xms-pix>=0 && yms-piy >=0 && xms<pix+x*size && yms<piy+y*size )/*111斷定*/ { x1=(int)((xms-pix)/size);/*盤算鼠標今朝的按鈕地位*/ y1=(int)((yms-piy)/size); if(ams==-1 && bms==1 && pan1[x1][y1]==0)/*單擊鼠標左鍵*/ { if(k==0)/*k這裡斷定能否是第一次按下.0:不計時,1:開端計時*/ { gettime(&t1); k=1; } if(pan[x1][y1]!=9) { Draw1(x1,y1); Open(x,y); } else { Dead(sizel,x,y); k=0; } } if(ams==-1 && bms==2 && pan1[x1][y1]==0)/*單擊鼠標右鍵*/ { delay(100); setcolor(10); circle(x1*size+pix+7,y1*size+piy+7,4); pan1[x1][y1]=2; Have(sum,pix+20,30,x,y); } else if(ams==-1 && bms==2 && pan1[x1][y1]==2)/*單擊鼠標右鍵*/ { delay(100); Draw(x1*size+pix,y1*size+piy,size,size); pan1[x1][y1]=0; Have(sum,pix+20,30,x,y); }/*相當於鼠標右擊*/ if(ams==-1 && bms==3 && pan1[x1][y1]==1) {/*相當於鼠標雙擊,有用性斷定*/ i=0; if(x1-1>=0 && y1-1>=0 && pan1[x1-1][y1-1]==2) i++; if(y1-1>=0 && pan1[x1][y1-1]==2)i++; if(x1+1<x && y1-1>=0 && pan1[x1+1][y1-1]==2) i++; if(x1-1>=0 && pan1[x1-1][y1]==2) i++; if(x1+1<x && pan1[x1+1][y1]==2) i++; if(x1-1>=0 && y1+1<y && pan1[x1-1][y1+1]==2) i++; if(y1+1<y && pan1[x1][y1+1]==2) i++; if(x1+1<x && y1+1<y && pan1[x1+1][y1+1]==2) i++; if(i==pan[x1][y1]) /*有用*/ { if(x1-1>=0 && y1-1>=0 && pan1[x1-1][y1-1]!=2) { if(pan[x1-1][y1-1]!=9) Draw1(x1-1,y1-1); else { Dead(sizel,x,y); k=0; } } if(y1-1>=0 && pan1[x1][y1-1]!=2) { if(pan[x1][y1-1]!=9) Draw1(x1,y1-1); else { Dead(sizel,x,y); k=0; } } if(x1+1<x && y1-1>=0 && pan1[x1+1][y1-1]!=2) { if(pan[x1+1][y1-1]!=9) Draw1(x1+1,y1-1); else { Dead(sizel,x,y); k=0; } } if(x1-1>=0 && pan1[x1-1][y1]!=2) { if(pan[x1-1][y1]!=9) Draw1(x1-1,y1); else { Dead(sizel,x,y); k=0; } } if(x1+1<x && pan1[x1+1][y1]!=2) { if(pan[x1+1][y1]!=9) Draw1(x1+1,y1); else { Dead(sizel,x,y); k=0; } } if(x1-1>=0 && y1+1<y && pan1[x1-1][y1+1]!=2) { if(pan[x1-1][y1+1]!=9) Draw1(x1-1,y1+1); else { Dead(sizel,x,y); k=0; } } if(y1+1<y && pan1[x1][y1+1]!=2) { if(pan[x1][y1+1]!=9) Draw1(x1,y1+1); else { Dead(sizel,x,y); k=0; } } if(x1+1<x && y1+1<y &&pan1[x1+1][y1+1]!=2) { if(pan[x1+1][y1+1]!=9) Draw1(x1+1,y1+1); else { Dead(sizel,x,y); k=0; } } Open(x,y); } } /*成功前提*/ k1=0; for(i=0;i<x;i++) for(j=0;j<y;j++) if(pan1[i][j]!=1) k1++; if(k1==sum) { for(i=0;i<x;i++) for(j=0;j<y;j++) if(pan1[i][j]==0) { setcolor(10);circle(i*size+pix+7,j*size+piy+7,4); } Facedraw(250,30,sizel,3); if(x==9 && tt<co[0]) {j=0;co[0]=tt;i=0;} if(x==16 && tt<co[1]) {j=1;co[1]=tt;i=0;} if(x==30 && tt<co[2]) {j=2;co[2]=tt;i=0;} if(i==0) { Draw(10,10,300,55); setcolor(4); outtextxy(20,15,"You break the corse!"); outtextxy(20,25,"Please input your name(0 - 19):"); setfillstyle(1, 14); bar(20,35,200,50); for(i=0;i<19;i++) { name[j][i]=getch(); if(name[j][i]==8) i=i-2; if(name[j][i]==13) {name[j][i]='\0';break;} name[j][i+1]='\0'; setfillstyle(1, 14); bar(20,35,200,50); setcolor(1); outtextxy(20,40,name[j]); } if((p = fopen("score.dat", "w")) == NULL) { printf("The file cannot open!\n"); exit(1); } fprintf(p,"%d %d %d,",co[0],co[1],co[2]); for(i=0;i<3;i++) fprintf(p,"%s\n",name[i]); fclose(p); Coread(); } getch(); goto bss; } }/*停止111的斷定*/ /*上面是一些快捷功效鍵的界說*/ if(ams=='q'||ams=='Q'|| ams==27 ) {fclose(p);closegraph();farfree(Map);exit(1);} /*加入主法式的獨一出口*/ if(ams=='c'||ams=='C') goto bss; /*重來*/ if(ams=='h'||ams=='H') {Help();k=0;} /*贊助文檔*/ if(ams=='r'||ams=='R') {Coread();k=0;} /*觀察成就*/ getimage(xms,yms,xms+20,yms+20,Map); Ddraw2(xms,yms); delay(10); }/*停止鼠標輪回讀取的逝世輪回*/ } /*++++++++主函數停止++++++++*/ /*這個函數用於完成鼠標的初始化*/ int Msinit() { int recored; regs.x.ax=0; int86 (0x33, & regs, & regs); recored=regs.x.ax; if(recored==0) { printf("Mouse not found or Mouse driver not installed.\n"); return 0; } else return recored; } /*上面這個子法式是完成描寫一個按鈕*/ void Draw(int x,int y,int sizex,int sizey)/* x, y為左上角坐標sizex,sizey為長和寬*/ { int sizx=sizex-1; int sizy=sizey-1; setcolor(15);/*這裡最好用白色*/ line(x,y,x+sizx-1,y); line(x,y+1,x+sizx-2,y+1); line(x,y,x,y+sizy-1); line(x+1,y,x+1,y+sizy-2); setcolor(8);/*這裡最好用深灰色*/ line(x+1,y+sizy,x+sizx,y+sizy); line(x+2,y+sizy-1,x+sizx,y+sizy-1); line(x+sizx-1,y+1,x+sizx-1,y+sizy); line(x+sizx,y+2,x+sizx,y+sizy); setcolor(7);/*這裡最好用灰色*/ putpixel(x,y+sizy,3); putpixel(x+1,y+sizy-1,3); putpixel(x+sizx,y,3); putpixel(x+sizx-1,y+1,3); setfillstyle(1, 7);/*這裡最好用灰色,設置填充形式*/ bar(x+2,y+2,x+sizx-2,y+sizy-2); } /*上面是一些繪圖法式*/ /*形參x,y笑容的中間坐標,sizel臉的年夜小(半徑), k為要描寫的臉型,1:哭、2:平凡、3:笑*/ void Facedraw(int x,int y,int sizel,int k) {Draw(x-sizel-3,y-sizel-3,2*(sizel+4),2*(sizel+4));/*畫一個按鈕*/ setcolor(14); setfillstyle(1, 14); pieslice(x, y, 0, 360, sizel);/*畫一個黃色的圓面*/ setfillstyle(1, 0); setcolor(0); if(k==1)/*掉敗*/ { line(x-sizel*7/20,y-sizel*7/20,x-sizel*3/20,y-sizel*3/20);/*畫兩個差表現眼睛*/ line(x-sizel*7/20,y-sizel*3/20,x-sizel*3/20,y-sizel*7/20); line(x+sizel*3/20,y-sizel*7/20,x+sizel*7/20,y-sizel*3/20); line(x+sizel*3/20,y-sizel*3/20,x+sizel*7/20,y-sizel*7/20); arc(x,y+sizel,20,160, sizel/2); } if(k==2)/*平凡*/ { bar(x-sizel*7/20,y-sizel*7/20,x-sizel*3/20,y-sizel*3/20); bar(x+sizel*3/20,y-sizel*7/20,x+sizel*7/20,y-sizel*3/20); arc(x,y,200,340, sizel*3/4); } if(k==3)/*勝利*/ { bar(x-sizel/2,y-sizel/2,x-sizel*3/20,y-sizel*3/20); bar(x+sizel*3/20,y-sizel/2,x+sizel/2,y-sizel*3/20); line(x-sizel*3/20,y-sizel/2,x+sizel*3/20,y-sizel/2); line(x-sizel/2,y-sizel*5/20,x-sizel,y); line(x+sizel/2,y-sizel*5/20,x+sizel,y); arc(x,y,200,340, sizel*3/4); /*嘴巴*/ } } /*逝世亡後的處置法式*/ /*x,y要斷定的點的坐標,sizel為臉的年夜小*/ void Dead(int sizel,int x,int y) { int i,j;/*輪回變量*/ setcolor(4); for(i=0;i<x;i++) for(j=0;j<y;j++) if(pan[i][j]==9) { circle(i*size+pix+7,j*size+piy+7,4); }/*用白色的圓圈標志有雷的方塊*/ Facedraw(250,30,sizel,1); Eflags=1; } /*上面的函數用於完成設置鼠標的挪動規模*/ /*xmax,ymax為左上角的坐標x,y矩陣的年夜小*/ void Setmouse(int xmax,int ymax,int x,int y) { int left,right,top,buttom;/*這四個變量用於肯定挪動的左上角和右下角*/ left=xmax; right=x; top=ymax; buttom=y; regs.x.ax=7; regs.x.cx=left; regs.x.dx=right; int86(0x33,& regs,& regs); regs.x.ax=8; regs.x.cx=top; regs.x.dx=buttom; int86(0x33,& regs,& regs); } /*上面這個函數用於完成鼠標的讀取*/ /*xp,yp,bup分離為鼠標的地位和按鍵情形,t1,k是時光實際參數,t1為開端時光,k為開端標志*/ int Msread(int *xp,int *yp,int *bup,struct time t1,int k) { int x0=*xp,y0=*yp,bu0=*bup; int xnew,ynew,ch; int tt1=0;/*用於記載時光差*/ struct time t2; char ttt[4]="000"; do { if(kbhit()) return getch(); regs.x.ax=3; int86(0x33,& regs,& regs); xnew=regs.x.cx; ynew=regs.x.dx; *bup=regs.x.bx; /*上面用於顯示時光*/ if(k==1)/*假如曾經開端就盤算時光差*/ { gettime(&t2); tt1=(t2.ti_hour- t1.ti_hour)*3600 + (t2.ti_min- t1.ti_min)*60 + t2.ti_sec - t1.ti_sec;/*有待改良*/ if(tt1<=999 && tt!=tt1)/*其時間差有轉變時,才顯示*/ { tt=tt1; ttt[0]=(tt-tt%100)/100+48; ttt[1]=(tt%100-tt%10)/10 +48; ttt[2]=tt%10+48; setfillstyle(1, 0); bar(460-pix,25,490-pix,40); setcolor(4); outtextxy(465-pix,30,ttt); } } } while(xnew==x0&&ynew==y0&&*bup==bu0); *xp=xnew; *yp=ynew; return -1;/*鍵盤無輸出時前往-1,其次前往鍵盤值*/ } void Draw1(int x,int y)/*這個函數用於在x,y的地位描寫開後的情形*/ { setfillstyle(1, 7); bar(x*size+pix,y*size+piy,x*size+size+pix-1,y*size+size+piy-1); /*在四個角上畫上點標志*/ /*putpixel(x*size+pix,y*size+piy,8); putpixel(x*size+size+pix-1,y*size+size+piy-1,8); putpixel(x*size+pix,y*size+size+piy-1,8); putpixel(x*size+size+pix-1,y*size+piy,8);*/ setcolor(8); setlinestyle(1, 0, 1); rectangle(x*size+pix,y*size+piy,x*size+size+pix-1,y*size+size+piy-1); setlinestyle(0, 0, 1); if(pan[x][y]!=0)/*沒有雷的話不做顯示*/ { b[0]=pan[x][y]+48; if(pan[x][y]!=7)/*避免字的色彩和配景色彩雷同*/ setcolor(pan[x][y]); else setcolor(9); outtextxy (x*size+pix+3,y*size+piy+3,b); } pan1[x][y]=1;/*在pan1[][]中標志這一點的挖雷情形*/ } /*自開函數*/ int Open(int x,int y)/*函數中引入pan2[][]的目標是為了增長自開的效力,然則照樣有缺乏的地方*/ { int i,j,k; int pan2[30][16]={0};/*pan2[][],暫時記載盤面的自開情形,0沒有自開過,1:曾經自開過(30 這裡有風險的技巧性成績!!!)*/ for(;;) { k=0;/*是一個標志變量*/ for(i=0;i<x;i++) for(j=0;j<y;j++) { if (pan[i][j]==0 && pan1[i][j]==1 && pan2[i][j]==0)/*假如知足上面前提,沒有雷,曾經翻開,沒有自開過就持續*/ { pan2[i][j]=1;/*標志自開過*/ k=k+1; /*開四周的點*/ if(i-1>=0 && j-1>=0 && pan1[i-1][j-1]==0) Draw1(i-1,j-1); /*左上方*/ if(j-1>=0 && pan1[i][j-1]==0) Draw1(i,j-1); /*上方*/ if(i+1<x && j-1>=0 && pan1[i+1][j-1]==0) Draw1(i+1,j-1); /*右上方*/ if(i-1>=0 && pan1[i-1][j]==0) Draw1(i-1,j); /*左方*/ if(i+1<x && pan1[i+1][j]==0) Draw1(i+1,j); /*右方*/ if(i-1>=0 && j+1<y && pan1[i-1][j+1]==0) Draw1(i-1,j+1); /*左下方*/ if(j+1<y && pan1[i][j+1]==0) Draw1(i,j+1); /*下方*/ if(i+1<x && j+1<y && pan1[i+1][j+1]==0) Draw1(i+1,j+1); /*右下方*/ } } if(k==0) return 0;/*沒有新的自開點時加入*/ } } float Random()/*隨即數生成函數,參加了時光變量目標在於增強它的隨機性*/ {float aa; int i,j; struct time t; gettime(&t); i=t.ti_min+t.ti_hour+t.ti_sec+t.ti_hund; for(j=0;j<i;j++) rand(); aa=rand()/32767.0; return aa;/*前往發生的隨機數(0-1)*/ } /*上面是一個顯示殘剩雷數量的函數*/ void Have(int sum,int x,int y,int xx,int yy)/*游戲中雷的總數量不克不及過剩99顆,sum 為雷的總數量,x,y為顯示的所在*/ { int i,j,k=0; char a[3]="1"; for(i=0;i<xx;i++) for(j=0;j<yy;j++) {if (pan1[i][j]==2) k++;}/*統計一共標志了若干*/ k=sum-k;/*剩下了若干*/ if(k<0) k=0; a[0]=(k-(k%10))/10+48;/*字符轉換*/ a[1]=k%10+48; setfillstyle(1, 0); bar(x-5,y-5,x+20,y+10);/*在原點塗黑*/ setcolor(4); outtextxy(x,y,a);/*顯示數量*/ } /*上面是贊助函數*/ void Help() { Draw(40,1,560,160); setcolor(1); outtextxy(300,10,"Help"); setcolor(4); outtextxy(50,30,"Welcome to play this game. The mouse is supplied."); outtextxy(50,40,"Please press left button of the mouse where there is no boom."); outtextxy(50,50,"If you think there is a boom please press right button."); outtextxy(50,60,"You can choose the size of the game with press the right buttons."); outtextxy(50,70,"'Big' means 99 booms,'Normal' means 40 booms,'Small' means 10 booms."); outtextxy(50,80,"You can press the laugh-face-button or press C to play again."); outtextxy(50,90,"When you fail or success you can press any key to play again. "); outtextxy(50,100,"Whenever you want to quit this game please press Q. "); outtextxy(50,110,"If you find out all booms then you are winning. "); setcolor(9); outtextxy(50,140,"Press any key to play again."); Eflags=2; } void Coread()/*這個函數用於讀取記載並顯示*/ { int co[3],i; char name[3][20]; char cco[3][4]; FILE * p; for(i=0;i<3;i++) cco[i][3]='\0'; if((p = fopen("score.dat", "rb")) == NULL) { printf("The file cannot open!\n"); exit(1); } fscanf(p,"%d %d %d,",&co[0],&co[1],&co[2]); for(i=0;i<3;i++) fscanf(p,"%s\n",name[i]); fclose(p); Draw(10,20,320,90); setcolor(1); outtextxy(140,30,"HighCore"); setcolor(2); outtextxy(20,50,"Easy"); outtextxy(20,60,"Normal"); outtextxy(20,70,"Hard"); for(i=0;i<3;i++) { cco[i][0]=(co[i]-co[i]%100)/100+48; cco[i][1]=(co[i]%100-co[i]%10)/10 +48; cco[i][2]=co[i]%10+48; } setcolor(3); outtextxy(100,50,cco[0]); outtextxy(100,60,cco[1]); outtextxy(100,70,cco[2]); setcolor(5); outtextxy(150,50,name[0]); outtextxy(150,60,name[1]); outtextxy(150,70,name[2]); setcolor(9); outtextxy(30,85,"Press any key to play again."); Eflags=2; } /*這個函數用來畫鼠標光標,x,y,為左上角坐標,年夜小為20*20*/ void Ddraw2(int x,int y) { /*這個處所臨時應用簡略單純光標,法式成熟今後應用龐雜的*/ setcolor(1); line(x,y,x,y+18); line(x+1,y,x+1,y+18); line(x,y,x+12,y+12); line(x+1,y,x+13,y+12); line(x,y+18,x+4,y+14); line(x,y+17,x+4,y+13); line(x+4,y+14,x+6,y+20); line(x+4,y+13,x+6,y+19); line(x+6,y+20,x+10,y+18); line(x+6,y+19,x+10,y+17); line(x+10,y+18,x+8,y+12); line(x+10,y+17,x+8,y+11); line(x+8,y+12,x+12,y+12); line(x+8,y+11,x+12,y+11); }
至此法式完成,直接編譯運轉便可!