这个模块是为了来在TC2.0下的一个作品而设计的模块.
但由于这个作品花了我几个月的时间做,
本来想等这个作品一共把源代码发布出来给大家.
但由于一直没有这个精力,已经有好4个月没去碰它的.
因此,还是把这个独立性较大的模块发给大家,
以便大家在学习及业余爱好有所帮助.

 在此提供C语言小游戏源码,包括扫雷游戏,贪吃蛇游戏,时钟等。

/*********************************
作者:HungryAnt
姓名:孙麟
E-mail:ljsunlin@126.com
QQ:517377100
blog:
*********************************/

#ifndef ZXF_MOUS_C_INCLUDE
#define ZXF_MOUS_C_INCLUDE

运行时只要把红色部分改为自己电脑上TC目录的BGI分目录即可。

 

#include <dos.h>
#include <time.h>

 

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

int MouseHolded   =0;        /*是否支持鼠标功能:0–不支持,1–支持*/
int MouseButtonNum=0;        /*当支持鼠标功能时,存放鼠标的按钮数*/
int MouseX        =0;        /*存放鼠标的水平方向的值*/
int MouseY        =0;        /*存放鼠标的垂直方向的值*/
char MouseType    =1;        /*设置鼠标类型:1–为箭头型,2–编辑型*/
#define MouseStatusMouseOn  1    /*在MouseStatus()中实时显示鼠标 */
#define MouseStatusMouseOff
2    /*在MouseStatus()中不实时显示鼠标*/

