Win-Tc(C语言)小游戏编程实例

Win-Tc (C语言) 小游戏编程实例

扫雷游戏的游戏界面采用3D窗体显示,用鼠标操作实现整个游戏过程。

图1、3D窗体扫雷游戏界面 图2、游戏中打开非雷方块

游戏规则

游戏开始时,系统会在布雷区小方块中随机设置游戏级别中规则的雷体个数。布好雷后系统会在非雷方块中填上表示其周围8个方块中有多少雷体的数字,(如图2所示)。玩家用鼠标左键点开布雷区方块后开始计时,玩家可根据非雷方块中数字正确判断打开所有非雷方块后,游戏胜利结束,系统会自动打开所有雷方块,并显示胜利会话框。在游戏过程中,如果提前打开雷方块则立即失败,游戏结束(如图3所示)。游戏计时为999秒,如果时间到了系统会自动结束游戏。

图3、提前打开雷方块 图4、打开Game按钮子菜单

Game按钮单击事件

鼠标左键单击Game按钮会打开如图4所示的子程序选择会话框,玩家可选择5种功能中的某一项来实现某种功能。5种功能分别如下所示:

BEGIN按钮―――――――开局(重新开始)

PRIMARY按钮―――――――初级(级别)

INTERMEDIATE―――――――中级(级别)

HIGH按钮――――――――――高级(级别)

EXIT――――――――――――-返回操作系统(退出应用程序)

程序基本流程如下:

开始――调用鼠标程序(如果调用失败退出)――创建并显示窗体――布雷

