C语言扫雷源代码.txt如果背叛是一种勇气,那么接受背叛则需要更大的勇气。爱情是块砖,婚姻是座山。砖不在多,有一块就灵;山不在高,守一生就行。 #include
/*鼠标信息宏定义*/
#define WAITING 0xff00 #define LEFTPRESS 0xff01 #define LEFTCLICK 0xff10 #define LEFTDRAG 0xff19 #define RIGHTPRESS 0xff02 #define RIGHTCLICK 0xff20 #define RIGHTDRAG 0xff2a #define MIDDLEPRESS 0xff04 #define MIDDLECLICK 0xff40 #define MIDDLEDRAG 0xff4c #define MOUSEMOVE 0xff08 struct {
int num;/*格子当前处于什么状态,1有雷,0已经显示过数字或者空白格子*/ int roundnum;/*统计格子周围有多少雷*/
int flag;/*右键按下显示红旗的标志,0没有红旗标志,1有红旗标志*/ }Mine[10][10];
int gameAGAIN=0;/*是否重来的变量*/
int gamePLAY=0;/*是否是第一次玩游戏的标志*/ int mineNUM;/*统计处理过的格子数*/
char randmineNUM[3];/*显示数字的字符串*/
int Keystate; int MouseExist; int MouseButton; int MouseX; int MouseY;
int up[16][16],down[16][16],mouse_draw[16][16],pixel_save[16][16];
void MouseMath()/*计算鼠标的样子*/ {int i,j,jj,k; long UpNum[16]={
0x3fff,0x1fff,0x0fff,0x07ff, 0x03ff,0x01ff,0x00ff,0x007f, 0x003f,0x00ff,0x01ff,0x10ff,
0x30ff,0xf87f,0xf87f,0xfc3f };
long DownNum[16]={
0x0000,0x7c00,0x6000,0x7000, 0x7800,0x7c00,0x7e00,0x7f00, 0x7f80,0x7e00,0x7c00,0x4600, 0x0600,0x0300,0x0300,0x0180 };
for(i=0;i<16;i++) {
j=jj=15;
while(UpNum[i]!=0) {
up[i][j]=UpNum[i]%2; j--;
UpNum[i]/=2; }
while(DownNum[i]!=0) {
down[i][jj--]=DownNum[i]%2; DownNum[i]/=2; }
for(k=j;k>=0;k--) up[i][k]=0;
for(k=jj;k>=0;k--) down[i][k]=0;
for(k=0;k<16;k++)/*四种组合方式*/ {
if(up[i][k]==0&&down[i][k]==0) mouse_draw[i][k]=1;
else if(up[i][k]==0&&down[i][k]==1) mouse_draw[i][k]=2;
else if(up[i][k]==1&&down[i][k]==0) mouse_draw[i][k]=3; else
mouse_draw[i][k]=4; } }
mouse_draw[1][2]=4;/*特殊点*/ }
void Init(void);/*图形驱动*/
void MouseOn(int,int);/*鼠标光标显示*/ void MouseOff(void);/*鼠标光标隐藏*/
void MouseSetXY(int,int);/*设置当前位置*/ int LeftPress(void);/*左键按下*/
int RightPress(void);/*鼠标右键按下*/ int MiddlePress();
void MouseGetXY(void);/*得到当前位置*/ int MouseStatus();
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();
MouseMath();
//MouseOn(MouseX,MouseY); Control(); Close(); }
void Init(void)/*图形开始*/ {
int gd=DETECT,gm;
registerbgidriver(EGAVGA_driver); initgraph(&gd,&gm,\}
void Close(void)/*图形关闭*/ {
closegraph(); }
/*鼠标光标显示*/
void MouseOn(int x,int y) {
int i,j; int color;
for(i=0;i<16;i++)/*画鼠标*/
{
for(j=0;j<16;j++) {
pixel_save[i][j]=getpixel(x+j,y+i);/*保存原来的颜色*/ if(mouse_draw[i][j]==1) putpixel(x+j,y+i,0);
else if(mouse_draw[i][j]==2) putpixel(x+j,y+i,15); } } }
/*隐藏鼠标*/
void MouseOff() {
int i,j,x,y,color; x=MouseX; y=MouseY;
for(i=0;i<16;i++)/*原位置异或消去*/ for(j=0;j<16;j++) {
if(mouse_draw[i][j]==3||mouse_draw[i][j]==4) continue;
color=getpixel(x+j,y+i);
putpixel(x+j,y+i,color^color);
putpixel(x+j,y+i,pixel_save[i][j]); } }
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); }
/*是否按下中键
返回值同上 */ int MiddlePress() {
_AX=0x03;
geninterrupt(0x33); return(_BX&4); }
void MouseGetXY(void)/*得到当前位置*/ {
_AX=0x03;
geninterrupt(0x33); MouseX=_CX; MouseY=_DX; }
/*鼠标按键情况,返回0表示只移动,返回1表示左右键同时按下,2表示只按了左键,3表示只按了右键*/
int MouseStatus() {
int x,y; int status; int press=0;
int i,j,color;
status=0;/*默认鼠标没有移动*/
x=MouseX; y=MouseY;
while(x==MouseX&&y==MouseY&&status==0&&press==0) {
if(LeftPress()&&RightPress()) press=1;
else if(LeftPress()) press=2;
else if(RightPress()) press=3; MouseGetXY();
if(MouseX!=x||MouseY!=y) status=1; }