//扫雷游戏 #include <graphics.h> #include <stdlib.h>
#include <dos.h> #define LEFTPRESS 0xff01 #define LEFTCLICK
0xff10 #define LEFTDRAG 0xff19 #define MOUSEMOVE 0xff08 struct { int
num; int roundnum; int flag; }Mine[10][10]; int gameAGAIN=0; int
gamePLAY=0; int mineNUM; char randmineNUM[3]; int Keystate; int
MouseExist; int MouseButton; int MouseX; int MouseY; void Init(void);
void MouseOn(void); void MouseOff(void); void MouseSetXY(int,int); int
LeftPress(void); int RightPress(void); void MouseGetXY(void); void
Control(void); void GameBegain(void); void DrawSmile(void); void
DrawRedflag(int,int); void DrawEmpty(int,int,int,int); void
GameOver(void); void GameWin(void); int MineStatistics(int,int); int
ShowWhite(int,int); void GamePlay(void); void Close(void); void
main(void) { Init(); Control(); Close(); } void Init(void) { int
gd=DETECT,gm; initgraph(&gd,&gm,”D://tc20//BGI”); } void Close(void) {
closegraph(); } void MouseOn(void) { _AX=0x01; geninterrupt(0x33); }
void MouseOff(void) { _AX=0x02; geninterrupt(0x33); } void
MouseSetXY(int x,int y) { _CX=x; _DX=y; _AX=0x04; geninterrupt(0x33);
} int LeftPress(void) { _AX=0x03; geninterrupt(0x33); return(_BX&1); }
int RightPress(void) { _AX=0x03; geninterrupt(0x33); return(_BX&2); }
void MouseGetXY(void) { _AX=0x03; geninterrupt(0x33); MouseX=_CX;
MouseY=_DX; } void Control(void) { int gameFLAG=1; while(1) {
if(gameFLAG) { GameBegain(); GamePlay(); if(gameAGAIN==1) { gameAGAIN=0;
continue; } } MouseOn(); gameFLAG=0; if(LeftPress()) { MouseGetXY();
if(MouseX>280&&MouseX<300&&MouseY>65&&MouseY<85) {
gameFLAG=1; continue; } } if(kbhit()) break; } MouseOff(); } void
DrawSmile(void) { setfillstyle(SOLID_FILL,YELLOW);
fillellipse(290,75,10,10); setcolor(YELLOW);
setfillstyle(SOLID_FILL,BLACK); fillellipse(285,75,2,2);
fillellipse(295,75,2,2); setcolor(BLACK); bar(287,80,293,81); } void
DrawRedflag(int i,int j) { setcolor(7); setfillstyle(SOLID_FILL,RED);
bar(198+j*20,95+i*20,198+j*20+5,95+i*20+5); setcolor(BLACK);
line(198+j*20,95+i*20,198+j*20,95+i*20+10); } void DrawEmpty(int
i,int j,int mode,int color) { setcolor(color);
setfillstyle(SOLID_FILL,color); if(mode==0)
bar(200+j*20-8,100+i*20-8,200+j*20+8,100+i*20+8); else if(mode==1)
bar(200+j*20-7,100+i*20-7,200+j*20+7,100+i*20+7); } void
GameBegain(void) { int i,j; cleardevice(); if(gamePLAY!=1) {
MouseSetXY(290,70); MouseX=290; MouseY=70; } gamePLAY=1; mineNUM=0;
setfillstyle(SOLID_FILL,7); bar(190,60,390,290); for(i=0;i<10;i++)
for(j=0;j<10;j++) DrawEmpty(i,j,0,8); setcolor(7); DrawSmile();
randomize();//__page_break__ for(i=0;i<10;i++)
for(j=0;j<10;j++) { Mine[i][j].num=random(8);
if(Mine[i][j].num==1) mineNUM++; else Mine[i][j].num=2;
Mine[i][j].flag=0; } sprintf(randmineNUM,”%d”,mineNUM); setcolor(1);
settextstyle(0,0,2); outtextxy(210,70,randmineNUM); mineNUM=100-mineNUM;
MouseOn(); } void GameOver(void) { int i,j; setcolor(0);
for(i=0;i<10;i++) for(j=0;j<10;j++) if(Mine[i][j].num==1) {
DrawEmpty(i,j,0,RED); setfillstyle(SOLID_FILL,BLACK);
fillellipse(200+j*20,100+i*20,7,7); } } void GameWin(void) {
setcolor(11); settextstyle(0,0,2); outtextxy(230,30,”YOU WIN!”); } int
MineStatistics(int i,int j) { int nNUM=0; if(i==0&&j==0) {
if(Mine[0][1].num==1) nNUM++; if(Mine[1][0].num==1) nNUM++;
if(Mine[1][1].num==1) nNUM++; } else if(i==0&&j==9) {
if(Mine[0][8].num==1) nNUM++; if(Mine[1][9].num==1) nNUM++;
if(Mine[1][8].num==1) nNUM++; } else if(i==9&&j==0) {
if(Mine[8][0].num==1) nNUM++; if(Mine[9][1].num==1) nNUM++;
if(Mine[8][1].num==1) nNUM++; } else if(i==9&&j==9) {
if(Mine[9][8].num==1) nNUM++; if(Mine[8][9].num==1) nNUM++;
if(Mine[8][8].num==1) nNUM++; } else if(j==0) {
if(Mine[i][j+1].num==1) nNUM++; if(Mine[i+1][j].num==1) nNUM++;
if(Mine[i-1][j].num==1) nNUM++; if(Mine[i-1][j+1].num==1)
nNUM++; if(Mine[i+1][j+1].num==1) nNUM++; } else if(j==9) {
if(Mine[i][j-1].num==1) nNUM++; if(Mine[i+1][j].num==1) nNUM++;
if(Mine[i-1][j].num==1) nNUM++; if(Mine[i-1][j-1].num==1)
nNUM++; if(Mine[i+1][j-1].num==1) nNUM++; } else if(i==0) {
if(Mine[i+1][j].num==1) nNUM++; if(Mine[i][j-1].num==1) nNUM++;
if(Mine[i][j+1].num==1) nNUM++; if(Mine[i+1][j-1].num==1)
nNUM++; if(Mine[i+1][j+1].num==1) nNUM++; } else if(i==9) {
if(Mine[i-1][j].num==1) nNUM++; if(Mine[i][j-1].num==1) nNUM++;
if(Mine[i][j+1].num==1) nNUM++; if(Mine[i-1][j-1].num==1)
nNUM++; if(Mine[i-1][j+1].num==1) nNUM++; } else {
if(Mine[i-1][j].num==1) nNUM++; if(Mine[i-1][j+1].num==1)
nNUM++; if(Mine[i][j+1].num==1) nNUM++;
if(Mine[i+1][j+1].num==1) nNUM++; if(Mine[i+1][j].num==1)
nNUM++; if(Mine[i+1][j-1].num==1) nNUM++;
if(Mine[i][j-1].num==1) nNUM++; if(Mine[i-1][j-1].num==1)
nNUM++; }//__page_break__ return (nNUM); } int ShowWhite(int i,int
j) { if(Mine[i][j].flag==1||Mine[i][j].num==0) return;
mineNUM–; if(Mine[i][j].roundnum==0&&Mine[i][j].num!=1) {
DrawEmpty(i,j,1,7); Mine[i][j].num=0; } else
if(Mine[i][j].roundnum!=0) { DrawEmpty(i,j,0,8);
sprintf(randmineNUM,”%d”,Mine[i][j].roundnum); setcolor(RED);
outtextxy(195+j*20,95+i*20,randmineNUM); Mine[i][j].num=0; return
; } if(i!=0&&Mine[i-1][j].num!=1) ShowWhite(i-1,j);
if(i!=0&&j!=9&&Mine[i-1][j+1].num!=1) ShowWhite(i-1,j+1);
if(j!=9&&Mine[i][j+1].num!=1) ShowWhite(i,j+1);
if(j!=9&&i!=9&&Mine[i+1][j+1].num!=1) ShowWhite(i+1,j+1);
if(i!=9&&Mine[i+1][j].num!=1) ShowWhite(i+1,j);
if(i!=9&&j!=0&&Mine[i+1][j-1].num!=1) ShowWhite(i+1,j-1);
if(j!=0&&Mine[i][j-1].num!=1) ShowWhite(i,j-1);
if(i!=0&&j!=0&&Mine[i-1][j-1].num!=1) ShowWhite(i-1,j-1); } void
GamePlay(void) { int i,j,Num; for(i=0;i<10;i++) for(j=0;j<10;j++)
Mine[i][j].roundnum=MineStatistics(i,j); while(!kbhit()) {
if(LeftPress()) { MouseGetXY();
if(MouseX>280&&MouseX<300&&MouseY>65&&MouseY<85) {
MouseOff(); gameAGAIN=1; break; }
if(MouseX>190&&MouseX<390&&MouseY>90&&MouseY<290) {
j=(MouseX-190)/20; i=(MouseY-90)/20; if(Mine[i][j].flag==1)
continue; if(Mine[i][j].num!=0) { if(Mine[i][j].num==1) {
MouseOff(); GameOver(); break; } else { MouseOff();
Num=MineStatistics(i,j); if(Num==0) ShowWhite(i,j); else {
sprintf(randmineNUM,”%d”,Num); setcolor(RED);
outtextxy(195+j*20,95+i*20,randmineNUM); mineNUM–; } MouseOn();
Mine[i][j].num=0; if(mineNUM<1) { GameWin(); break; } } } } }
if(RightPress()) { MouseGetXY();
if(MouseX>190&&MouseX<390&&MouseY>90&&MouseY<290) {
j=(MouseX-190)/20; i=(MouseY-90)/20; MouseOff();
if(Mine[i][j].flag==0&&Mine[i][j].num!=0) { DrawRedflag(i,j);
Mine[i][j].flag=1; } else if(Mine[i][j].flag==1) {
DrawEmpty(i,j,0,8); Mine[i][j].flag=0; } } MouseOn(); sleep(1); } }
}

int m_poly[8]={0,0,5,7,0,9,0,0};/*鼠标*/
int m_now_poly[8]={0,0,5,7,0,9,0,0};
int re[10][6];/*储存鼠标经过前的像素颜色*/
int m_s[93-40+1][52-2+1];

#define MouseDoubleClickTime 0.3    /*鼠标双击的最大时间间隔*/
clock_t LastMouseClickTime=0;    /*上一次鼠标单击的时间*/
clock_t NowMouseClickTime=0;    /*这次鼠标单击的时间  */
char   
MouseClickType=0;        /*上一次鼠标单击是左键还是右键:1–左键,2–右键*/

//时钟 #include<graphics.h> #include<math.h>
#include<dos.h> #define pi 3.1415926 #define X(a,b,c)
x=a*cos(b*c*pi/180-pi/2)+300; #define Y(a,b,c)
y=a*sin(b*c*pi/180-pi/2)+240; #define d(a,b,c)
X(a,b,c);Y(a,b,c);line(300,240,x,y) void init() {int i,l,x1,x2,y1,y2;
setbkcolor(0); circle(300,240,200); circle(300,240,205);
circle(300,240,5); for(i=0;i<60;i++) {if(i%5==0) l=15; else l=5;
x1=200*cos(i*6*pi/180)+300; y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300; y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2); } } main() { int x,y; int gd=VGA,gm=2; unsigned char
h,m,s; struct time t[1]; initgraph(&gd,&gm,”d://tc20//BGI”); init();
setwritemode(1); gettime(t); h=t[0].ti_hour; m=t[0].ti_min;
s=t[0].ti_sec; setcolor(7); d(150,h,30); setcolor(14); d(170,m,6);
setcolor(4); d(190,s,6); while(!kbhit()) {while(t[0].ti_sec==s)
gettime(t); sound(400); delay(70); sound(200); delay(30); nosound();
setcolor(4); d(190,s,6); s=t[0].ti_sec; d(190,s,6); if
(t[0].ti_min!=m) { setcolor(14); d(170,m,6); m=t[0].ti_min;
d(170,m,6); } if (t[0].ti_hour!=h) { setcolor(7); d(150,h,30);
h=t[0].ti_hour; d(150,h,30); sound(1000); delay(240); nosound();
delay(140); sound(2000); delay(240); nosound(); } } getch();
closegraph(); }

int n1=-1,n2=-1;
int hard=1;/*0:易 1:中 2: 难*/
int count=40;/*地雷数量*/
int mx=16,my=16;/*地图宽高*/
char
map[16][30];/*0位存放是否有地雷,1有0无,1位存放是否打开,1打开0没有打开,2位表示是否插旗,1有0无*/
int ha_x=320-120,ha_y=240-100;/*游戏栏*/
int dead=0;/*1:死亡 2:生*/
int score=0;

int arrowMousePixSave[16][10];    /*用于保存鼠标即将覆盖的区域*/
int
arrowMouseDraw[16][10]={    /*设计鼠标的形状,其中1:表示鼠标的边界,2:表示鼠标边界所包围的区域,3:表示鼠标以外的区域*/
    {1,1,3,3,3,3,3,3,3,3},
    {1,2,1,3,3,3,3,3,3,3},
    {1,2,2,1,3,3,3,3,3,3},
    {1,2,2,2,1,3,3,3,3,3},
    {1,2,2,2,2,1,3,3,3,3},
    {1,2,2,2,2,2,1,3,3,3},
    {1,2,2,2,2,2,2,1,3,3},
    {1,2,2,2,2,2,2,2,1,3},
    {1,2,2,2,2,2,2,2,2,1},
    {1,2,2,2,2,2,2,1,3,3},
    {1,2,2,2,2,2,1,3,3,3},
    {1,2,1,3,1,2,2,1,3,3},
    {1,1,3,3,1,2,2,1,3,3},
    {3,3,3,3,3,1,2,2,1,3},
    {3,3,3,3,3,1,2,2,1,3},
    {3,3,3,3,3,3,1,2,2,1} };
int editMousePixSave[15][5];
int editMouseDraw[15][5]={
    {1,1,3,1,1},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {3,3,1,3,3},
    {1,1,3,1,1}    };

//贪吃蛇 #define N 200 #include <graphics.h> #澳门新葡萄京官网注册 ,include
<stdlib.h> #include <dos.h> #define LEFT 0x4b00 #define
RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b
int i,key; int score=0; int gamespeed=50000; struct Food { int x; int y;
int yes; }food; struct Snake { int x[N]; int y[N]; int node; int
direction; int life; }snake; void Init(void); void Close(void); void
DrawK(void); void GameOver(void); void GamePlay(void); void
PrScore(void); void main(void) { Init(); DrawK(); GamePlay(); Close(); }
void Init(void) { int gd=DETECT,gm; initgraph(&gd,&gm,”D://tc20//BGI”);
cleardevice(); } void DrawK(void) { setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH); for(i=50;i<=600;i+=10) {
rectangle(i,40,i+10,49); rectangle(i,451,i+10,460); }
for(i=40;i<=450;i+=10) { rectangle(50,i,59,i+10);
rectangle(601,i,610,i+10); } } void GamePlay(void) { randomize();
food.yes=1; snake.life=0; snake.direction=1;
snake.x[0]=100;snake.y[0]=100; snake.x[1]=110;snake.y[1]=100;
snake.node=2; PrScore(); while(1) { while(!kbhit()) { if(food.yes==1) {
food.x=rand()%400+60; food.y=rand()%350+60; while(food.x%10!=0)
food.x++; while(food.y%10!=0) food.y++; food.yes=0; } if(food.yes==0) {
setcolor(GREEN); rectangle(food.x,food.y,food.x+10,food.y-10); }
for(i=snake.node-1;i>0;i–) { snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1]; } switch(snake.direction) { case
1:snake.x[0]+=10;break; case 2: snake.x[0]-=10;break; case 3:
snake.y[0]-=10;break; case 4: snake.y[0]+=10;break; }
for(i=3;i<snake.node;i++) {
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0]) { GameOver();
snake.life=1; break; } }
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455) { GameOver(); snake.life=1; } if(snake.life==1)
break; if(snake.x[0]==food.x&&snake.y[0]==food.y) { setcolor(0);
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20; snake.node++;
food.yes=1; score+=10; PrScore(); } setcolor(4);
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10, snake.y[i]-10);
delay(gamespeed); setcolor(0);
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10); }
if(snake.life==1) break; key=bioskey(0); if(key==ESC) break; else
if(key==UP&&snake.direction!=4) snake.direction=3; else
if(key==RIGHT&&snake.direction!=2) snake.direction=1; else
if(key==LEFT&&snake.direction!=1) snake.direction=2; else
if(key==DOWN&&snake.direction!=3) snake.direction=4; } } void
GameOver(void) { cleardevice(); PrScore(); setcolor(RED);
settextstyle(0,0,4); outtextxy(200,200,”GAME OVER”); getch(); } void
PrScore(void) { char str[10]; setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35); setcolor(6); settextstyle(0,0,2);
sprintf(str,”score:%d”,score); outtextxy(55,20,str); } void Close(void)
{ getch(); closegraph(); }

