⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 挖地雷.txt

📁 本程序通过tc2.0和tc3.0编译运行
💻 TXT
📖 第 1 页 / 共 2 页
字号:
       setcolor(4);
       rectangle(x1*size+pix,y1*size+piy,x1*size+size+pix-1,y1*size+size+piy-1);
  }
 }
/*++++++++主函数结束++++++++*/


/*这个函数用于实现鼠标的初始化*/
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);
}
/*下面是一些画图程序*/
void Facedraw(int x,int y,int sizel,int k)
/*形参x,y笑脸的中心坐标,sizel脸的大小(半径),
k为要描述的脸型,1:哭、2:平常、3:笑*/
 {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); /*嘴巴*/
  }
}
/*死亡后的处理程序*/
void Dead(int sizel,int x,int y)
/*x,y要判断的点的坐标,sizel为脸的大小*/
{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,20,sizel,1);
 getch();
}
/*下面的函数用于实现设置鼠标的移动范围*/
void Setmouse(int xmax,int ymax,int x,int y)
/*xmax,ymax为左上角的坐标x,y矩阵的大小*/
{int left,right,top,buttom;/*这四个变量用于确定移动的左上角和右下角*/
 left=xmax;
 right=xmax+size*(x-1);
 top=ymax-size;
 buttom=ymax+size*(y-1);
 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);
}
/*下面这个函数用于实现鼠标的读取*/
int Msread(int *xp,int *yp,int *bup,struct time t1,int k)
/*xp,yp,bup分别为鼠标的位置和按键情况,t1,k是时间现实参数,t1为开始时间,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(105,15,135,30);
   setcolor(4);
   outtextxy(110,20,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);
 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. ");
outtextxy(50,120,"This game is express by XiaJia. ");
outtextxy(50,130,"Anybody do not have copyright,except get the right from XiaJia.");
setcolor(9);
outtextxy(50,140,"Press any key to play again.");
getch();
}
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("out.xia", "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,400,90);
setcolor(11);
outtextxy(100,30,"HighCore");
setcolor(2);
outtextxy(20,50,"Small");
outtextxy(20,60,"Normal");
outtextxy(20,70,"Big");
setcolor(3);
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;}
outtextxy(70,50,cco[0]);
outtextxy(70,60,cco[1]);
outtextxy(70,70,cco[2]);
setcolor(5);
outtextxy(100,50,name[0]);
outtextxy(100,60,name[1]);
outtextxy(100,70,name[2]); 
setcolor(1);
outtextxy(30,85,"Press any key to play again!");
getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -