_c language of mine-clearing game code based on C language

Source: Internet
Author: User

In this paper, the Code of mine-clearing game based on C language is described in detail, and the code is provided with more detailed annotation, which is convenient for readers to read and understand. Hope to learn game development friends can have a little value for reference.

The complete instance code is as follows:

/* Simulated mine-clearing game/#include <graphics.h> #include <math.h> #include <stdio.h> #include <dos.h> #includ
E <stdlib.h> #include <conio.h> #include <alloc.h> Union regs regs; The int size=15;/* is used to denote the size of each square (square edges)/int Pix,piy=50;/*pix,piy is the offset of the matrix/char b[2]= "1";/* to display the number of mines around the grid/int pan[30][16] /* Used to record the disk surface: 0: No, 9: There are thunder, 1~8: The number of mines around the mine/int pan1[30][16];/*pan1[][] record the current mine-digging situation, 0: No operation, 1: Opened, 2: marked the * * int tt;/* record time parameter */INT
eflags;/* is used to mark the validity of the mouse button, 0: Valid, 1: invalid, 2: This is the mouse of any key equal to start again/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);         /* Below is the main function */main () {int mode=vgahi,devices=vga;/* graphics mode initialization variable/char AMS; /* Mouse operation of the symbol variable * *NT Xms,yms,bms;      /* Mouse state variable */int i,j,k,k1=0;    /*i,j,k is a cyclic variable */int x=9,y=9,flags=0;        The size of the/*x,y matrix */int sum=10;       The total number of thunder on the/*sum disk is a x,y function/int x1=0,y1=0;      /* is used to record the current position of the cursor */int x11=0,y11=0;       /* Temporarily save the value of the mouse position */int sizel=10;   * * Face size/int cflags=1; /* This is the menu operation flag variable, no pop-up 1, pop-up 0*/struct time t1={0,0,0,0};   /* Time structure, header file defined */int co[3];   * * Temporary record of the historical record/void far *map;   /* Used to save the mouse picture * * Char name[3][20];   /* Name string, used to record the name/FILE * p;               /* file pointer for file operation/Msinit ();   /* Mouse initialization//*registerbgidriver (egavga_driver); * * Initgraph (&devices,&mode, "C:\\TC"); /* Graphics mode initialization///////////////////////////if ((Map=farmalloc (ImageSize (0,0,20,20)) ==null)/* Picture size is 20*20*/{printf ("Memory ererr!\n"
 );
 printf ("Press any key to out!\n");
 Exit (1); /* is used to verify that the file is complete */while (P = fopen ("Score.dat", "r") = = NULL)/* If not open, create a new */{if (P = fopen ("Score.dat", "w") = =
  NULL)/* If you cannot create a new prompt error and launch/{printf ("The file Cannot open!\n");
  printf ("Presss any key to exit!\n");
    Getch ();Exit (1);
 /* Write initial content/* fprintf (P, "%d%d%d,%s\n%s\n%s\n", 999,999,999, "Xiajia", "Xiajia", "Xiajia"); 
 Fclose (P); /* Read the history record temporarily.
 and co[3] Record/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); /* Set the mouse activity range * * PIX=250-X*SIZE/2;    /* Calculate the Mine button matrix left/bss:b[0]= ' 1 '; * * The beginning of the game and the starting point * * flags=0;
 /* Test this variable does not seem to work, but for the integrity of the logic of the temporary reserve * * * K=0;
 eflags=0;
 tt=0;
    Cleardevice ()/* Clear Screen * * SetBkColor (Lightcyan);
     for (i=0;i<30;i++)/* Disk initialization/for (j=0;j<16;j++) {pan[i][j]=0;
 pan1[i][j]=0;
   for (;;)/* The disk condition used to generate the Thunder/{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++)/* is used to statistic the perimeter of each point * * for (j=0;j<y;j++) {if (pan[i][j]==0)/* * Only need to be processed without thunder/{if (i-1>=0 &AMP;&A mp
  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 Base * * Draw (170,1,162,200);
 SetColor (1);
 Outtextxy (175,5, "Game ()");
 SetColor (4);
 Outtextxy (175,5, "G");
  }/* Small */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");
 }/* Large/SetColor (1);////Outtextxy (100,350, ": Help.");
 SetColor (4);
 Outtextxy (100,350, "H");
 SetColor (1);
 Outtextxy (200,350, "/: Exit.");
 SetColor (4);
 Outtextxy (200,350, "Q"); OUsTtextxy (220,350, "ESC");
 SetColor (1);
 Outtextxy (330,350, ": Cores.");
 SetColor (4);

 Outtextxy (330,350, "R"); Facedraw (250,30,sizel,2)/* Display control button, face//for (i=0;i<x;i++)/* This section is used to describe the disk surface/for (j=0;j<y;j++) {Draw (i*size+pix,j*
 Size+piy,size,size);
 Have (sum,pix+20,30,x,y);/* Initial display of the items * * k=0;
 Setfillstyle (1, 0);
 Bar (460-pix,25,490-pix,40);
 SetColor (4);

Outtextxy (465-pix,30, "000");
 /* The following section is used to receive the user's control, and to react/for (;;) {Ams=msread (&xms,&yms,&bms,t1,k); * Read mouse status////////////////////(flags!=0) {putimage (x11,y11,map,c
 Opy_put);
 } X11=XMS;
 y11=yms;

 Flags=1; * * Insert menu operation/if (xms>=pix-10 && xms<=pix+26 && yms>=2 && yms<=14 && bms==1) || ams== ' G ' | |
  ams== ' G ')/* Point of the menu in the judgment/{Draw (pix-10,14,100,88);/* Picture Menu * * cflags=0;
  SetColor (1);/* Show menu item/OUTTEXTXY (pix-4,19, Restar (R)) below;
  SetColor (4);
  Outtextxy (pix-4,19, "R");
  SetColor (1);//* Below display menu item * * OUTTEXTXY (pix-4,30, "Easy (E)");
  SetColor (4); Outtextxy (pix-4,30, "E");
  SetColor (1);/* Show menu item * * OUTTEXTXY (pix-4,41, "Nomall (N)") below;
  SetColor (4);
  Outtextxy (pix-4,41, "N");
  SetColor (1);/* Show menu item/OUTTEXTXY (pix-4,52, "Hard (H)") below;
  SetColor (4);
  Outtextxy (pix-4,52, "H");
  SetColor (1);//* Below shows menu item */OUTTEXTXY (pix-4,63, "Corse (C)");
  SetColor (4);
  Outtextxy (pix-4,63, "C");
  SetColor (1);/* Show menu item/OUTTEXTXY (pix-4,74, Help (L)) below;
  SetColor (4);
  Outtextxy (pix-4,74, "L");
  SetColor (1);/* Show menu item/OUTTEXTXY (pix-4,85, "Quit (Q)") below;
  SetColor (4);
  Outtextxy (pix-4,85, "Q");
 bms=0;
  }/* Complete Menu Description////////* Here is the content to be added to fully implement mouse control */if (eflags==2 && (bms!=0 | ams!=-1)) {goto BSS; /* Below implement menu functionality, each response to a single menu item */if (cflags==0) {if (xms>=pix-6 && xms<=pix+85 && yms>=17 &AMP;&A mp yms<=28 && bms==1) | | (ams== ' r ' | | ams== ' r '))
  /* Below in response to the menu of the various * * {Cflags=1;
  Goto BSS; else if ((xms>=pix-6 && xms<=pix+85 && yms>=28 && yms<=39 && bms==1) | ms== ' 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 &AMP;&Amp 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; Implementation of}/* End Menu Function *///////////if (cflags!=0 && xms >=250-sizel-2 && yms >= 30-sizel-2 && Amp
 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 &A

  mp;& yms<piy+y*size)/*111 judge/{x1= (int) ((Xms-pix)/size);/* Compute the current button position of the mouse/y1= (int) ((YMS-PIY)/size); if (ams==-1 && bms==1 && pan1[x1][y1]==0) * * Click the left mouse button/{if (k==0)/*k here to determine whether it is the first time pressed. 0: Not counted, 1: Start time/{get
   Time (&AMP;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 &&amP
  PAN1[X1][Y1]==0) * * Click the right mouse button/{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) * * Click the right mouse button/{delay (100);
   Draw (x1*size+pix,y1*size+piy,size,size);
   pan1[x1][y1]=0;
  Have (Sum,pix+20,30,x,y);
  }/* equivalent mouse Right click/if (ams==-1 && bms==3 && pan1[x1][y1]==1) {/* equivalent to a mouse double-click, the validity of the judgement/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])/* Valid/{if (x1-1>=0 &AMP;&Amp
   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 &Amp;& 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);
 }/* Victory condition * * 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); 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, "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]= ' "; break;}
   Name[j][i+1]= ' ";
   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; }/* End 111 's judgment/////* Below is a definition of some shortcut function keys/if (ams== ' q ' | | ams== ' Q ' | |  ams==27) {fclose (P); closegraph (); Farfree (MAP); exit (1);} /* Exit the main program only exit/if (ams== ' C ' | |  ams== ' C ') goto BSS; * * Re/if (ams== ' h ' | | ams== ' H ') {help (); k=0}////if (ams== ' r ') *
 ams== ' R ') {coread (); k=0}/* See Results/getimage (XMS,YMS,XMS+20,YMS+20,MAP);
 DDRAW2 (xms,yms);
   Delay (10);
 }/* end Mouse Loop read dead loop/}/*++++++++ main function End ++++++++*//* This function is used to implement the initialization of the mouse/int msinit () {int recored;
 regs.x.ax=0;
 Int86 (0x33, & Regs, & Regs);
 RECORED=REGS.X.AX; Ifrecored==0) {printf ("Mouse not found or Mouse driver not installed.\n");
 return 0;
else return recored;
 }/* The following subroutine is completed to depict a button/void Draw (int x,int y,int sizex,int sizey)/* x, Y is the upper left corner coordinate Sizex,sizey for long and wide */{int sizx=sizex-1;
 int sizy=sizey-1;
 SetColor (15);/* It is best to use white */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);/* It is best to use dark grey/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);/* Here is the best use of gray/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);/* It is best to use gray, set the fill mode/bar (x+2,y+2,x+sizx-2,y+sizy-2); /* Below are some paint programs////* x,y Smiley Center coordinates, Sizel face size (RADIUS), K to describe the face, 1: Cry, 2: Normal, 3: Laugh/void Facedraw (int x,int y,int sizel,int k) {Draw (x
 -sizel-3,y-sizel-3,2* (sizel+4), 2* (sizel+4); * Draw a button/* SetColor (14);
 Setfillstyle (1, 14);
Pieslice (x, y, 0, 360, Sizel); * Draw a yellow round face * * Setfillstyle (1, 0);
 SetColor (0); if (k==1)/* Failed/{line (X-SIZEL*7/20,Y-SIZEL*7/20,X-SIZEL*3/20,Y-SIZEL*3/20);/* Draw two difference means eye/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)/* Normal */{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) * * Success/{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);
 * * Mouth//}///* Death handler//*x,y to judge the point of the coordinates, Sizel for the size of the face/void Dead (int sizel,int x,int y) {int i,j;/* cycle variable * * * 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);
 }/* with a red circle marked with a thunder of the square * * Facedraw (250,30,sizel,1);
Eflags=1; }/* The following function is used to implement setting the mouse's moving range//*xmax,ymax to the upper-left corner of the coordinate x,y matrix size/void Setmouse (int xmax,int ymax,int x,int y) {int left,right,top,
 buttom;/* These four variables are used to determine the moving upper-left and lower-right corners/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); /* The following function is used to implement the mouse read//*xp,yp,bup respectively the position of the mouse and the key situation, T1,k is the time realistic parameters, T1 for the start time, K for the start tag/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;/* for recording time difference/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;
    /* The following is used to display the time/if (k==1)/* If already started to calculate the variance/{gettime (&AMP;T2); tt1= (T2.ti_hour-t1.ti_hour) *3600 + (t2.ti_min-t1.ti_min) *60 + t2.ti_sec-t1.ti_sec;/* to be improved */if (tt1<=999 && tt!=tt1)/* When the time difference is changed, only show * * 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&AMP;&AMP;YNEW==Y0&AMP;&AMP;*BUP==BU0);
 *xp=xnew;
 *yp=ynew;
 return-1;/* Keyboard No input return-1, followed by the return of the keyboard value/} void Draw1 (int x,int y)/* This function is used to describe the situation after the x,y position * * * Setfillstyle (1, 7);
 
 Bar (x*size+pix,y*size+piy,x*size+size+pix-1,y*size+size+piy-1);
 * * Draw a point mark on Four Corners//*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)/* No thunder words do not show/{b[0]=pan[x][y]+48;
 if (pan[x][y]!=7)/* Prevent the same color and background color of the word * * SetColor (pan[x][y]);
 else SetColor (9); OutteXtxy (X*SIZE+PIX+3,Y*SIZE+PIY+3,B); pan1[x][y]=1;/* to mark this in pan1[][]./////////////////////* The purpose of introducing pan2[][in the function/int Open (int x,int y)/* function is to increase the efficiency of the self, but there is still a shortage of * * int
 I,j,k; int pan2[30][16]={0};/*pan2[][], temporary recording of the opening of the disk, 0 has not been opened, 1: has since opened (30 there are dangerous technical problems!!!)
 * for (;;) {k=0;/* is a token variable */for (i=0;i<x;i++) for (j=0;j<y;j++) {if (pan[i][j]==0 && pan1[i][j]==1 && p
  an2[i][j]==0)/* If the following conditions are met, there is no thunder, has been opened, has not been opened on the continued * * * pan2[i][j]=1;/* marked since the opening/k=k+1; /* Open the surrounding point * * (i-1>=0 && j-1>=0 && pan1[i-1][j-1]==0) Draw1 (i-1,j-1);    /* Upper Left/if (j-1>=0 && pan1[i][j-1]==0) Draw1 (i,j-1); /* Above/if (i+1<x && j-1>=0 && pan1[i+1][j-1]==0) Draw1 (i+1,j-1);     /* Upper Right */if (i-1>=0 && pan1[i-1][j]==0) Draw1 (I-1,J);       /* Left/if (i+1<x && pan1[i+1][j]==0) Draw1 (I+1,J); /* Right/if (i-1>=0 && j+1<y && pan1[i-1][j+1]==0) Draw1 (i-1,j+1); /* lower Left/if (j+1<y && pan1[i][j+1]==0) Draw1 (i,j+1);  /* Below */if (i+1<x && j+1<y && pan1[i+1][j+1]==0) Draw1 (i+1,j+1);
 /* The lower Right/}} if (k==0) return 0;/* no new from the open point of exit/}/float Random ()/* The number generated function, added the time variable to strengthen its randomness/{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;/* returns the resulting random number (0-1)///* Below is a function that shows the number of remaining mines./void Have (int sum,int x,int y,int xx,int yy)/* The total number of thunder in the game can not be more than 99, sum is the total number of thunder
 Mesh, X,y for the display of the location * * {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++;}
 * Statistics Total number of tags/* * k=sum-k;/* How many * * * * (k<0) k=0 left;
 A[0]= (k (k%10))/10+48;/* character conversion */a[1]=k%10+48;
 Setfillstyle (1, 0);
 Bar (x-5,y-5,x+20,y+10);/* Black/SetColor (4) at the origin;
 Outtextxy (X,Y,A)////* Display number */}//* Below is the help function * * * () {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 are 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 booms, ' Normal ' means booms, ' Small ' means 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 your 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 for you are winning."
 ");
 SetColor (9);
 Outtextxy (50,140, "Press any key to play again.");
eflags=2;
 void Coread ()/* This function is used to read the record and display/{int co[3],i;
 Char name[3][20];
 Char cco[3][4];
 FILE * p;

 for (i=0;i<3;i++) cco[i][3]= ' ";
    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;
 }/* This function is used to draw the mouse cursor, x,y, the upper left corner coordinates, the size is 20*20*/void Ddraw2 (int x,int y) {* * This place temporarily uses a simple cursor, the program after the mature use of complex * * 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); }

This program completes, directly compile and run!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.