void menu_window();

void MountMouse();            /*加载鼠标*/
void UnmountMouse();        /*卸载鼠标*/
void DrawMouseOnly(int,int);    
   /*绘画鼠标,但不保存即将被鼠标覆盖的区域*/
void
MouseOn(int,int);        /*显示鼠标,但保存即将被鼠标覆盖的区域*/
void MouseOff(int,int);        /*隐藏鼠标*/
void SetMouseHoriBound(int,int);    /*设置鼠标水平方向边界*/
void SetMouseVertBound(int,int);    /*设置鼠标垂直方向边界*/
void SetMouseXY(int,int);             /*设置鼠标的初始位置*/
void GetMouseXY();            /*获得鼠标的当前位置*/
void MouseSpeed(int,int);             /*设置鼠标的速度*/
int  MouseStatus(int);        /*获得鼠标按键状态*/
void  Timer(long);            /*计时器*/

//鼠标控制 #include <dos.h> #include <bios.h> #include
<malloc.h> #include <stdlib.h> #include <stdio.h>
#include “graphics.h” #define R 15 void initgr(void) { int gd =
DETECT, gm = 0; initgraph(&gd, &gm, “D://TC20//BGI”); } void
getmouse(int *x,int *y,int *key) { union REGS inregs,outregs;
inregs.x.ax=3; int86(0x33,&inregs,&outregs); *x=outregs.x.cx;
*y=outregs.x.dx; *key=outregs.x.bx; } void visbilemouse() { union REGS
inregs,outregs; inregs.x.ax=0x01; int86(0x33,&inregs,&outregs); } void
mouse(int *x,int *y,int *z) { int a=0,b=0,c=0,a_old=0,b_old=0; int
*ball; ball=malloc(imagesize(a,b,a+R,b+R)); getimage(a,b,a+R,b+R,ball);
while(c==0) { getmouse(&a,&b,&c); if(a<0) a=0; if(b<0) b=0;
if(a>getmaxx()-R) a=getmaxx()-R; if(b>getmaxy()-R) b=getmaxy()-R;
if(a!=a_old || b!=b_old) { putimage(a_old,b_old,ball,0);
getimage(a,b,a+R,b+R,ball); setcolor(GREEN); setlinestyle(0,0,1);
line(a,b,a+R,b+R/2); line(a,b,a+R/2,b+R); line(a+R,b+R/2,a+R/2,b+R);
line(a+R*3/4,b+R*3/4,a+R,b+R); } a_old=a;b_old=b; }
*x=a;*y=b;*z=c; putimage(a,b,ball,0); free(ball); } void main() { int
x,y,z; initgr(); visbilemouse(); do { setcolor(WHITE);
rectangle(175,8,220,25); outtextxy(180,10,”exit”); mouse(&x,&y,&z);
if(z==1) { setlinestyle(0,0,1); setcolor(12); circle(x,y,1); } if(z==2)
{setfillstyle(1,BLACK); bar(0,0,getmaxx(),getmaxy()); } }while(x<175
|| x>220 || y<8 || y>25); closegraph(); }

char sao16S[]={
/* 以下是 ‘扫’ 的 16点阵宋体 字模,32 byte */
  0x10,0x00,0x10,0x00,0x11,0xFC,0x10,0x04,
  0xFE,0x04,0x10,0x04,0x14,0x04,0x18,0xFC,
  0x30,0x04,0xD0,0x04,0x10,0x04,0x10,0x04,
  0x11,0xFC,0x50,0x00,0x20,0x00,0x00,0x00,
};

void  Timer(long getTime)        /*计时器*/
{
    clock_t startTime=clock();
    clock_t endTime=clock();
    while((endTime-startTime)>=getTime)
    {
        endTime=clock();
    }
    return ;
}
/*加载鼠标*/
void MountMouse()
{
    _AX=0x00;        /*功能00H*/
    geninterrupt(0x33);    /*0x33:鼠标中断类型*/

 

char lei16S[]={
    /* 以下是 ‘雷’ 的 16点阵宋体 字模,32 byte */
    0x1F,0xF8,0x01,0x00,0x7F,0xFE,0x41,0x04,
    0x1D,0x70,0x01,0x00,0x1D,0x70,0x01,0x00,
    0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,
    0x21,0x08,0x21,0x08,0x3F,0xF8,0x20,0x08,
};

   
MouseHolded      =_AX;    /*_AX为0000H——不支持鼠标功能,为FFFFH——支持鼠标功能*/
    MouseButtonNum=_BX;    /*鼠标按钮个数*/
}

 

char you12S[]={
/* 以下是 ‘游’ 的 12点阵宋体 字模,24 byte */
  0x91,0x00,0x49,0xE0,0x3E,0x00,0x93,0xE0,
  0x5C,0x40,0x54,0x80,0x55,0xE0,0x94,0x80,
  0x94,0x80,0xA4,0x80,0x4D,0x80,0x00,0x00,
};

/*卸载鼠标*/
void UnmountMouse()
{
    _AX=0x02;        /*功能02H*/
    geninterrupt(0x33);    /*0x33:鼠标中断类型*/
    return ;
}


char xi12S[]={
/* 以下是 ‘戏’ 的 12点阵宋体 字模,24 byte */
  0x02,0x80,0xF2,0x40,0x12,0x40,0x13,0xE0,
  0x9E,0x00,0x52,0x40,0x22,0x80,0x31,0x00,
  0x49,0x20,0x42,0xA0,0x8C,0x60,0x00,0x00,
};

/*设置鼠标水平边界:minX为水平方向的最小值,maxX为水平方向的最大值*/
void SetMouseHoriBound(int minX,int maxX)
{
    _AX=0x07;
    _CX=minX;
    _DX=maxX;
    geninterrupt(0x33);
    return;
}

char kai12S[]={
/* 以下是 ‘开’ 的 12点阵宋体 字模,24 byte */
  0x00,0x40,0x7F,0xE0,0x11,0x00,0x11,0x00,
  0x11,0x00,0xFF,0xE0,0x11,0x00,0x11,0x00,
  0x11,0x00,0x21,0x00,0xC1,0x00,0x00,0x00,
};

/*设置鼠标垂直边界:minY为垂直方向的最小值,maxY为垂直方向的最大值*/
void SetMouseVertBound(int minY,int maxY)
{
    _AX=0x08;
    _CX=minY;
    _DX=maxY;
    geninterrupt(0x33);
    return;
}

char ju12S[]={
/* 以下是 ‘局’ 的 12点阵宋体 字模,24 byte */
  0x3F,0xC0,0x20,0x40,0x3F,0xC0,0x20,0x00,
  0x3F,0xE0,0x20,0x20,0x2F,0x20,0x29,0x20,
  0x4F,0x20,0x49,0x20,0x80,0xC0,0x00,0x00,
};

/*设置鼠标指针位置:xValue为水平方向位置,yValue为垂直方向的位置*/
void SetMouseXY(int xValue,int yValue)
{
    _AX=0x04;
    _CX=xValue;
    _DX=yValue;
    geninterrupt(0x33);
    return;
}

char tui12S[]={
/* 以下是 ‘退’ 的 12点阵宋体 字模,24 byte */
  0x8F,0xC0,0x48,0x40,0x4F,0xC0,0x08,0x40,
  0xCF,0xC0,0x48,0x00,0x4B,0x40,0x48,0x80,
  0x4E,0x40,0xB0,0x00,0x8F,0xE0,0x00,0x00,
};

/*读取鼠标位置*/
void GetMouseXY()
{
    _AX=0x03;
    geninterrupt(0x33);

char chu12S[]={
/* 以下是 ‘出’ 的 12点阵宋体 字模,24 byte */
  0x04,0x00,0x44,0x40,0x44,0x40,0x44,0x40,
  0x7F,0xC0,0x04,0x00,0x44,0x40,0x44,0x40,
  0x44,0x40,0x44,0x40,0x7F,0xC0,0x00,0x00,
};

    MouseX=_CX;        /*将鼠标水平方向位置存放到MouseX*/
    MouseY=_DX;        /*将鼠标垂直方向位置存放到MouseY*/
    return;
}

char nan12S[]={
/* 以下是 ‘难’ 的 12点阵宋体 字模,24 byte */
  0x02,0x80,0x02,0x80,0xF7,0xE0,0x14,0x80,
  0x9F,0xE0,0x54,0x80,0x24,0x80,0x27,0xE0,
  0x54,0x80,0x94,0x80,0x07,0xE0,0x00,0x00,
};

/*设置鼠标速度*/
void MouseSpeed(int xSpeed,int ySpeed)
{
   _CX=xSpeed;
   _DX=ySpeed;
   _AX=0x0f;
   geninterrupt(0x33);
}

char du12S[]={
/* 以下是 ‘度’ 的 12点阵宋体 字模,24 byte */
  0x02,0x00,0x7F,0xE0,0x48,0x80,0x7F,0xE0,
  0x48,0x80,0x4F,0x80,0x40,0x00,0x5F,0x80,
  0x45,0x00,0x87,0x00,0xB8,0xE0,0x00,0x00,
};

/*绘画鼠标,但不保存即将被鼠标覆盖的区域*/
void DrawMouseOnly(int mousex,int mousey)
{
    int i,j;
    int color;

char yi12S[]={
/* 以下是 ‘易’ 的 12点阵宋体 字模,24 byte */
  0x3F,0x80,0x20,0x80,0x3F,0x80,0x20,0x80,
  0x3F,0x80,0x10,0x00,0x3F,0xC0,0xC9,0x40,
  0x12,0x40,0x64,0x40,0x19,0x80,0x00,0x00,
};

    if(MouseType==1)
    {
        for(i=0;i<16;i++)
    for(j=0;j<10;j++)
    {                
        if(arrowMouseDraw[i][j]==1)
        putpixel(mousex+j,mousey+i,0);
        else if(arrowMouseDraw[i][j]==2)    /* 画鼠标*/
        putpixel(mousex+j,mousey+i,15);
    }    
    }
    else if(MouseType==2)
    {
    for(i=0;i<15;i++)
                for(j=0;j<5;j++)
        {
        if(editMouseDraw[i][j]==1)    /*由于编辑鼠标的热点在鼠标的中心*/
                putpixel(mousex-2+j,mousey-7+i,0);
        }
     }
}

char zhong12S[]={
/* 以下是 ‘中’ 的 12点阵宋体 字模,24 byte */
  0x04,0x00,0x04,0x00,0x7F,0xC0,0x44,0x40,
  0x44,0x40,0x44,0x40,0x7F,0xC0,0x04,0x00,
  0x04,0x00,0x04,0x00,0x04,0x00,0x00,0x00,
};

/*显示鼠标,但保存即将被鼠标覆盖的区域*/
void MouseOn(int mousex,int mousey)
{
    int i,j;
    int color;

void drawmat(char *mat,int matsize,int x,int y,int
color){/*点阵字显示函数*/
    int i,j,k,n;
    n=(matsize-1)/8+1;/*有几个字符位*/
    for(j=0;j<matsize;j++)/*行*/
        for(i=0;i<n;i++)
            for(k=0;k<8;k++)
                if(mat[j*n+i]&0x80>>k)
                    putpixel(x+i*8+k,y+j,color);
}

    if(MouseType==1)
    {
        for(i=0;i<16;i++)
    for(j=0;j<10;j++)
    {
        arrowMousePixSave[i][j]=getpixel(mousex+j,mousey+i);/*
保存原来的颜色*/
        if(arrowMouseDraw[i][j]==1)
        putpixel(mousex+j,mousey+i,0);
        else if(arrowMouseDraw[i][j]==2)        /* 画鼠标*/
            putpixel(mousex+j,mousey+i,15);
    }    
    }
    else if(MouseType==2)
    {
    for(i=0;i<15;i++)
            for(j=0;j<5;j++)
            {
        
   editMousePixSave[i][j]=getpixel(mousex-2+j,mousey-7+i);
        if(editMouseDraw[i][j]==1)            /*由于编辑鼠标的热点在鼠标的中心*/
            putpixel(mousex-2+j,mousey-7+i,0);
        }
    }
}

void game_over(){
    int x,y;

/*隐藏鼠标*/
void MouseOff(int mousex,int mousey)
{
   int i,j,x,y,color;
   x=mousex;
   y=mousey;

    setcolor(BLACK);
    for(y=0;y<my;y++)
        for(x=0;x<mx;x++)
            if(map[y][x]&1){
                setfillstyle(SOLID_FILL,LIGHTGRAY);
               
bar(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10+8);

   if(MouseType==1)
   {
    for(i=0;i<16;i++)
    for(j=0;j<10;j++)
    {
        if(arrowMouseDraw[i][j]==3)
        continue;
        color=getpixel(x+j,y+i);
        putpixel(x+j,y+i,color^color);        /*原位置异或清除*/
        putpixel(x+j,y+i,arrowMousePixSave[i][j]);/*
还原原背景*/
    }
   }
   else if(MouseType==2)
   {
        for(i=0;i<15;i++)
    for(j=0;j<5;j++)
    {
        if(editMouseDraw[i][j]==3)
            continue;
        color=getpixel(x-2+j,y-7+i);
        putpixel(x-2+j,y-7+i,color^color);    /*原位置异或清除*/
        putpixel(x-2+j,y-7+i,editMousePixSave[i][j]);/*
还原原背景*/
    }
   }
}

                circle(ha_x+2+x*10+4,ha_y+2+y*10+4,3);/*地雷图*/
                setfillstyle(SOLID_FILL,BLACK);
               
floodfill(ha_x+2+x*10+4,ha_y+2+y*10+4,BLACK);/*黑色填充*/
            }
}

/*获取鼠标状态*/
int MouseStatus(int Mouse_On_Off)
{
  int MouseMSG=0;
  int oldMouseX,oldMouseY;
  int i,j,color;

void win(){
    setviewport(0,0,639,479,0);
    settextstyle(0,0,3);
    setcolor(WHITE);
    outtextxy(216,211,”you
win!!!”);/****************显示you
win****************/
    setcolor(GREEN);
    outtextxy(215,210,”you
win!!!”);/****************显示you
win****************/
}

  oldMouseX=MouseX,oldMouseY=MouseY;    /*保存当前鼠标的位置*/

void box_open(int x,int y,int
control){/*方格被打开,control用于判断是否是鼠标点击打开,1表示鼠标点击,0表示自动*/
    int sum=0;
    char num[2];

  _AX=0x03;            /*读取鼠标按钮状态*/
  geninterrupt(0x33);        /*产生33号鼠标软中断*/

    if(map[y][x]>>2&1 && control)return;/*标记过,点击无效*/

  if((_BX&1) &&
!(_BX&2))        /*鼠标左键被按下同时右键没有按下*/
    MouseMSG=4;

    if(map[y][x]>>1&1)return;/*检查是否被打开过*/
    map[y][x]+=1<<1;

  if((_BX&2) &&
!(_BX&1))        /*鼠标右键被按下同时左键没有按下*/
    MouseMSG=5;

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10+8);

  if(_BX&1 && _BX&2)        /*鼠标左键和右键同时被按下*/
    MouseMSG=3;

    if(map[y][x]&1==1){/*踩到地雷,游戏失败*/
        game_over();
        dead=1;/*死亡*/
        return;
    }
    score++;/*加分*/
    if(score==mx*my-count){
        win();
        dead=1;
        return;
    }

  _AX=0x06;            /*读取鼠标按钮释放信息*/
  _BX=0x00;            /*指定读取鼠标左键的释放信息*/
  geninterrupt(0x33);        /*产生33号鼠标软中断*/
  if(_BX==1)            /*如果鼠标左键的释放数为1*/
    MouseMSG=2;            /*产生一个单击左键信息*/

    if(x!=0)sum+=map[y][x-1]&1;
    if(x!=mx-1)sum+=map[y][x+1]&1;
    if(y!=0)sum+=map[y-1][x]&1;
    if(y!=my-1)sum+=map[y+1][x]&1;
    if(x!=0 && y!=0)sum+=map[y-1][x-1]&1;
    if(x!=mx-1 && y!=0)sum+=map[y-1][x+1]&1;
    if(x!=mx-1 && y!=my-1)sum+=map[y+1][x+1]&1;
    if(x!=0 && y!=my-1)sum+=map[y+1][x-1]&1;

  _AX=0x06;            /*读取鼠标按钮释放信息*/
  _BX=0x01;            /*指定读取鼠标右键的释放信息*/
  geninterrupt(0x33);        /*产生33号鼠标软中断*/
  if(_BX==1)            /*如果鼠标左键的释放次数为1*/
    MouseMSG=1;            /*产生一个单击右键信息*/

    settextstyle(0,0,1);
    if(sum!=0){
        sprintf(num,”%d”,sum);
        setcolor(sum%6);/*确定颜色*/
       
outtextxy(ha_x+2+x*10+1,ha_y+2+y*10+1,num);/*显示周围雷数*/
    }
    else{
        if(x!=0 &&
!map[y][x-1]&1)box_open(x-1,y,0);/*0表示自动打开*/
        if(x!=mx-1 && !map[y][x+1]&1)box_open(x+1,y,0);
        if(y!=0 && !map[y-1][x]&1)box_open(x,y-1,0);
        if(y!=my-1 && !map[y+1][x]&1)box_open(x,y+1,0);
        if(x!=0 && y!=0 && !map[y-1][x-1]&1)box_open(x-1,y-1,0);
        if(x!=mx-1 && y!=0 &&
!map[y-1][x+1]&1)box_open(x+1,y-1,0);
        if(x!=mx-1 && y!=my-1 &&
!map[y+1][x+1])box_open(x+1,y+1,0);
        if(x!=0 && y!=my-1 && !map[y+1][x-1])box_open(x-1,y+1,0);
    }
}

  GetMouseXY();            /*获得当前鼠标位置,并把数据赋给MouseX,MouseY*/

void box_mark(int x,int y){/*给小方块插旗标记*/
    int nx=ha_x+2+x*10,ny=ha_y+2+y*10;
    if(map[y][x]>>1&1)return;/*已经打开*/
   
if(map[y][x]>>2&1)map[y][x]-=1<<2;/*有旗拔旗*/
    else map[y][x]+=1<<2;/*插旗*/

  if(Mouse_On_Off==MouseStatusMouseOn)    /*实时显示*/
     if(oldMouseX!=MouseX || oldMouseY!=MouseY)
     {
        MouseOff(oldMouseX,oldMouseY);
        MouseOn(MouseX,MouseY);
      }

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    setcolor(WHITE);
   
line(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10);/*一横,使之有立体感*/
   
line(ha_x+2+x*10,ha_y+2+y*10+1,ha_x+2+x*10,ha_y+2+y*10+8);/*一竖*/

  /*鼠标双击的判断*/
  if(MouseMSG==3)            /*如果是同时按下鼠标的左键*/
   
MouseClickType=0;        /*上一次的按键是既不是鼠标左键也不是鼠标右键*/
  else if(MouseMSG==1)        /*如果是按下鼠标的右键*/
  {
     if(MouseClickType==2)        /*如果上一次也是按下鼠标的右键*/
     {
    NowMouseClickTime=clock();/*获得现在的程序运行时间*/
    /*判断上一次按下鼠标的右键到这次按下鼠标右键的时间间隔是不是小于最大鼠标双击时间间隔*/
    if(((NowMouseClickTime-LastMouseClickTime)/CLK_TCK)<=MouseDoubleClickTime)
         MouseMSG=6;        /*鼠标消息为右键双击*/
    LastMouseClickTime=NowMouseClickTime;
     }
     else
     {
    MouseClickType=2;        /*作为下一次的按键判断时的上一次按键状态*/
    NowMouseClickTime=clock(); 
 /*作为下一次的按键判断时的上一次按键时间*/
    LastMouseClickTime=NowMouseClickTime;
     }
   }
   else if(MouseMSG==2)
   {
    if(MouseClickType==1)
    {
        NowMouseClickTime=clock();/*获得现在的程序运行时间*/
       
/*判断上一次按下鼠标的左键到这次按下鼠标左键的时间间隔是不是小于最大鼠标双击时间间隔*/
       
if(((NowMouseClickTime-LastMouseClickTime)/CLK_TCK)<=MouseDoubleClickTime)
        MouseMSG=7;    /*鼠标消息为左键双击*/
        LastMouseClickTime=NowMouseClickTime;
    }
    else
    {
        MouseClickType=1;        
   /*作为下一次的按键判断时的上一次按键状态*/
        NowMouseClickTime=clock();   
/*作为下一次的按键判断时的上一次按键时间*/
        LastMouseClickTime=NowMouseClickTime;
    }
   }

   
bar(ha_x+2+x*10+1,ha_y+2+y*10+1,ha_x+2+x*10+8,ha_y+2+y*10+8);

  return MouseMSG;        /*返回鼠标按键消息:0–没有按键,1–单击右键,
            2–单击左键,3–同时按下左键和右键,
            4–拖曳左键,5–拖曳右键,6–双击右键,7–双击左键*/
}

    if(map[y][x]>>2&1){
        setcolor(RED); /*绘制小旗帜*/
        line(nx+3,ny+2,nx+7,ny+4);
        line(nx+3,ny+4,nx+7,ny+4);
        setcolor(BLACK);
        line(nx+3,ny+2,nx+3,ny+7);
        line(nx+2,ny+7,nx+4,ny+7);
    }
}

