C语言项目实战:《连连看》基础项目丨460 行源码注释

这篇文章主要为大家详细介绍了C语言实现——《连连看》小游戏,示例代码介绍的非常详细,具有想当的参考价值,感兴趣的小伙伴们可以参考一下!
游戏介绍:
连连看小游戏速度节奏快,画面清晰可爱,适合细心的玩家 。丰富的道具和公共模式的加入,增强游戏的竞争性 。多样式的地图,使玩家在各个游戏水平都可以寻找到挑战的目标,长期地保持游戏的新鲜感 。本期举例的项目类似宠物连连看,小动物造型的连连看游戏(这个主要看你准备好的图片素材)
游戏玩法

C语言项目实战:《连连看》基础项目丨460 行源码注释

文章插图
加载游戏后,点击画面中间的图像即进入游戏状态 。使用鼠标左键即可,点击相同的两张图卡,用三根内的直线连在一起就可以消除 。只要我们在有限的时间里,用我们智慧消除相连卡片,就可以获得最终的胜利 。那么我们了解了规则之后,就动手来试试吧!
编译器:/2019最佳;
插件:图形库插件easyX,涉及图片素材可以自行百度找也可以关注文末领取;
效果图展示:
源代码示例:
#include #include #include #include #include #pragma comment(lib,"winmm.lib")//15015012721易//6010016932中//10012014828难#define leftedge150//游戏区距左边框距离#define topedge150//游戏区距上边框距离#define COL12//游戏区列数#define ROW7//游戏区行数#define GridNum21//游戏图片数目#define GridW42//游戏图片的长#define GridH48//游戏图片的宽#define N555//开屏大小(宽) #define M785//开屏大小(长)IMAGE image[GridNum + 1][2];//图片库IMAGE image2;//填充图片intGridID[ROW + 2][COL + 2];//游戏图纸MOUSEMSG mouse;//记录鼠标信息struct GridInfor//记入击中图片信息{int idx,idy;//图纸坐标int leftx,lefty; //屏幕坐标int GridID;//图片类型}pre,cur,dur;struct//记录连线点{int x;int y;}point[4]; static int pn;//记录连线点个数void InitFace ();//初始化界面void Shuffle();//随即打乱图片void ShowGrid ();//显示图片void RandGrid ();//绘制地图void Link();//连接两图void Des_direct ();//直接相消void Des_one_corner();//一折相消void Des_two_corner();//两折相消void Load_picture ();//加载图片void Init_Grid (GridInfor& pre);//初始化格子信息void Leftbottondown (MOUSEMSG mouse);//实现鼠标左击效果void Draw_frame (int leftx,int lefty);//绘制边框void Mousemove (int leftx,int lefty);//实现鼠标移动效果bool Judg_val (int leftx,int lefty);//判断鼠标是否在游戏区void SeleReact (int leftx,int lefty);//显示选中效果void TranstoPhycoor (int* idx,int* idy);//图纸坐标转变为屏幕坐标void GridPhy_coor (int& leftx,int& lefty);//规范物理坐标void iPaint (long x1,long y1,long x2,long y2);//将直线销毁void DrawLine (int x1,int y1,int x2,int y2) ;//用直线连接两图bool DesGrid (GridInfor pre,GridInfor cur);//判断两者是否能相消bool Match_direct (POINT ppre,POINT pcur);//判断两者是否能够直接相消bool Match_one_corner (POINT ppre,POINT pcur);//判断两者是否能一折相消bool Match_two_corner (POINT ppre,POINT pcur);//判断两者是否能两折相消void ExchaVal (GridInfor& pre,GridInfor& cur);//交换图片信息bool Single_click_judge (int mousex,int mousey);//判断单击是否有效 void RecordInfor (int leftx,int lefty,GridInfor &grid);//记录选中的信息void TranstoDracoor (int mousex,int mousey,int *idx,int *idy);//鼠标坐标转化为图纸坐标void Explot (POINT point,int *left,int *right,int *top,int *bottel);//探索point点附近的空位置void main(){initgraph(M,N);mciSendString("play game_begin.mp3 repeat", NULL, 0, NULL); InitFace();while(1){ mouse = GetMouseMsg(); switch(mouse.uMsg){case WM_MOUSEMOVE:Mousemove(mouse.x,mouse.y);break;case WM_LBUTTONDOWN:if(Single_click_judge(mouse.x,mouse.y)){Leftbottondown(mouse);}break;default:break;}}closegraph();}生成操作//void RandGrid()//产生图片的标记{for(int iCount = 0, x = 1; x