C++ 风靡一时的连连看游戏的实现流程详解
void Mousemove (int leftx,int lefty) //鼠标移动时的变化
{
static int prex,prey,preidx,preidy, curidx,curidy;
if(Judg_val(leftx,lefty))
{
TranstoDracoor(leftx,lefty,&curidx,&curidy); //转化为图纸坐标
if(GridID[curidy][curidx] != 0)
{
GridPhy_coor(leftx,lefty);
if(pre.idx == preidx && pre.idy == preidy)
putimage(prex,prey,&image[GridID[preidy][preidx]][1]);
else
putimage(prex,prey,&image[GridID[preidy][preidx]][0]);
prex = leftx, prey = lefty;
preidx = curidx, preidy = curidy;
Draw_frame(leftx,lefty); //绘制边框
} } }
void Leftbottondown (MOUSEMSG mouse) //左击时的变化
{
static int click = 0, idx,idy;
click++;
SeleReact (mouse.x,mouse.y); //显示选中效果
if(click == 1) RecordInfor(mouse.x,mouse.y,pre);
if(click == 2)
{
TranstoDracoor (mouse.x,mouse.y,&idx,&idy);
if(idx != pre.idx || idy != pre.idy)
{
RecordInfor (mouse.x,mouse.y,cur);
if(pre.GridID == cur.GridID && DesGrid(pre,cur))
{
GridID[pre.idy][pre.idx] = GridID[cur.idy][cur.idx] =0;
Link (); pn = 0;
putimage(pre.leftx,pre.lefty,&image2);
putimage(cur.leftx,cur.lefty,&image2);
Init_Grid(pre); Init_Grid(cur); click = 0;
}
else
{
ExchaVal(dur,pre); ExchaVal(pre,cur);
Init_Grid(cur); click = 1;
putimage(dur.leftx,dur.lefty,&image[GridID[dur.idy][dur.idx]][0]);
} }
else click = 1;
} }
void SeleReact (int leftx,int lefty) //选中时效果
{
if(Judg_val(leftx,lefty))
{
int idx,idy;
TranstoDracoor (leftx,lefty,&idx,&idy);
GridPhy_coor (leftx,lefty);
putimage(leftx,lefty,&image[GridID[idy][idx]][1]);
} }
bool Judg_val(int leftx,int lefty) //判断鼠标是否在游戏区
{
return leftx > leftedge && leftx < leftedge + GridW * COL &&
lefty > topedge && lefty < topedge + GridH * ROW;
}
void TranstoDracoor (int mousex,int mousey ,int *idx,int *idy) //鼠标坐标转化为图纸坐标
{
if(Judg_val(mousex,mousey))
{
*idx = (mousex - leftedge) / 42 + 1;
*idy = (mousey - topedge) / 48 + 1 ;
} }
void RecordInfor(int leftx,int lefty,GridInfor &grid) //记录选中的信息
{
TranstoDracoor(leftx,lefty,&grid.idx,&grid.idy);
grid.leftx = (grid.idx - 1) * 42 + leftedge;
grid.lefty = (grid.idy - 1) * 48 + topedge;
grid.GridID = GridID[grid.idy][grid.idx];
}
bool Single_click_judge (int mousex,int mousey) //判断单击是否有效
{
int idx,idy;
TranstoDracoor (mousex,mousey,&idx,&idy); //转化为图纸坐标
if(Judg_val(mouse.x,mouse.y) && GridID[idy][idx] != 0)
return true;
return false;
}
void Draw_frame(int leftx,int lefty) //绘制方框
{
setcolor(RGB(126,91,68));
setlinestyle(PS_SOLID,NULL,1);
rectangle(leftx,lefty,leftx+41,lefty+47);
rectangle(leftx + 2,lefty + 2,leftx+39,lefty+45);
setcolor(RGB(250,230,169));
rectangle(leftx + 1,lefty + 1,leftx+40,lefty+46);
}
- .NET Core系列之MemoryCache 初识
- 007手机一键Root(安机网一键Root) v3.0 官方最新版 一键ROOT您的Android手机
- 12306密码被盗了怎么办?12306密码外泄解决方法
- 12个字的qq网名
- 150M迷你型无线路由器怎么设置?
- 192.168.1.1打不开怎么办?路由器192.168.1.1打不开的原因以及解决办法
- 2011年电子报合订本 电子报 编辑部 中文 PDF版 [84M]
- 2015年1月15日小米新旗舰发布会现场图文直播
- 2016.3.1vivo Xplay5新品发布会现场视频直播 优酷直播
- 2016华为P9发布会视频直播地址 4月15日华为P9国行发布会直播