#endif/*ZXF_MOUS_C_INCLUDE*/

void map_window(){/*地图绘制*/
    int x,y;
    setfillstyle(SOLID_FILL,BLACK);/*清除屏幕*/
    bar(1,40,638,478);/*清除屏幕*/

    setcolor(WHITE);
    rectangle(ha_x,ha_y,ha_x+1+mx*10+1,ha_y+1+my*10+1);
    setfillstyle(SOLID_FILL,DARKGRAY);
   
bar(ha_x+1,ha_y+1,ha_x+1+mx*10,ha_y+1+my*10);/*扫雷部分背景*/

    rectangle(ha_x,ha_y-30,ha_x+1+mx*10+1,ha_y);/*扫雷上部分*/
    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(ha_x+1,ha_y-29,ha_x+1+mx*10,ha_y-1);/*扫雷上部分*/

    setfillstyle(SOLID_FILL,LIGHTGRAY);/*绘制开局框–*/
    setcolor(WHITE);
   
line((ha_x+ha_x+2+mx*10)/2-16,(ha_y+ha_y-30)/2-9,(ha_x+ha_x+2+mx*10)/2-16,(ha_y+ha_y-30)/2+8);/*竖*/
   
line((ha_x+ha_x+2+mx*10)/2-15,(ha_y+ha_y-30)/2-9,(ha_x+ha_x+2+mx*10)/2+15,(ha_y+ha_y-30)/2-9);/*横*/
    setcolor(DARKGRAY);
   
line((ha_x+ha_x+2+mx*10)/2+16,(ha_y+ha_y-30)/2-9,(ha_x+ha_x+2+mx*10)/2+16,(ha_y+ha_y-30)/2+9);/*竖*/
   
line((ha_x+ha_x+2+mx*10)/2-15,(ha_y+ha_y-30)/2+9,(ha_x+ha_x+2+mx*10)/2+15,(ha_y+ha_y-30)/2+9);/*横*/
   
bar((ha_x+ha_x+2+mx*10)/2-15,(ha_y+ha_y-30)/2-8,(ha_x+ha_x+2+mx*10)/2+15,(ha_y+ha_y-30)/2+8);/*–绘制开局框*/

   
drawmat(kai12S,12,(ha_x+ha_x+2+mx*10)/2-13,(ha_y+ha_y-30)/2-6,BLACK);
   
drawmat(ju12S,12,(ha_x+ha_x+2+mx*10)/2+1,(ha_y+ha_y-30)/2-6,BLACK);

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    for(y=0;y<my;y++)/*显示小方格*/
        for(x=0;x<mx;x++){
            setcolor(WHITE);
           
line(ha_x+2+x*10,ha_y+2+y*10,ha_x+2+x*10+8,ha_y+2+y*10);/*一横,使之有立体感*/
           
line(ha_x+2+x*10,ha_y+2+y*10+1,ha_x+2+x*10,ha_y+2+y*10+8);/*一竖*/

            /*setcolor(DARKGRAY);
           
line(ha_x+2+x*10,ha_y+2+y*10+8,ha_x+2+x*10+8,ha_y+2+y*10+8);
一横
           
line(ha_x+2+x*10+8,ha_y+2+y*10+1,ha_x+2+x*10+8,ha_y+2+y*10+8);
一竖

           
bar(ha_x+2+x*10+1,ha_y+2+y*10+1,ha_x+2+x*10+7,ha_y+2+y*10+7);
            */
           
bar(ha_x+2+x*10+1,ha_y+2+y*10+1,ha_x+2+x*10+8,ha_y+2+y*10+8);
        }
}

