• <em id="6vhwh"><rt id="6vhwh"></rt></em>

    <style id="6vhwh"></style>

    <style id="6vhwh"></style>
    1. <style id="6vhwh"></style>
        <sub id="6vhwh"><p id="6vhwh"></p></sub>
        <p id="6vhwh"></p>
          1. 国产亚洲欧洲av综合一区二区三区 ,色爱综合另类图片av,亚洲av免费成人在线,久久热在线视频精品视频,成在人线av无码免费,国产精品一区二区久久毛片,亚洲精品成人片在线观看精品字幕 ,久久亚洲精品成人av秋霞

            連連看秘籍(連連看方法)

            更新時間:2023-03-01 18:18:19 閱讀: 評論:0

            這篇文章主要為大家詳細介紹了C語言實現——《連連看》小游戲,示例代碼介紹的非常詳細,具有想當的參考價值,感興趣的小伙伴們可以參考一下!

            游戲介紹:

            連連看小游戲速度節奏快,畫面清晰可愛,適合細心的玩家。豐富的道具和公共模式的加入,增強游戲的競爭性。多樣式的地圖,使玩家在各個游戲水平都可以尋找到挑戰的目標,長期地保持游戲的新鮮感。本期舉例的項目類似寵物連連看,小動物造型的連連看游戲(這個主要看你準備好的圖片素材)

            游戲玩法

            加載游戲后,點擊畫面中間的圖像即進入游戲狀態。使用鼠標左鍵即可,點擊相同的兩張圖卡,用三根內線連在一起就可以消除。只要我們在有限的時間里,用我們智慧消除相連卡片,就可以獲得最終的勝利。那么我們了解了規則之后,就動手來試試吧!

            編譯器:VS2013/2019最佳;

            插件:圖形庫插件easyX,涉及圖片素材可以自行百度找也可以關注文末領取;

            效果圖展示:

            源代碼示例:

            #include <graphics.h>#include <conio.h>#include <time.h>#include <stdio.h>#include <windows.h>#pragma comment(lib,"winmm.lib")//150 150 12 7 21 易//60 100 16 9 32 中//100 120 14 8 28 難#define leftedge 150 //游戲區距左邊框距離#define topedge 150 //游戲區距上邊框距離#define COL 12 //游戲區列數#define ROW 7 //游戲區行數#define GridNum 21 //游戲圖片數目#define GridW 42 //游戲圖片的長#define GridH 48 //游戲圖片的寬#define N 555 //開屏大小(寬) #define M 785 //開屏大小(長)IMAGE image[GridNum + 1][2]; //圖片庫IMAGE image2; //填充圖片int GridID[ROW + 2][COL + 2]; //游戲圖紙MOUSEMSG mou; //記錄鼠標信息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 mou); //實現鼠標左擊效果void Draw_frame (int leftx,int lefty); //繪制邊框void Moumove (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 moux,int mouy); //判斷單擊是否有效 void RecordInfor (int leftx,int lefty,GridInfor &grid); //記錄選中的信息void TranstoDracoor (int moux,int mouy,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) { mou = GetMouMsg(); switch(mou.uMsg) { ca WM_MOUSEMOVE: Moumove(mou.x,mou.y); break; ca WM_LBUTTONDOWN: if(Single_click_judge(mou.x,mou.y)) { Leftbottondown(mou); } break; default: break; } } clograph();}////////////////////////////////////////生成操作//////////////////////////////void RandGrid() //產生圖片的標記{ for(int iCount = 0, x = 1; x <= ROW; ++x ) { for( int y = 1; y <= COL; ++y ) { GridID[x][y] = iCount++ % GridNum + 1;} } }void Shuffle( ) //打亂棋盤{ int ix, iy, jx, jy, grid; for( int k = 0; k < 84; ++k ) { ix = rand() % ROW + 1; // 產生 1 - COL 的隨機數 iy = rand() % COL + 1; // 產生 1 - ROW 的隨機數 jx = rand() % ROW + 1; // 產生 1 - COL 的隨機數 jy = rand() % COL + 1; // 產生 1 - ROW 的隨機數 if( GridID[ix][iy] != GridID[jx][jy] ) //如果不相等就交換數據 { grid = GridID[ix][iy]; GridID[ix][iy] = GridID[jx][jy]; GridID[jx][jy] = grid;} } }////////////////////////////////初始化界面///////////////////////////////////////void InitFace() { srand((unsigned)time(NULL)); Load_picture(); RandGrid(); IMAGE image3; loadimage(&image3,"res\bg.bmp"); putimage(0,0,&image3); getimage(&image2,3 * 42,2 * 48,42, 48); Shuffle(); ShowGrid(); }void Load_picture() //加載圖片{ IMAGE image1,background; loadimage(&image1,"IMAGE","grids"); SetWorkingImage(&image1); for(int i = 1 ;i < GridNum + 1 ;i ++) for(int j = 0;j < 2;j++) getimage(&image[i][j],j * 42,i * 48,42, 48); loadimage(&background,"IMAGE","bg"); SetWorkingImage(&background); getimage(&image2,3 * 42,2 * 48,42, 48); SetWorkingImage(); putimage(0,0,&background);}void ShowGrid(){ int idx,idy; for(int i = 0 ;i < ROW; i ++) for(int j = 0 ;j < COL ; j++) { idy = i * 48 + topedge ,idx = j * 42 + leftedge; putimage(idx,idy,&image[GridID[i + 1][j + 1]][0]); } }/////////////////////////////////鼠標操作////////////////////////////////////////void Moumove (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]); el putimage(prex,prey,&image[GridID[preidy][preidx]][0]); prex = leftx, prey = lefty; preidx = curidx, preidy = curidy; Draw_frame(leftx,lefty); //繪制邊框 } } } void Leftbottondown (MOUSEMSG mou) //左擊時的變化{ static int click = 0, idx,idy; click++; SeleReact (mou.x,mou.y); //顯示選中效果 if(click == 1) RecordInfor(mou.x,mou.y,pre); if(click == 2) { TranstoDracoor (mou.x,mou.y,&idx,&idy); if(idx != pre.idx || idy != pre.idy) { RecordInfor (mou.x,mou.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; } el { ExchaVal(dur,pre); ExchaVal(pre,cur); Init_Grid(cur); click = 1; putimage(dur.leftx,dur.lefty,&image[GridID[dur.idy][dur.idx]][0]); } } el 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 moux,int mouy ,int *idx,int *idy) //鼠標坐標轉化為圖紙坐標{ if(Judg_val(moux,mouy)) { *idx = (moux - leftedge) / 42 + 1; *idy = (mouy - 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 moux,int mouy) //判斷單擊是否有效{ int idx,idy; TranstoDracoor (moux,mouy,&idx,&idy); //轉化為圖紙坐標 if(Judg_val(mou.x,mou.y) && GridID[idy][idx] != 0) return true; return fal;}void Draw_frame(int leftx,int lefty) //繪制方框{ tcolor(RGB(126,91,68)); tlinestyle(PS_SOLID,NULL,1); rectangle(leftx,lefty,leftx+41,lefty+47); rectangle(leftx + 2,lefty + 2,leftx+39,lefty+45); tcolor(RGB(250,230,169)); rectangle(leftx + 1,lefty + 1,leftx+40,lefty+46); }////////////////////////////////判斷消除操作/////////////////////////////////////bool DesGrid (GridInfor pre,GridInfor cur) //判斷兩者是否能相消{ bool match = fal; POINT ppre,pcur; ppre.x = pre.idx; ppre.y = pre.idy; pcur.x = cur.idx; pcur.y = cur.idy; if(Match_direct(ppre,pcur)) match = true; el if(Match_one_corner(ppre,pcur)) match = true; el if(Match_two_corner(ppre,pcur)) match =true; return match;}bool Match_direct(POINT ppre,POINT pcur) //判斷兩者是否能夠直接相消{ int k,t; if(ppre.x == pcur.x) { k = ppre.y > pcur.y ? ppre.y : pcur.y; t = ppre.y < pcur.y ? ppre.y : pcur.y; if(t + 1 == k) goto FIND; for(int i = t + 1;i < k ;i++) if(GridID[i][ppre.x] != 0) return fal; if(i == k) goto FIND; } el if(ppre.y == pcur.y) { k = ppre.x > pcur.x ? ppre.x : pcur.x; t = ppre.x < pcur.x ? ppre.x : pcur.x; if(t + 1 == k) goto FIND; for(int i = t + 1;i < k ;i++) if(GridID[ppre.y][i] != 0) return fal; if(i == k) goto FIND; } return fal;FIND: point[pn].x = pcur.x, point[pn].y = pcur.y; pn++; point[pn].x = ppre.x, point[pn].y = ppre.y; pn++; return true;}bool Match_one_corner(POINT ppre,POINT pcur) //判斷兩者是否能一折相消{ int left,right,top,bottel,x = ppre.x,y = ppre.y; Explot(ppre,&left,&right,&top,&bottel); ppre.y = top - 1;RESEARCHX: if(ppre.y < bottel) ppre.y++; el goto BACK; if(Match_direct(ppre,pcur)) goto FIND; el goto RESEARCHX;BACK: ppre.y = y; ppre.x = left - 1;RESEARCHY: if(ppre.x < right) ppre.x++; el goto REBACK; if(Match_direct(ppre,pcur)) goto FIND; el goto RESEARCHY;REBACK: pn = 0; return fal;FIND: point[pn].x = x,point[pn].y = y,pn++; return true;}bool Match_two_corner(POINT ppre,POINT pcur) //判斷兩者是否能兩折相消{ int left,right,top,bottel,x = ppre.x,y = ppre.y; Explot(ppre,&left,&right,&top,&bottel); ppre.y = top - 1;RESEARCHX: if(ppre.y < bottel) ppre.y++; el goto BACK; if(Match_one_corner(ppre,pcur)) goto FIND; el goto RESEARCHX;BACK: ppre.y = y; ppre.x = left - 1;RESEARCHY: if(ppre.x < right) ppre.x++; el goto REBACK; if(Match_one_corner(ppre,pcur)) goto FIND; el goto RESEARCHY;REBACK: pn = 0;return fal;FIND: point[pn].x = x,point[pn].y = y,pn++; return true;}void Explot(POINT point,int *left,int *right,int *top,int *bottel){ int x = point.x,y = point.y; x++; while(x <= COL + 1 && GridID[y][x] == 0) x++; *right = x - 1; x = point.x; x--; while(x >= 0 && GridID[y][x] == 0) x--; *left = x + 1; x = point.x; y++; while(y <= ROW + 1 && GridID[y][x] == 0) y++; *bottel= y - 1; y = point.y; y--; while(y >= 0 && GridID[y][x] == 0) y--; *top = y + 1; }/////////////////////////////////消除操作////////////////////////////////////////void Link (){ switch(pn) { ca 2: Des_direct(); break; ca 3: Des_one_corner(); break; ca 4: Des_two_corner(); break; default : break;} }void Des_direct (){ TranstoPhycoor(&point[0].x,&point[0].y); TranstoPhycoor(&point[1].x,&point[1].y); DrawLine(point[0].x,point[0].y,point[1].x,point[1].y); Sleep(250); iPaint(point[0].x,point[0].y,point[1].x,point[1].y);}void Des_one_corner(){ TranstoPhycoor(&point[0].x,&point[0].y); TranstoPhycoor(&point[1].x,&point[1].y); TranstoPhycoor(&point[2].x,&point[2].y); DrawLine(point[0].x,point[0].y,point[1].x,point[1].y); DrawLine(point[1].x,point[1].y,point[2].x,point[2].y); Sleep(250); iPaint(point[0].x,point[0].y,point[1].x,point[1].y); iPaint(point[1].x,point[1].y,point[2].x,point[2].y);}void Des_two_corner(){ TranstoPhycoor(&point[0].x,&point[0].y); TranstoPhycoor(&point[1].x,&point[1].y); TranstoPhycoor(&point[2].x,&point[2].y); TranstoPhycoor(&point[3].x,&point[3].y); DrawLine(point[0].x,point[0].y,point[1].x,point[1].y); DrawLine(point[1].x,point[1].y,point[2].x,point[2].y); DrawLine(point[2].x,point[2].y,point[3].x,point[3].y); Sleep(250); iPaint(point[0].x,point[0].y,point[1].x,point[1].y); iPaint(point[1].x,point[1].y,point[2].x,point[2].y); iPaint(point[2].x,point[2].y,point[3].x,point[3].y);} void DrawLine (int x1,int y1,int x2,int y2){ tlinestyle(PS_SOLID,NULL,3); tcolor(RGB(90,43,9)); line(x1 + 21,y1 + 24,x2 + 21,y2 + 24);}void iPaint (long x1,long y1,long x2,long y2) { int minx,miny,maxx,maxy; if(x1 == x2) { maxy = y1 > y2? y1:y2; miny = y1 < y2? y1:y2; for(int i = miny; i <= maxy;i += 48) putimage(x1,i,&image2); } el if(y1 == y2) { maxx = x1 > x2? x1:x2; minx = x1 < x2? x1:x2; for(int j = minx; j <= maxx;j += 42 ) putimage(j,y1,&image2);} }/////////////////////////////////////////////////////////////////////////////////void GridPhy_coor(int& leftx,int& lefty) //轉化為標準物理坐標{ leftx = ((leftx - leftedge) / 42) * 42 + leftedge; lefty = ((lefty - topedge) / 48) * 48 + topedge;}void ExchaVal(GridInfor& pre,GridInfor& cur) //交換格子信息{ pre.GridID = cur.GridID; pre.idx = cur.idx;pre.idy = cur.idy; pre.leftx = cur.leftx;pre.lefty = cur.lefty;}void Init_Grid(GridInfor& grid) //初始化格子{ grid.GridID = 0; grid.idx = 0; grid.idy = 0; grid.leftx = 0; grid.lefty = 0;}void TranstoPhycoor (int* idx,int* idy) //圖紙坐標轉變為屏幕坐標{ int x ,y;x =*idx,y = *idy; *idy = (y - 1) * 48 + leftedge; *idx = (x - 1) * 42 + topedge;}

            未完成的部分功能代碼,大家也可以自己先去想想試試,每一次的思考就是你進步的過程!

            如果學習的過程中有什么問題,以及本項目有什么不懂的地方,都可以來找我交流,我來幫你!

            那么今天的分享就到這里了,后續會更新更多精彩項目或者知識內容的,大家要好好學C語言C++喲~

            寫在最后:對于準備學習C/C++編程的小伙伴,如果你想更好的提升你的編程核心能力(內功)不妨從現在開始!

            編程學習書籍分享:

            編程學習視頻分享:

            整理分享(多年學習的源碼、項目實戰視頻、項目筆記,基礎入門教程)

            歡迎轉行和學習編程的伙伴,利用更多的資料學習成長比自己琢磨更快哦!

            對于C/C++感興趣可以關注小編在后臺私信我:【編程交流】一起來學習哦!可以領取一些C/C++的項目學習視頻資料哦!已經設置好了關鍵詞自動回復,自動領取就好了!

            本文發布于:2023-02-28 20:15:00,感謝您對本站的認可!

            本文鏈接:http://www.newhan.cn/zhishi/a/167766589979950.html

            版權聲明:本站內容均來自互聯網,僅供演示用,請勿用于商業和其他非法用途。如果侵犯了您的權益請與我們聯系,我們將在24小時內刪除。

            本文word下載地址:連連看秘籍(連連看方法).doc

            本文 PDF 下載地址:連連看秘籍(連連看方法).pdf

            標簽:連連看   秘籍   方法
            相關文章
            留言與評論(共有 0 條評論)
               
            驗證碼:
            Copyright ?2019-2022 Comsenz Inc.Powered by ? 實用文體寫作網旗下知識大全大全欄目是一個全百科類寶庫! 優秀范文|法律文書|專利查詢|
            主站蜘蛛池模板: 国产精品日韩中文字幕| 欧洲精品码一区二区三区| 成年女人A级毛片免| 国产成人亚洲日韩欧美| 大地资源高清免费观看| 亚洲日韩国产精品第一页一区 | 亚洲中文字幕成人综合网| 综合伊人久久在| 亚洲成人av在线综合| 日韩欧美一区二区三区永久免费 | 在线国产精品中文字幕| 中文字幕网伦射乱中文| a在线观看视频在线播放| a级免费视频| 五月丁香激激情亚洲综合| 67194亚洲无码| freechinese麻豆| 国产亚洲精品AA片在线播放天| 久久免费观看归女高潮特黄| 欧洲一区二区中文字幕| 综合午夜福利中文字幕人妻| 日本一区二区三区激情视频| 无码伊人久久大杳蕉中文无码| 国产精品成人av电影不卡| 久久精品国产亚洲欧美| 亚洲第一香蕉视频啪啪爽| 久久精品国产亚洲AV麻豆长发| 久久久www成人免费毛片| 国产偷窥熟女高潮精品视频| 日本不卡在线一区二区| 高清破外女出血AV毛片| 丝袜高潮流白浆潮喷在线播放| 激情久久综合精品久久人妻| 暖暖视频免费观看| 成人午夜无人区一区二区| 99久久国产综合精品成人影院 | 韩国福利视频一区二区三区| 五月婷婷中文字幕| 亚洲天堂av免费在线看| 性动态图无遮挡试看30秒 | 国产一区二区不卡视频在线|