(初始化设

置)――游戏(玩家操作(打开非雷方块、提前打开雷方块游戏结束、Game事件(重新开始))――判断胜利(胜利(显示胜利会话框)、Game事件(重新开始))――Close按钮事件(退出应用程序返回操作系统)

扫雷游戏程序源码清单如下:

#include

#include

#include

#include

#define PRIMARY 1 /*初级标识符*/

#define PRIMARYCOLUMN 9 /*初级布雷区列数*/

#define PRIMARYROW 9 /*初级布雷区行数*/

#define PRIMARYMINE 10 /*初级布雷区雷的数目*/

#define INTERMEDIATE 2 /*中级标识符*/

#define INTERMEDIATECOLUMN 16 /*中级布雷区列数*/

#define INTERMEDIATEROW 16 /*中级布雷区行数*/

#define INTERMEDIATEMINE 40 /*中级布雷区雷的数目*/

#define HIGH 3 /*高级标识符*/

#define HIGHCOLUMN 30 /*高级布雷区列数*/

#define HIGHROW 16 /*高级布雷区行数*/

#define HIGHMINE 99 /*高级布雷区雷的数目*/

#define GAMEOVER 1 /*游戏结束标识符*/

/*定义鼠标数据类型*/

typedef struct MOUSE

{

int mx; /*鼠标x坐标值*/

int my; /*鼠标y坐标值*/

int mkey;/*鼠标按钮状态*/

char fillcolor[16][16];/*鼠标覆盖下的颜色*/

}Mouseh;

/*定义按钮数据类型*/

typedef struct BUTTON

{

int left;

int top;

int right;

int down;

char *caption;/*按钮标题标识*/

char table[100];/*按钮目录标题标识*/

int fillcolor;/*按钮面颜色标识*/

int fontcolor;/*按钮面字体颜色标识*/

}BUTTON;

/*定义窗口数据类型*/

typedef struct WINDOW

{

int left;

int top;

int width;

int height;

int backcolor;/*窗体背景颜色*/

char *caption;/*窗体标题*/

BUTTON close;/*窗体关闭按钮*/

BUTTON game;/*游戏按钮*/

BUTTON help;/*帮助按钮*/

BUTTON settime;/*显示时间按钮*/

BUTTON minenumber;/*显示游戏区间雷体数目按钮*/

}Hwnd;

/*定义布雷区数据类型*/

typedef struct MINEFIELD

{

int left;

int top;

int right;

int down; int status; /*是否有雷的标识状态符*/ int openst; /*雷区是否打开的标识符*/ int minenumbers;/*雷区周围有多少雷的标识符*/

}MINEFIELD;

/*-=-=-=-=-=-=-= 全局变量 -=-=-=-=-=-=-=-=-*/

/*鼠标屏幕绘码*/

char MouseMask[]={0x00,0x00,0x40,0x00,0x60,0x00,0x70,0x00,

0x78,0x00,0x7c,0x00,0x7e,0x00,0x7f,0x00,

0x7f,0x80,0x7f,0xc0,0x6c,0x00,0x46,0x00,

0x06,0x00,0x03,0x00,0x01,0x80,0x00,0x00

};

/*鼠标屏幕绘码边框码*/

char MouseMaskE[]={0xc0,0x00,0xa0,0x00,0x90,0x00,0x88,0x00,

0x84,0x00,0x82,0x00,0x81,0x00,0x80,0x80,

0x80,0x40,0x80,0x20,0x93,0xf0,0xa9,0x00,

0xc9,0x00,0x04,0x80,0x02,0x40,0x01,0xc0

};

int newx=0,newy=0;/*定义鼠标(x,y)坐标状态变量*/

MINEFIELD Mine[HIGHROW][HIGHCOLUMN];/*布雷区域大小数组*/

Hwnd hWnd;/*窗口句柄*/

Mouseh *hw;/*鼠标句柄*/

int row;/*雷区行标识*/

int column;/*雷区列标识*/

int mine;/*雷区雷数标识*/

int end;/*游戏结束标识*/

int begin;/*游戏开始标识*/

int mtime;/*游戏用时标识*/

int active;/*当前活动窗体标识*/

/*Game按钮子菜单项目录*/

static char *MENU[5]={

void SelectLoop(int r,int c);

/*======================= 鼠标模块源码 ===========================*/ /*鼠标初始化函数*/

int MouseInit(int Xmin,int Xmax,int Ymin,int Ymax)

{

int retcode;

union REGS regs;

regs.x.ax=0;

int86(51,&regs,&regs);

retcode=regs.x.ax;

if(retcode==0)

return 0; regs.x.ax=7; regs.x.cx=Xmin; regs.x.dx=Xmax;

int86(51,&regs,&regs);

regs.x.ax=8;

regs.x.cx=Ymin;

regs.x.dx=Ymax;

int86(51,&regs,&regs);

return retcode;

}

/*显示鼠标*/

void ShowMouse(Mouseh *hw,int mousecolor)

{

int i,j,k;

for(i=0;i

for(j=0;j

hw->fillcolor[i][j]=getpixel(hw->mx+j,hw->my+i);

for(j=0;j

for(i=0;i

for(k=0;k

if(MouseMask[j*2+i]&(0x80>>k))

putpixel(hw->mx+i*8+k,hw->my+j,mousecolor);

for(j=0;j>k))

putpixel(hw->mx+i*8+k,hw->my+j,0);

}

/*鼠标屏幕恢复*/

void HideMouse(Mouseh *hw)

{

int i,j;

for(i=0;i

for(j=0;j

putpixel(hw->mx+j,hw->my+i,hw->fillcolor[i][j]);

}

/*按目录设置按钮*/

void SetButton1(BUTTON bt)

{

setfillstyle(1,bt.fillcolor);

bar(bt.left,bt.top,bt.right,bt.down);

setcolor(bt.fontcolor);

outtextxy(bt.left+6,bt.top+7,bt.table);

}

/*读取鼠标位置和按钮状态*/

void MouseRead(Mouseh *hd)

{

union REGS r1;

int dx,dy,ky;

struct time t,t1;

gettime(&t1);

do{

gettime(&t);

if(t1.ti_sec>t.ti_sec)

t1.ti_sec=t.ti_sec;

if(begin)

{

if(t.ti_sec-t1.ti_sec==1)

{

mtime+=1;

sprintf(hWnd.settime.table,

SetButton1(hWnd.settime);

t1.ti_sec=t.ti_sec;

if(mtime==999)

{

begin=0;

end=GAMEOVER;

break;

}

}

}

r1.x.ax=3;

int86(51,&r1,&r1);

dx=r1.x.cx;

dy=r1.x.dx;

hd->mkey=r1.x.bx;

if(hd->mkey)

break;

}while(dx==newx&&dy==newy);

HideMouse(hd);

hd->mx=r1.x.cx;

hd->my=r1.x.dx;

newx=hd->mx;

newy=hd->my;

}

/*======================= 绘制框体

==========================*/

/*绘制阴影在左边的框体*/

void DrawBox1(int left,int top,int right,int down,int fillcolor)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(15);

line(right,top,right,down);

line(left,down,right,down);

setcolor(8);

line(left,top,left,down);

line(left,top,right,top);

}

/*绘制阴影在右边的框体*/

void DrawBox2(int left,int top,int right,int down,int fillcolor)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(15);

line(left,top,left,down);

line(left,top,right,top);

模块源码

setcolor(8);

line(right,top,right,down);

line(left,down,right,down);

}

/*绘制雷区3D框体*/

void DrawBox(int left,int top,int right,int down,int fillcolor)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(fillcolor);

rectangle(left,top,right,down);

setcolor(15);

line(left+1,top+1,left+1,down-1);

line(left+1,top+1,right-1,top+1);

setcolor(8);

line(right-1,top+1,right-1,down-1);

line(left+1,down-1,right-1,down-1);

}

/*===================== 按钮模块源码 ===================*/ /*按标题设置按钮*/

void SetButton(BUTTON bt)

{

setfillstyle(1,bt.fillcolor);

bar(bt.left,bt.top,bt.right,bt.down);

setcolor(bt.fontcolor);

outtextxy(bt.left+3,bt.top+3,bt.caption);

}

/*判断鼠标是否在按钮上*/

int OnButton(BUTTON bt)

{

int but=0;

if(hw->mx>bt.left&&hw->mxmy>bt.top&&hw->my

return but;

}

/*高亮按钮*/

void LightButton(BUTTON bt)

{

DrawBox2(bt.left,bt.top,bt.right,bt.down,bt.fillcolor);

setcolor(bt.fontcolor);

outtextxy(bt.left+3,bt.top+3,bt.caption);

while(OnButton(bt))

{

ShowMouse(hw,15);

MouseRead(hw);

if(hw->mkey)

break;

}

SetButton(bt);

}

/*==================== 绘制脸部源码 =====================*/ /*绘制笑脸*/

void DrawFace1(int left,int top,int right,int down)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

DrawBox2(left,top,right,down,7);

setcolor(0);

circle(rx,ry,8);

setfillstyle(1,14);

floodfill(rx,ry,0);

line(rx-4,ry+3,rx-2,ry+5);

line(rx+4,ry+3,rx+2,ry+5);

line(rx-2,ry+5,rx+2,ry+5);

setfillstyle(1,0);

bar(rx-3,ry-2,rx-2,ry-1);

bar(rx+3,ry-2,rx+2,ry-1);

}

/*绘制苦瓜脸*/

void DrawFace3(int left,int top,int right,int down)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

DrawBox2(left,top,right,down,7);

setcolor(0);

circle(rx,ry,8);

setfillstyle(1,14);

floodfill(rx,ry,0);

line(rx-4,ry-4,rx-2,ry-2);

line(rx-2,ry-4,rx-4,ry-2);

line(rx+4,ry-4,rx+2,ry-2);

line(rx+2,ry-4,rx+4,ry-2);

line(rx-4,ry+4,rx-2,ry+2);

line(rx+4,ry+4,rx+2,ry+2);

line(rx-2,ry+2,rx+2,ry+2);

}

/*根据表情状态绘制动画表情脸谱*/

void DrawFace2(int left,int top,int right,int down,int status)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

DrawBox2(left,top,right,down,7);

setcolor(0);

circle(rx,ry,8);

setfillstyle(1,14);

floodfill(rx,ry,0);

circle(rx,ry+3,2);

setfillstyle(1,0);

bar(rx-4,ry-4,rx-2,ry-2);

bar(rx+4,ry-4,rx+2,ry-2);

delay(50000);

if(!status)

DrawFace1(left,top,right,down);

if(status)

DrawFace3(left,top,right,down);

}

/*==================== 窗体源码 =======================*/ /*按级别创建窗体*/

Hwnd CreateWindow(int rank)

{

int i,j;

Hwnd hd;

hd.top=20;

if(rank==PRIMARY)

{

hd.width=165;

hd.left=(getmaxx()-hd.width)/2;

hd.height=245;

row=PRIMARYROW;

column=PRIMARYCOLUMN;

mine=PRIMARYMINE;

active=PRIMARY;

}

if(rank==INTERMEDIATE)

{

hd.width=284; hd.left=(getmaxx()-hd.width)/2; hd.height=364; row=INTERMEDIATEROW;

column=INTERMEDIATECOLUMN; mine=INTERMEDIATEMINE; active=INTERMEDIATE;

}

if(rank==HIGH)

{

hd.width=522;

hd.left=(getmaxx()-hd.width)/2; hd.height=364;

row=HIGHROW;

column=HIGHCOLUMN;

mine=HIGHMINE;

active=HIGH;

}

hd.backcolor=7;

hd.caption=

hd.close.fontcolor=15;

hd.close.caption=

hd.game.left=hd.left+3;

hd.game.top=hd.top+25;

hd.game.right=hd.game.left+36; hd.game.down=hd.game.top+12; hd.game.fillcolor=7;

hd.game.fontcolor=0;

hd.game.caption=

hd.help.left=hd.left+53;

hd.help.top=hd.top+25;

hd.help.right=hd.help.left+36; hd.help.down=hd.help.top+12; hd.help.fillcolor=7;

hd.help.fontcolor=0;

hd.help.caption=

hd.settime.left=hd.left+hd.width-40;

hd.settime.top=hd.top+55;

hd.settime.right=hd.settime.left+30;

hd.settime.down=hd.settime.top+20;

hd.settime.fillcolor=8;

hd.settime.fontcolor=12;

sprintf(hd.settime.table,

hd.minenumber.left=hd.left+10;

hd.minenumber.top=hd.top+55;

hd.minenumber.right=hd.minenumber.left+30;

hd.minenumber.down=hd.minenumber.top+20;

hd.minenumber.fillcolor=8;

hd.minenumber.fontcolor=12;

sprintf(hd.minenumber.table,

for(i=0;i

for(j=0;j

{

Mine[i][j].left=hd.left+6+j*17;

Mine[i][j].top=hd.top+86+i*17;

Mine[i][j].right=Mine[i][j].left+17;

Mine[i][j].down=Mine[i][j].top+17;

}

return hd;

}

/*显示窗体*/

void ShowWindow(Hwnd hd)

{

int i,j,left,top,right,down;

cleardevice();

left=hd.left;

top=hd.top;

right=hd.left+hd.width;

down=hd.top+hd.height;

setfillstyle(1,1);

bar(left,top,right,top+20);

setfillstyle(1,7);

bar(left,top+20,right,down);

setcolor(7);

line(left,top+17,right,top+17);

setcolor(9);

line(left,top+16,right,top+16);

line(left,top+18,right,top+18);

rectangle(left-1,top-1,right+1,down+1);

setcolor(15);

outtextxy(left+5,top+5,hd.caption);

SetButton(hd.close);

SetButton(hd.game);

SetButton(hd.help);

DrawBox2(left+2,top+47,right-2,down-2,7);

DrawBox1(left+5,top+50,right-5,top+80,7);

DrawBox1(left+5,top+85,right-5,down-5,7);

SetButton1(hd.minenumber);

SetButton1(hd.settime);

DrawFace1(hd.left+hd.width/2-10,top+55,hd.left+hd.width/2+10,top+75);

for(i=0;i

for(j=0;j

DrawBox(Mine[i][j].left,Mine[i][j].top,Mine[i][j].right,Mine[i][j].down,7);

}

/*===================== 雷区操作源码 ======================*/

/*绘制雷体*/

void DrawMine(int left,int top,int right,int down)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

setcolor(0);

circle(rx,ry,4);

setfillstyle(1,0);

floodfill(rx,ry,0);

setfillstyle(1,15);

bar(rx-2,ry-2,rx-1,ry-1);

}

/*打开雷区域*/

void OpenMine(int left,int top,int right,int down,int fillcolor,int status)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(7);

rectangle(left,top,right,down);

if(status)

DrawMine(left,top,right,down);

}

/*取得无雷区周围雷体的数目*/

void GetMineNumber()

{

int i,j,str,stc,numbers;

for(i=0;i

for(j=0;j

{

numbers=0;

if(!Mine[i][j].status)

{

str=i;

stc=j;

if(str>0)

{

if(Mine[str-1][j].status)

numbers++;

if(stc>0)

{

if(Mine[str-1][stc-1].status)

numbers++;

}

if(stc

{

if(Mine[str-1][stc+1].status)

numbers++;

}

}

if(str

{

if(Mine[str+1][j].status)

numbers++;

if(stc>0)

{

if(Mine[str+1][stc-1].status)

numbers++;

}

if(stc

{

if(Mine[str+1][stc+1].status)

numbers++;

}

}

if(stc>0)

{

if(Mine[str][stc-1].status)

numbers++;

}

if(stc

{

if(Mine[str][stc+1].status)

numbers++;

}

}

Mine[i][j].minenumbers=numbers;

}

}

/*随机安置雷体*/

void SetMine()

{

int i,j,k,str,stc;

srand((unsigned) time(NULL));

for(i=0;i

for(j=0;j

{

Mine[i][j].status=0;

Mine[i][j].openst=0;

}

for(i=0;i

{

str=rand()%row;

stc=rand()%column;

if(!Mine[str][stc].status)

Mine[str][stc].status=1;

else

{

for(j=0;j

{

if(!Mine[str][j].status)

{

Mine[str][j].status=1;

break;

}

else

{

for(k=0;k

{

if(!Mine[k][stc].status)

{

Mine[k][stc].status=1;

break;

}

}

break;

}

}

}

}

GetMineNumber();

}

/*绘制无雷区*/

void DrawNotM(int r,int c)

{

char cn[10];

OpenMine(Mine[r][c].left,Mine[r][c].top,Mine[r][c].right-1,Mine[r][c].down-1,8,Mine[r][c].status);

Mine[r][c].openst=1;

if(Mine[r][c].minenumbers)

{

sprintf(cn,

if(Mine[r][c].minenumbers

setcolor(Mine[r][c].minenumbers);

else

setcolor(5);

outtextxy(Mine[r][c].left+5,Mine[r][c].top+5,cn);

}

}

/*判断雷方块属性*/

int ReturnSelect(int r,int c)

{

int Select=0;

if(Mine[r][c].openst||Mine[r][c].status)

Select=1;

else

{

DrawNotM(r,c);

if(Mine[r][c].minenumbers)

Select=1;

}

return Select;

}

/*打开无雷区片区域*/

void Select(int r,int c)

{

int t1,t2;

if(Mine[r][c].minenumbers)

DrawNotM(r,c);

else

{

DrawNotM(r,c);

t1=r;

while(t1>0)

{

t1-=1;

if(ReturnSelect(t1,c))

break;

else

SelectLoop(t1,c);

}

t1=r;

while(t1

{

t1+=1;

if(ReturnSelect(t1,c))

break;

else

SelectLoop(t1,c);

}

SelectLoop(r,c);

}

}

/*间接递归Select()函数*/

void SelectLoop(int r,int c)

{

int tc;

tc=c;

while(tc>0)

{

tc-=1;

if(ReturnSelect(r,tc))

break;

else

Select(r,tc);

}

tc=c;

while(tc

{

tc+=1;

if(ReturnSelect(r,tc))

break;

else

Select(r,tc);

}

}

/*打开有雷区域*/

void DisplayMine()

{

int i,j;

for(i=0;i

for(j=0;j

{

if(Mine[i][j].status&&!Mine[i][j].openst)

{

OpenMine(Mine[i][j].left,Mine[i][j].top,Mine[i][j].right-1,Mine[i][j].down-1,8,Mine[i][j].status);

Mine[i][j].openst=1;

}

}

}

/*雷区单击事件*/

void MineClick(Mouseh *hd)

{

int i,j;

for(i=0;i

{

for(j=0;j

{

if(hd->mx>Mine[i][j].left&&hd->mxmy>Mine[i][j].top&&hd->my

{

begin=1;

if(Mine[i][j].status)

end=GAMEOVER;

if(!Mine[i][j].openst)

{

DrawFace2(hWnd.left+hWnd.width/2-10,hWnd.top+55,hWnd.left+hWnd.width/2+10,hWnd.top+75,Mine[i][j].status);

if(Mine[i][j].status)

{

OpenMine(Mine[i][j].left,Mine[i][j].top,Mine[i][j].right-1,Mine[i][j].down-1,12,Mine[i][j].status);

Mine[i][j].openst=1;

}

else

Select(i,j);

}

}

if(end)

break;

}

if(end)

break;

} if(end) { begin=0;

DisplayMine();

}

}

/*判断鼠标是否在布雷区域内*/

int OnMinefield(Mouseh *mt)

{

int rt=0;

if(mt->mx>Mine[0][0].left&&mt->mxmy>Mine[0][0].top&&mt->my

rt=1;

return rt;

}

/*Game按钮单击事件*/

void GameClick(BUTTON bt,char *Meun[])

{

int i,size,tk=0;

BUTTON mb[5];

size=imagesize(bt.left,bt.down+1,bt.left+110,bt.down+78); buffer=malloc(size);

getimage(bt.left,bt.down+1,bt.left+110,bt.down+78,buffer); DrawBox2(bt.left,bt.down+1,bt.left+110,bt.down+78,7); setcolor(0);

for(i=0;i

{

outtextxy(bt.left+5,bt.down+8+i*14,Meun[i]);

mb[i].left=bt.left+3;

mb[i].top=bt.down+6+i*14;

mb[i].right=bt.left+107;

mb[i].down=mb[i].top+12;

mb[i].caption=Meun[i];

mb[i].fillcolor=7;

mb[i].fontcolor=0;

}

while(!tk)

{

ShowMouse(hw,15);

MouseRead(hw);

if(hw->mkey)

{

if(OnButton(mb[0]))

hWnd=CreateWindow(active),tk=1;

if(OnButton(mb[1]))

hWnd=CreateWindow(PRIMARY),tk=1;

if(OnButton(mb[2]))

hWnd=CreateWindow(INTERMEDIATE),tk=1; if(OnButton(mb[3]))

hWnd=CreateWindow(HIGH),tk=1;

if(OnButton(mb[4]))

closegraph(),exit(0);

if(hw->mx>bt.left+110||hw->my>bt.down+78) tk=2;

}

for(i=0;i

{

if(OnButton(mb[i]))

LightButton(mb[i]);

}

}

putimage(bt.left,bt.down+1,buffer,COPY_PUT);

if(tk==1) { ShowWindow(hWnd); SetMine();

end=0;

mtime=0;

}

}

/*判断是否胜利*/

void AllOpen()

{

int i,j,size,qt=0,ok=0;

void *buffer;

char mt[100];

for(i=0;i

{

for(j=0;j

{

if(!Mine[i][j].openst&&Mine[i][j].status) ok=1;

if(!Mine[i][j].openst&&!Mine[i][j].status) {

ok=0;

qt=1;

break;

}

}

if(qt)

break;

}

if(ok)

{

DisplayMine();

end=GAMEOVER;

begin=0;

for(i=0;i

{

delay(50000);

}

size=imagesize(200,150,440,330); buffer=malloc(size);

getimage(200,150,440,330,buffer);

DrawBox2(200,150,440,330,7);

setcolor(6);

outtextxy(280,230,

outtextxy(280,250,

sprintf(mt,

outtextxy(330,250,mt);

setcolor(10);

outtextxy(240,270,

DrawFace2(310,180,330,200,0);

getch();

putimage(200,150,buffer,COPY_PUT);

free(buffer);

}

}

/*===================== 游戏入口 ======================*/ void Process()

{

if(MouseInit(0,639,0,479)==0)

exit(1);

hw=(Mouseh *)malloc(sizeof(Mouseh));

hw->mx=320;

hw->my=240; hWnd=CreateWindow(PRIMARY); ShowWindow(hWnd); SetMine();

end=0;

begin=0;

mtime=0;

for(;;)

{

ShowMouse(hw,15);

MouseRead(hw);

AllOpen();

if(hw->mkey==1)

{

if(OnMinefield(hw))

MineClick(hw);

if(OnButton(hWnd.close))

break;

if(OnButton(hWnd.game))

GameClick(hWnd.game,MENU);

}

if(OnButton(hWnd.close))

LightButton(hWnd.close);

if(OnButton(hWnd.game)) LightButton(hWnd.game); if(OnButton(hWnd.help)) LightButton(hWnd.help); }

}

main()

{

int grd,grm;

grd=DETECT;

registerbgidriver(EGAVGA_driver); initgraph(&grd,&grm,

Process();

closegraph();

}

Win-Tc (C语言) 小游戏编程实例

扫雷游戏的游戏界面采用3D窗体显示,用鼠标操作实现整个游戏过程。

图1、3D窗体扫雷游戏界面 图2、游戏中打开非雷方块

游戏规则

游戏开始时,系统会在布雷区小方块中随机设置游戏级别中规则的雷体个数。布好雷后系统会在非雷方块中填上表示其周围8个方块中有多少雷体的数字,(如图2所示)。玩家用鼠标左键点开布雷区方块后开始计时,玩家可根据非雷方块中数字正确判断打开所有非雷方块后,游戏胜利结束,系统会自动打开所有雷方块,并显示胜利会话框。在游戏过程中,如果提前打开雷方块则立即失败,游戏结束(如图3所示)。游戏计时为999秒,如果时间到了系统会自动结束游戏。

图3、提前打开雷方块 图4、打开Game按钮子菜单

Game按钮单击事件

鼠标左键单击Game按钮会打开如图4所示的子程序选择会话框,玩家可选择5种功能中的某一项来实现某种功能。5种功能分别如下所示:

BEGIN按钮―――――――开局(重新开始)

PRIMARY按钮―――――――初级(级别)

INTERMEDIATE―――――――中级(级别)

HIGH按钮――――――――――高级(级别)

EXIT――――――――――――-返回操作系统(退出应用程序)

程序基本流程如下:

开始――调用鼠标程序(如果调用失败退出)――创建并显示窗体――布雷

(初始化设

置)――游戏(玩家操作(打开非雷方块、提前打开雷方块游戏结束、Game事件(重新开始))――判断胜利(胜利(显示胜利会话框)、Game事件(重新开始))――Close按钮事件(退出应用程序返回操作系统)

扫雷游戏程序源码清单如下:

#include

#include

#include

#include

#define PRIMARY 1 /*初级标识符*/

#define PRIMARYCOLUMN 9 /*初级布雷区列数*/

#define PRIMARYROW 9 /*初级布雷区行数*/

#define PRIMARYMINE 10 /*初级布雷区雷的数目*/

#define INTERMEDIATE 2 /*中级标识符*/

#define INTERMEDIATECOLUMN 16 /*中级布雷区列数*/

#define INTERMEDIATEROW 16 /*中级布雷区行数*/

#define INTERMEDIATEMINE 40 /*中级布雷区雷的数目*/

#define HIGH 3 /*高级标识符*/

#define HIGHCOLUMN 30 /*高级布雷区列数*/

#define HIGHROW 16 /*高级布雷区行数*/

#define HIGHMINE 99 /*高级布雷区雷的数目*/

#define GAMEOVER 1 /*游戏结束标识符*/

/*定义鼠标数据类型*/

typedef struct MOUSE

{

int mx; /*鼠标x坐标值*/

int my; /*鼠标y坐标值*/

int mkey;/*鼠标按钮状态*/

char fillcolor[16][16];/*鼠标覆盖下的颜色*/

}Mouseh;

/*定义按钮数据类型*/

typedef struct BUTTON

{

int left;

int top;

int right;

int down;

char *caption;/*按钮标题标识*/

char table[100];/*按钮目录标题标识*/

int fillcolor;/*按钮面颜色标识*/

int fontcolor;/*按钮面字体颜色标识*/

}BUTTON;

/*定义窗口数据类型*/

typedef struct WINDOW

{

int left;

int top;

int width;

int height;

int backcolor;/*窗体背景颜色*/

char *caption;/*窗体标题*/

BUTTON close;/*窗体关闭按钮*/

BUTTON game;/*游戏按钮*/

BUTTON help;/*帮助按钮*/

BUTTON settime;/*显示时间按钮*/

BUTTON minenumber;/*显示游戏区间雷体数目按钮*/

}Hwnd;

/*定义布雷区数据类型*/

typedef struct MINEFIELD

{

int left;

int top;

int right;

int down; int status; /*是否有雷的标识状态符*/ int openst; /*雷区是否打开的标识符*/ int minenumbers;/*雷区周围有多少雷的标识符*/

}MINEFIELD;

/*-=-=-=-=-=-=-= 全局变量 -=-=-=-=-=-=-=-=-*/

/*鼠标屏幕绘码*/

char MouseMask[]={0x00,0x00,0x40,0x00,0x60,0x00,0x70,0x00,

0x78,0x00,0x7c,0x00,0x7e,0x00,0x7f,0x00,

0x7f,0x80,0x7f,0xc0,0x6c,0x00,0x46,0x00,

0x06,0x00,0x03,0x00,0x01,0x80,0x00,0x00

};

/*鼠标屏幕绘码边框码*/

char MouseMaskE[]={0xc0,0x00,0xa0,0x00,0x90,0x00,0x88,0x00,

0x84,0x00,0x82,0x00,0x81,0x00,0x80,0x80,

0x80,0x40,0x80,0x20,0x93,0xf0,0xa9,0x00,

0xc9,0x00,0x04,0x80,0x02,0x40,0x01,0xc0

};

int newx=0,newy=0;/*定义鼠标(x,y)坐标状态变量*/

MINEFIELD Mine[HIGHROW][HIGHCOLUMN];/*布雷区域大小数组*/

Hwnd hWnd;/*窗口句柄*/

Mouseh *hw;/*鼠标句柄*/

int row;/*雷区行标识*/

int column;/*雷区列标识*/

int mine;/*雷区雷数标识*/

int end;/*游戏结束标识*/

int begin;/*游戏开始标识*/

int mtime;/*游戏用时标识*/

int active;/*当前活动窗体标识*/

/*Game按钮子菜单项目录*/

static char *MENU[5]={

void SelectLoop(int r,int c);

/*======================= 鼠标模块源码 ===========================*/ /*鼠标初始化函数*/

int MouseInit(int Xmin,int Xmax,int Ymin,int Ymax)

{

int retcode;

union REGS regs;

regs.x.ax=0;

int86(51,&regs,&regs);

retcode=regs.x.ax;

if(retcode==0)

return 0; regs.x.ax=7; regs.x.cx=Xmin; regs.x.dx=Xmax;

int86(51,&regs,&regs);

regs.x.ax=8;

regs.x.cx=Ymin;

regs.x.dx=Ymax;

int86(51,&regs,&regs);

return retcode;

}

/*显示鼠标*/

void ShowMouse(Mouseh *hw,int mousecolor)

{

int i,j,k;

for(i=0;i

for(j=0;j

hw->fillcolor[i][j]=getpixel(hw->mx+j,hw->my+i);

for(j=0;j

for(i=0;i

for(k=0;k

if(MouseMask[j*2+i]&(0x80>>k))

putpixel(hw->mx+i*8+k,hw->my+j,mousecolor);

for(j=0;j>k))

putpixel(hw->mx+i*8+k,hw->my+j,0);

}

/*鼠标屏幕恢复*/

void HideMouse(Mouseh *hw)

{

int i,j;

for(i=0;i

for(j=0;j

putpixel(hw->mx+j,hw->my+i,hw->fillcolor[i][j]);

}

/*按目录设置按钮*/

void SetButton1(BUTTON bt)

{

setfillstyle(1,bt.fillcolor);

bar(bt.left,bt.top,bt.right,bt.down);

setcolor(bt.fontcolor);

outtextxy(bt.left+6,bt.top+7,bt.table);

}

/*读取鼠标位置和按钮状态*/

void MouseRead(Mouseh *hd)

{

union REGS r1;

int dx,dy,ky;

struct time t,t1;

gettime(&t1);

do{

gettime(&t);

if(t1.ti_sec>t.ti_sec)

t1.ti_sec=t.ti_sec;

if(begin)

{

if(t.ti_sec-t1.ti_sec==1)

{

mtime+=1;

sprintf(hWnd.settime.table,

SetButton1(hWnd.settime);

t1.ti_sec=t.ti_sec;

if(mtime==999)

{

begin=0;

end=GAMEOVER;

break;

}

}

}

r1.x.ax=3;

int86(51,&r1,&r1);

dx=r1.x.cx;

dy=r1.x.dx;

hd->mkey=r1.x.bx;

if(hd->mkey)

break;

}while(dx==newx&&dy==newy);

HideMouse(hd);

hd->mx=r1.x.cx;

hd->my=r1.x.dx;

newx=hd->mx;

newy=hd->my;

}

/*======================= 绘制框体

==========================*/

/*绘制阴影在左边的框体*/

void DrawBox1(int left,int top,int right,int down,int fillcolor)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(15);

line(right,top,right,down);

line(left,down,right,down);

setcolor(8);

line(left,top,left,down);

line(left,top,right,top);

}

/*绘制阴影在右边的框体*/

void DrawBox2(int left,int top,int right,int down,int fillcolor)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(15);

line(left,top,left,down);

line(left,top,right,top);

模块源码

setcolor(8);

line(right,top,right,down);

line(left,down,right,down);

}

/*绘制雷区3D框体*/

void DrawBox(int left,int top,int right,int down,int fillcolor)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(fillcolor);

rectangle(left,top,right,down);

setcolor(15);

line(left+1,top+1,left+1,down-1);

line(left+1,top+1,right-1,top+1);

setcolor(8);

line(right-1,top+1,right-1,down-1);

line(left+1,down-1,right-1,down-1);

}

/*===================== 按钮模块源码 ===================*/ /*按标题设置按钮*/

void SetButton(BUTTON bt)

{

setfillstyle(1,bt.fillcolor);

bar(bt.left,bt.top,bt.right,bt.down);

setcolor(bt.fontcolor);

outtextxy(bt.left+3,bt.top+3,bt.caption);

}

/*判断鼠标是否在按钮上*/

int OnButton(BUTTON bt)

{

int but=0;

if(hw->mx>bt.left&&hw->mxmy>bt.top&&hw->my

return but;

}

/*高亮按钮*/

void LightButton(BUTTON bt)

{

DrawBox2(bt.left,bt.top,bt.right,bt.down,bt.fillcolor);

setcolor(bt.fontcolor);

outtextxy(bt.left+3,bt.top+3,bt.caption);

while(OnButton(bt))

{

ShowMouse(hw,15);

MouseRead(hw);

if(hw->mkey)

break;

}

SetButton(bt);

}

/*==================== 绘制脸部源码 =====================*/ /*绘制笑脸*/

void DrawFace1(int left,int top,int right,int down)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

DrawBox2(left,top,right,down,7);

setcolor(0);

circle(rx,ry,8);

setfillstyle(1,14);

floodfill(rx,ry,0);

line(rx-4,ry+3,rx-2,ry+5);

line(rx+4,ry+3,rx+2,ry+5);

line(rx-2,ry+5,rx+2,ry+5);

setfillstyle(1,0);

bar(rx-3,ry-2,rx-2,ry-1);

bar(rx+3,ry-2,rx+2,ry-1);

}

/*绘制苦瓜脸*/

void DrawFace3(int left,int top,int right,int down)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

DrawBox2(left,top,right,down,7);

setcolor(0);

circle(rx,ry,8);

setfillstyle(1,14);

floodfill(rx,ry,0);

line(rx-4,ry-4,rx-2,ry-2);

line(rx-2,ry-4,rx-4,ry-2);

line(rx+4,ry-4,rx+2,ry-2);

line(rx+2,ry-4,rx+4,ry-2);

line(rx-4,ry+4,rx-2,ry+2);

line(rx+4,ry+4,rx+2,ry+2);

line(rx-2,ry+2,rx+2,ry+2);

}

/*根据表情状态绘制动画表情脸谱*/

void DrawFace2(int left,int top,int right,int down,int status)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

DrawBox2(left,top,right,down,7);

setcolor(0);

circle(rx,ry,8);

setfillstyle(1,14);

floodfill(rx,ry,0);

circle(rx,ry+3,2);

setfillstyle(1,0);

bar(rx-4,ry-4,rx-2,ry-2);

bar(rx+4,ry-4,rx+2,ry-2);

delay(50000);

if(!status)

DrawFace1(left,top,right,down);

if(status)

DrawFace3(left,top,right,down);

}

/*==================== 窗体源码 =======================*/ /*按级别创建窗体*/

Hwnd CreateWindow(int rank)

{

int i,j;

Hwnd hd;

hd.top=20;

if(rank==PRIMARY)

{

hd.width=165;

hd.left=(getmaxx()-hd.width)/2;

hd.height=245;

row=PRIMARYROW;

column=PRIMARYCOLUMN;

mine=PRIMARYMINE;

active=PRIMARY;

}

if(rank==INTERMEDIATE)

{

hd.width=284; hd.left=(getmaxx()-hd.width)/2; hd.height=364; row=INTERMEDIATEROW;

column=INTERMEDIATECOLUMN; mine=INTERMEDIATEMINE; active=INTERMEDIATE;

}

if(rank==HIGH)

{

hd.width=522;

hd.left=(getmaxx()-hd.width)/2; hd.height=364;

row=HIGHROW;

column=HIGHCOLUMN;

mine=HIGHMINE;

active=HIGH;

}

hd.backcolor=7;

hd.caption=

hd.close.fontcolor=15;

hd.close.caption=

hd.game.left=hd.left+3;

hd.game.top=hd.top+25;

hd.game.right=hd.game.left+36; hd.game.down=hd.game.top+12; hd.game.fillcolor=7;

hd.game.fontcolor=0;

hd.game.caption=

hd.help.left=hd.left+53;

hd.help.top=hd.top+25;

hd.help.right=hd.help.left+36; hd.help.down=hd.help.top+12; hd.help.fillcolor=7;

hd.help.fontcolor=0;

hd.help.caption=

hd.settime.left=hd.left+hd.width-40;

hd.settime.top=hd.top+55;

hd.settime.right=hd.settime.left+30;

hd.settime.down=hd.settime.top+20;

hd.settime.fillcolor=8;

hd.settime.fontcolor=12;

sprintf(hd.settime.table,

hd.minenumber.left=hd.left+10;

hd.minenumber.top=hd.top+55;

hd.minenumber.right=hd.minenumber.left+30;

hd.minenumber.down=hd.minenumber.top+20;

hd.minenumber.fillcolor=8;

hd.minenumber.fontcolor=12;

sprintf(hd.minenumber.table,

for(i=0;i

for(j=0;j

{

Mine[i][j].left=hd.left+6+j*17;

Mine[i][j].top=hd.top+86+i*17;

Mine[i][j].right=Mine[i][j].left+17;

Mine[i][j].down=Mine[i][j].top+17;

}

return hd;

}

/*显示窗体*/

void ShowWindow(Hwnd hd)

{

int i,j,left,top,right,down;

cleardevice();

left=hd.left;

top=hd.top;

right=hd.left+hd.width;

down=hd.top+hd.height;

setfillstyle(1,1);

bar(left,top,right,top+20);

setfillstyle(1,7);

bar(left,top+20,right,down);

setcolor(7);

line(left,top+17,right,top+17);

setcolor(9);

line(left,top+16,right,top+16);

line(left,top+18,right,top+18);

rectangle(left-1,top-1,right+1,down+1);

setcolor(15);

outtextxy(left+5,top+5,hd.caption);

SetButton(hd.close);

SetButton(hd.game);

SetButton(hd.help);

DrawBox2(left+2,top+47,right-2,down-2,7);

DrawBox1(left+5,top+50,right-5,top+80,7);

DrawBox1(left+5,top+85,right-5,down-5,7);

SetButton1(hd.minenumber);

SetButton1(hd.settime);

DrawFace1(hd.left+hd.width/2-10,top+55,hd.left+hd.width/2+10,top+75);

for(i=0;i

for(j=0;j

DrawBox(Mine[i][j].left,Mine[i][j].top,Mine[i][j].right,Mine[i][j].down,7);

}

/*===================== 雷区操作源码 ======================*/

/*绘制雷体*/

void DrawMine(int left,int top,int right,int down)

{

int rx,ry;

rx=left+(right-left)/2;

ry=top+(down-top)/2;

setcolor(0);

circle(rx,ry,4);

setfillstyle(1,0);

floodfill(rx,ry,0);

setfillstyle(1,15);

bar(rx-2,ry-2,rx-1,ry-1);

}

/*打开雷区域*/

void OpenMine(int left,int top,int right,int down,int fillcolor,int status)

{

setfillstyle(1,fillcolor);

bar(left,top,right,down);

setcolor(7);

rectangle(left,top,right,down);

if(status)

DrawMine(left,top,right,down);

}

/*取得无雷区周围雷体的数目*/

void GetMineNumber()

{

int i,j,str,stc,numbers;

for(i=0;i

for(j=0;j

{

numbers=0;

if(!Mine[i][j].status)

{

str=i;

stc=j;

if(str>0)

{

if(Mine[str-1][j].status)

numbers++;

if(stc>0)

{

if(Mine[str-1][stc-1].status)

numbers++;

}

if(stc

{

if(Mine[str-1][stc+1].status)

numbers++;

}

}

if(str

{

if(Mine[str+1][j].status)

numbers++;

if(stc>0)

{

if(Mine[str+1][stc-1].status)

numbers++;

}

if(stc

{

if(Mine[str+1][stc+1].status)

numbers++;

}

}

if(stc>0)

{

if(Mine[str][stc-1].status)

numbers++;

}

if(stc

{

if(Mine[str][stc+1].status)

numbers++;

}

}

Mine[i][j].minenumbers=numbers;

}

}

/*随机安置雷体*/

void SetMine()

{

int i,j,k,str,stc;

srand((unsigned) time(NULL));

for(i=0;i

for(j=0;j

{

Mine[i][j].status=0;

Mine[i][j].openst=0;

}

for(i=0;i

{

str=rand()%row;

stc=rand()%column;

if(!Mine[str][stc].status)

Mine[str][stc].status=1;

else

{

for(j=0;j

{

if(!Mine[str][j].status)

{

Mine[str][j].status=1;

break;

}

else

{

for(k=0;k

{

if(!Mine[k][stc].status)

{

Mine[k][stc].status=1;

break;

}

}

break;

}

}

}

}

GetMineNumber();

}

/*绘制无雷区*/

void DrawNotM(int r,int c)

{

char cn[10];

OpenMine(Mine[r][c].left,Mine[r][c].top,Mine[r][c].right-1,Mine[r][c].down-1,8,Mine[r][c].status);

Mine[r][c].openst=1;

if(Mine[r][c].minenumbers)

{

sprintf(cn,

if(Mine[r][c].minenumbers

setcolor(Mine[r][c].minenumbers);

else

setcolor(5);

outtextxy(Mine[r][c].left+5,Mine[r][c].top+5,cn);

}

}

/*判断雷方块属性*/

int ReturnSelect(int r,int c)

{

int Select=0;

if(Mine[r][c].openst||Mine[r][c].status)

Select=1;

else

{

DrawNotM(r,c);

if(Mine[r][c].minenumbers)

Select=1;

}

return Select;

}

/*打开无雷区片区域*/

void Select(int r,int c)

{

int t1,t2;

if(Mine[r][c].minenumbers)

DrawNotM(r,c);

else

{

DrawNotM(r,c);

t1=r;

while(t1>0)

{

t1-=1;

if(ReturnSelect(t1,c))

break;

else

SelectLoop(t1,c);

}

t1=r;

while(t1

{

t1+=1;

if(ReturnSelect(t1,c))

break;

else

SelectLoop(t1,c);

}

SelectLoop(r,c);

}

}

/*间接递归Select()函数*/

void SelectLoop(int r,int c)

{

int tc;

tc=c;

while(tc>0)

{

tc-=1;

if(ReturnSelect(r,tc))

break;

else

Select(r,tc);

}

tc=c;

while(tc

{

tc+=1;

if(ReturnSelect(r,tc))

break;

else

Select(r,tc);

}

}

/*打开有雷区域*/

void DisplayMine()

{

int i,j;

for(i=0;i

for(j=0;j

{

if(Mine[i][j].status&&!Mine[i][j].openst)

{

OpenMine(Mine[i][j].left,Mine[i][j].top,Mine[i][j].right-1,Mine[i][j].down-1,8,Mine[i][j].status);

Mine[i][j].openst=1;

}

}

}

/*雷区单击事件*/

void MineClick(Mouseh *hd)

{

int i,j;

for(i=0;i

{

for(j=0;j

{

if(hd->mx>Mine[i][j].left&&hd->mxmy>Mine[i][j].top&&hd->my

{

begin=1;

if(Mine[i][j].status)

end=GAMEOVER;

if(!Mine[i][j].openst)

{

DrawFace2(hWnd.left+hWnd.width/2-10,hWnd.top+55,hWnd.left+hWnd.width/2+10,hWnd.top+75,Mine[i][j].status);

if(Mine[i][j].status)

{

OpenMine(Mine[i][j].left,Mine[i][j].top,Mine[i][j].right-1,Mine[i][j].down-1,12,Mine[i][j].status);

Mine[i][j].openst=1;

}

else

Select(i,j);

}

}

if(end)

break;

}

if(end)

break;

} if(end) { begin=0;

DisplayMine();

}

}

/*判断鼠标是否在布雷区域内*/

int OnMinefield(Mouseh *mt)

{

int rt=0;

if(mt->mx>Mine[0][0].left&&mt->mxmy>Mine[0][0].top&&mt->my

rt=1;

return rt;

}

/*Game按钮单击事件*/

void GameClick(BUTTON bt,char *Meun[])

{

int i,size,tk=0;

BUTTON mb[5];

size=imagesize(bt.left,bt.down+1,bt.left+110,bt.down+78); buffer=malloc(size);

getimage(bt.left,bt.down+1,bt.left+110,bt.down+78,buffer); DrawBox2(bt.left,bt.down+1,bt.left+110,bt.down+78,7); setcolor(0);

for(i=0;i

{

outtextxy(bt.left+5,bt.down+8+i*14,Meun[i]);

mb[i].left=bt.left+3;

mb[i].top=bt.down+6+i*14;

mb[i].right=bt.left+107;

mb[i].down=mb[i].top+12;

mb[i].caption=Meun[i];

mb[i].fillcolor=7;

mb[i].fontcolor=0;

}

while(!tk)

{

ShowMouse(hw,15);

MouseRead(hw);

if(hw->mkey)

{

if(OnButton(mb[0]))

hWnd=CreateWindow(active),tk=1;

if(OnButton(mb[1]))

hWnd=CreateWindow(PRIMARY),tk=1;

if(OnButton(mb[2]))

hWnd=CreateWindow(INTERMEDIATE),tk=1; if(OnButton(mb[3]))

hWnd=CreateWindow(HIGH),tk=1;

if(OnButton(mb[4]))

closegraph(),exit(0);

if(hw->mx>bt.left+110||hw->my>bt.down+78) tk=2;

}

for(i=0;i

{

if(OnButton(mb[i]))

LightButton(mb[i]);

}

}

putimage(bt.left,bt.down+1,buffer,COPY_PUT);

if(tk==1) { ShowWindow(hWnd); SetMine();

end=0;

mtime=0;

}

}

/*判断是否胜利*/

void AllOpen()

{

int i,j,size,qt=0,ok=0;

void *buffer;

char mt[100];

for(i=0;i

{

for(j=0;j

{

if(!Mine[i][j].openst&&Mine[i][j].status) ok=1;

if(!Mine[i][j].openst&&!Mine[i][j].status) {

ok=0;

qt=1;

break;

}

}

if(qt)

break;

}

if(ok)

{

DisplayMine();

end=GAMEOVER;

begin=0;

for(i=0;i

{

delay(50000);

}

size=imagesize(200,150,440,330); buffer=malloc(size);

getimage(200,150,440,330,buffer);

DrawBox2(200,150,440,330,7);

setcolor(6);

outtextxy(280,230,

outtextxy(280,250,

sprintf(mt,

outtextxy(330,250,mt);

setcolor(10);

outtextxy(240,270,

DrawFace2(310,180,330,200,0);

getch();

putimage(200,150,buffer,COPY_PUT);

free(buffer);

}

}

/*===================== 游戏入口 ======================*/ void Process()

{

if(MouseInit(0,639,0,479)==0)

exit(1);

hw=(Mouseh *)malloc(sizeof(Mouseh));

hw->mx=320;

hw->my=240; hWnd=CreateWindow(PRIMARY); ShowWindow(hWnd); SetMine();

end=0;

begin=0;

mtime=0;

for(;;)

{

ShowMouse(hw,15);

MouseRead(hw);

AllOpen();

if(hw->mkey==1)

{

if(OnMinefield(hw))

MineClick(hw);

if(OnButton(hWnd.close))

break;

if(OnButton(hWnd.game))

GameClick(hWnd.game,MENU);

}

if(OnButton(hWnd.close))

LightButton(hWnd.close);

if(OnButton(hWnd.game)) LightButton(hWnd.game); if(OnButton(hWnd.help)) LightButton(hWnd.help); }

}

main()

{

int grd,grm;

grd=DETECT;

registerbgidriver(EGAVGA_driver); initgraph(&grd,&grm,

Process();

closegraph();

}


相关内容

  • Java编程入门
  • Java编程入门 理想情况下,在阅读本书前,你应该对Java程序语言已经有了相当程度的掌握.但或许你已 经很久没有用Java,或者你只是想通学习Java知识来进行手机游戏编程.如果你属于上述情况,那么本教程正是为你准备的.本教程不是要教你Java的所有细节,因为已经有大量的优秀书籍在做这些工作.相反 ...

  • 7猜数字游戏课程设计完整版
  • 北京邮电大学世纪学院 实验.实习.课程设计报告撰写格式与要求 (试行) 一.实验报告格式要求 1.有实验教学手册,按手册要求填写,若无则采用统一实验报告封面. 2.报告一律用钢笔书写或打印,打印要求用A4纸:页边距要求如下:页边距上下各为2.5厘米,左右边距各为2.5厘米:行间距取固定值(设置值为2 ...

  • 面向对象程序设计与面向过程程序设计的区别(2)
  • 面向过程程序设计和面向对象程序设计的区别 面向过程程序设计我个人的理解简单来说,他考虑问题的方式是面向流程的,一个程序的设计思路就是解决一个问题的流程.就好比游戏先登入界面,再输入密码,然后选择角色,在然后进入游戏玩耍,结束... .... 这把这些步样就是面向过程.面向过程就是分析出解决问题所需要 ...

  • [游戏设计-原理与实践]
  • <游戏设计-原理与实践> 前言: 游戏的可玩性是游戏所包含的交互性的程度及特点,就是玩家与游戏世界及游戏世界对玩家的选择作出反应的方式. 游戏设计就是定义游戏可玩性的内容.游戏设计决定了玩家可以在游戏世界中做出什么选择,并且这些选择会在游戏的其余部分造成哪些不同的结果.游戏设计决定了游戏 ...

  • 宏程序在数控编程中的应用技巧及编程实例
  • 2010年6月第38卷第12期 机床与液压 MACHINETOOL&HYDRAULICS Jull.2010V01.38No.12 DOI:10.3969/j.issn.1001-3881.2010.12.011 宏程序在数控编程中的应用技巧及编程实例 韩全立,王宏颖 (河南工业职业技术学院 ...

  • 局域网的象棋对战
  • 说 明 本系统是一款基于Eclipse平台开发的局域网象棋对战游戏,采用Java GUI技术绘制界面,面向连接的Socket实现局域网联机,多线程同步用户信息数据. 系统分为服务器端和客户端,服务器端起到处理用户联网信息并转发数据的作用,客户端主要实现象棋对弈. 该象棋游戏界面友好,操作方便,能满足 ...

  • 1.2算法描述与设计
  • 1.2 算法描述与设计 一.教材分析 本节是高中信息技术选修课<算法与程序设计>(教科版)第一章"如何用计算机解决问题"的第二节"算法描述与设计". 通过1.1 节的学习, 学生已经了解了计算机解决问题的基本过程,并知道算法是程序设计的灵魂,只要 ...

  • 人工智能(蔡自兴)-实验2事实的表示
  • 实验2 Prolog程序事实表示 Visual Prolog是面向对象的.严格类型化的和模式检验的程序设计语言.在编写Visual Prolog程序时,必须掌握这些内容,但是在这里将集中在编写代码这个核心问题上,也就是说,编写这些代码时暂时不考虑类.类型和模式. 为此,将使用包含在Visual Pr ...

  • FLASH游戏毕业论文
  • FLASH 游戏毕业论文 摘要 随着现代科技的高速发展短短几十年,电脑游戏得到迅猛发展.电脑游戏充分利用多媒体网络优势,拓宽了传统游戏的界限,给人们带来全新的体验.在这些游戏中,FLASH 游戏以其好看的动画,绚丽的声光效果,高度的通畅性,及很强的可玩性,而受到广大青少年的青睐.本文就一款名为&qu ...