void initmap(){/*地图初始化*/
    int i=0,x,y;
    dead=0;
    score=0;

    switch(hard){
    case 0:
        mx=9;
        my=9;
        count=10;
        break;
    case 1:
        mx=16;
        my=16;
        count=40;
        break;
    case 2:
        mx=30;
        my=16;
        count=99;
        break;
    }

    for(y=0;y<my;y++)/*地图数组设为0*/
        for(x=0;x<mx;x++)
            map[y][x]=0;
           
    for(;i<count;){/*随机埋雷*/
        y=rand()%my;
        x=rand()%mx;
        if(map[y][x]==0){
            map[y][x]++;
            i++;
        }
    }
    map_window();
}

void m_save(){/*储存menu挡住的部分*/
    int i,j;
    for(j=40;j<=93;j++)
        for(i=2;i<=52;i++)
            m_s[j-40][i-2]=getpixel(i,j);
}

void m_load(){/*恢复menu挡住的部分*/
    int i,j;
    for(j=40;j<=93;j++)
        for(i=2;i<=52;i++)
            putpixel(i,j,m_s[j-40][i-2]);
}

void ha_mouse(){
    int i,j,k,x=-1,y=-1,flag=0,color;
    int tx1,ty1,tx2,ty2,tbx;
    int new_x=ha_x,new_y=ha_y;
    /*char tgraph[193][303],tg=0;*/
    union REGS inregs,outregs,regs2;

 

    inregs.x.ax=0x03;

    while(!bioskey(1)){

        int86(0x33,&inregs,&outregs);/*调用鼠标中断*/

        regs2.x.ax=0x06;
        regs2.x.bx=0x00;
       
int86(0x33,?s2,?s2);/*CX=水平位置(最后释放时),DX=垂直位置(最后释放时)*/
        tx2=regs2.x.cx;
        ty2=regs2.x.dx;

        if(x!=outregs.x.cx || y!=outregs.x.dx || tbx!=outregs.x.bx){
            /*printf(“%d”,outregs.x.bx);*/
            if(flag){
               
for(j=0;j<10;j++)/*恢复上次鼠标一定范围内的像素颜色*/
                    for(i=0;i<6;i++)
                        putpixel(x+i,y+j,re[j][i]);
            }
            flag=1;
           
/*====================================================================================================================扩充功能部分*/

            if(outregs.x.bx &
0x01){/*鼠标左键按下————————鼠标点击判断*/
                if(outregs.x.cx>=639-19 && outregs.x.cx<=638 &&
outregs.x.dx>=1 && outregs.x.dx<=18)exit(0);/*关闭按钮*/
                else if(outregs.x.cx>=1 && outregs.x.cx<=32 &&
outregs.x.dx>=21 && outregs.x.dx<=38){/*主菜单-游戏*/
                    if(n1==-1)m_save();
                    else if(n1==1)m_load();
                    n1=0;
                    n2=-1;
                    menu_window();
                }
                else if(outregs.x.cx>=33 && outregs.x.cx<=64 &&
outregs.x.dx>=21 && outregs.x.dx<=38){/*主菜单-难度*/
                    if(n1==-1)m_save();
                    else if(n1==0)m_load();
                    n1=1;
                    n2=-1;
                    menu_window();
                }
                else if(n1==0 && n2==1)exit(0);

                /*开局*/
                else if((n1==0 && n2==0) ||
(outregs.x.cx>=(ha_x+ha_x+2+mx*10)/2-16 &&
outregs.x.cx<=(ha_x+ha_x+2+mx*10)/2+16 &&
outregs.x.dx>=(ha_y+ha_y-30)/2-9 &&
outregs.x.dx<=(ha_y+ha_y-30)/2+8)){/*开局*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    initmap();
                }
                else if(n1==1 && n2==0){/*易*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    hard=0;
                    initmap();
                }
                else if(n1==1 && n2==1){/*中*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    hard=1;
                    initmap();
                }
                else if(n1==1 && n2==2){/*难*/
                    dead=0;/*生*/
                    n1=-1;
                    m_load();
                    hard=2;
                    initmap();
                }

                /*
                else if(outregs.x.cx>=new_x &&
outregs.x.cx<=new_x+1+mx*10+1 && outregs.x.dx>+new_y-30 &&
outregs.x.dx<=new_y){ 拖动扫雷图标扫雷
                    if(tg==0){ 扫雷部分存储
                        tg++;
                        for(j=0;j<=1+my*10+1+30;j++)
                            for(i=0;i<=mx*10+2;i++)
                               
tgraph[j][i]=getpixel(ha_x+i,ha_y+j-30);
                    }

                    if(tbx&1 && x>=new_x && x<=new_x+1+mx*10+1
&& y>=new_y-30 && y<=new_y){
                        setcolor(YELLOW);
                       
rectangle(new_x,new_y-29,new_x+1+mx*10,new_y+1+my*10);
                       
rectangle(new_x,new_y-30,new_x+1+mx*10+1,new_y+1+my*10+1);
                        new_x+=outregs.x.cx-x;
                        new_y+=outregs.x.dx-y;
                        tg=2;
                    }
                    else if(tg=2 && x>=new_x &&
x<=new_x+1+mx*10+1 && y>=new_y-30 && y<=new_y){
                        tg=0;
                        ha_x=new_x;
                        ha_y=new_y;
                        for(j=0;j<=1+my*10+1+30;j++)
                            for(i=0;i<=mx*10+2;i++)
                               
putpixel(ha_x+i,ha_y+j-30,tgraph[j][i]);
                    }
                }
                */

                else{/*没有点击到按钮*/
                    if(n1!=-1)m_load();
                    n1=n2=-1;
                    menu_window();
                }

            }

            if(n1==0 && outregs.x.cx>=2 && outregs.x.cx<=31 &&
outregs.x.dx>=40 && outregs.x.dx<=75){/*游戏下级菜单操作*/
                n2=(outregs.x.dx-40)/18;
                menu_window();
            }
            if(n1==1 && outregs.x.cx>=34 && outregs.x.cx<=52 &&
outregs.x.dx>=40 && outregs.x.dx<=93){/*难度下级菜单操作*/
                n2=(outregs.x.dx-40)/18;
                menu_window();
            }

            /*—————————–左键点击控制部分*/
            if(tx2-ha_x-2>=0 && ty2-ha_y-2>=0 &&
(tx2-ha_x-2)/10>=0 && (tx2-ha_x-2)/10<=mx-1 &&
(ty2-ha_y-2)/10>=0 && (ty2-ha_y-2)/10<=my-1 && dead==0 &&
(tx1!=tx2 || ty1!=ty2)){
                box_open((tx2-ha_x-2)/10,(ty2-ha_y-2)/10,1);
            }

            if(outregs.x.bx>>1 & 0x01 &&
dead==0){/*鼠标右键按下————————鼠标点击判断*/
                if((outregs.x.cx-ha_x-2)/10>=0 &&
(outregs.x.cx-ha_x-2)/10<=mx-1 && (outregs.x.dx-ha_y-2)/10>=0 &&
(outregs.x.dx-ha_y-2)/10<=my-1){
                   
box_mark((outregs.x.cx-ha_x-2)/10,(outregs.x.dx-ha_y-2)/10);/*插旗标记*/
                }
            }

 

           
/*================================================================================================================================*/
            for(j=0;j<10;j++)/*储存鼠标一定范围内的像素颜色*/
                for(i=0;i<6;i++)
                   
re[j][i]=getpixel(outregs.x.cx+i,outregs.x.dx+j);

            for(i=0;i<8;i++){/*确定鼠标各顶点位置*/
                m_now_poly[i]=m_poly[i]+outregs.x.cx;
                i++;
                m_now_poly[i]=m_poly[i]+outregs.x.dx;
            }

            setcolor(GREEN);
            drawpoly(4,m_now_poly);/*显示鼠标框架*/
           
setfillstyle(SOLID_FILL,WHITE);/*填充鼠标,注意以白色填充,当遇到白色背景时会不能完全填充*/
            floodfill(m_now_poly[0]+1,m_now_poly[1]+5,GREEN);
            setcolor(LIGHTRED);
            drawpoly(4,m_now_poly);/*显示鼠标框架*/
        }
        x=outregs.x.cx;/*存鼠标坐标,供恢复使用*/
        y=outregs.x.dx;
        tbx=outregs.x.bx;
        tx1=tx2;/*暂存鼠标释放的位置*/
        ty1=ty2;
    }
}

void full_window(){/*整体部分,包括标题栏的绘制*/

    setbkcolor(BLACK);
    setcolor(WHITE);

    line(0,20,639,20);
    rectangle(0,0,639,479);

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(1,1,638,19);

    drawmat(sao16S,16,6,3,BLACK);/*标题部分-汉字*/
    drawmat(lei16S,16,25,3,BLACK);

    setcolor(BLACK);
    settextstyle(0,0,1);
    outtextxy(44,8,”- made by HungryAnt”);

    setfillstyle(SOLID_FILL,RED);/*显示关闭图标*/
    bar(639-19,1,638,18);

    setcolor(WHITE);
    setlinestyle(0,0,3);/*X*/
    line(639-19+2,1+2,638-2,18-2);
    line(639-19+2,18-2,638-2,1+2);
    setlinestyle(0,0,1);
}
  
void
menu_window(){/*——————————————菜单栏*/
    int i;

    setcolor(BLACK);
    for(i=0;i<2;i++){/*主菜单*/
        if(i==n1)setfillstyle(SOLID_FILL,DARKGRAY);
        else setfillstyle(SOLID_FILL,LIGHTGRAY);
        bar(32*i+1,21,32*(i+1),38);
    }

    drawmat(you12S,12,4,21+3,BLACK);/*游戏*/
    drawmat(xi12S,12,4+12+2,21+3,BLACK);
    drawmat(nan12S,12,32+4,21+3,BLACK);/*难度*/
    drawmat(du12S,12,32+4+12+2,21+3,BLACK);

 

    if(n1==0){/*——————包括菜单—————-游戏菜单*/
        for(i=0;i<2;i++){
            if(i==n2)setfillstyle(SOLID_FILL,DARKGRAY);
            else setfillstyle(SOLID_FILL,LIGHTGRAY);
            bar(2,39+(i*(12+6))+1,2+2+12*2+3,39+((i+1)*(12+6)));
        }
        drawmat(kai12S,12,4,39+3,BLACK);/*开局*/
        drawmat(ju12S,12,4+12+2,39+3,BLACK);

        drawmat(tui12S,12,4,39+6+3+12,BLACK);/*退出*/
        drawmat(chu12S,12,4+12+2,39+6+3+12,BLACK);
    }
    else if(n1==1){/*————————————-难度菜单*/
        for(i=0;i<3;i++){
            if(i==n2)setfillstyle(SOLID_FILL,DARKGRAY);
            else setfillstyle(SOLID_FILL,LIGHTGRAY);
            bar(2+32,39+(i*(12+6))+1,2+32+12+6,39+((i+1)*(12+6)));
        }
        drawmat(yi12S,12,2+32+4,39+3,BLACK);/*易中难*/
        drawmat(zhong12S,12,2+32+4,39+18+3,BLACK);
        drawmat(nan12S,12,2+32+4,39+36+3,BLACK);
    }

}

 

ha_graph(){/*图形模式初始化*/
    int gd=DETECT,gm,errorcode;
    initgraph(&gd,&gm,””);
    errorcode = graphresult();
    if (errorcode != grOk){
        printf(“Graphics error: %s”,grapherrormsg(errorcode));
        printf(“Author:HungryAnt”);
        getch();
        exit(1);
    }   
}

int main(){
    int i;

    srand((unsigned)time(NULL));/*使每次执行程序得到的结果不一样*/
    ha_graph();
    full_window();
    menu_window(-1,-1);/*菜单*/
    initmap();/*地图初始化*/

    ha_mouse();/*鼠标*/
}