




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、 /*方塊十字消游戲源代碼*/#include <stdio.h>#include <graphics.h>#include <stdlib.h>#include <math.h>#include <dos.h>#define true 1#define false 0/* -全局變量- */int BkGndColor=BLACK;int BorderColor=LIGHTGRAY;int LineColor=LIGHTBLUE;/* 消除一對方塊時時候的連線顏色 */* Pb - ProgressBar */int PbColor
2、=YELLOW;int PbY=30;int PbHeight=4;int PbValue; /* 進度條百分比,初始值為100.*/long StartTime; /* 開始時間的秒數,只統(tǒng)計分鐘,秒 */long TotalTime; /* 游戲總共的最大秒數!,*/* BoardDatas: a small-size board */* Boardxy0 - 0:empty, 1:filled */* Boardxy1 - cell's key; */unsigned char Board15152;int CellSize=20;int BoardX=170;int Board
3、Y=70;int BoardWidth=15;int BoardHeight=15;int CellColor=WHITE;int Focus=RED; /* focus's border rect color */int EraColor=CYAN; /* 用于擦除cell的顏色!*/int PairsCount; /*方塊對的數量*/int CellCount=0; /*剩余方塊的數量*/char buf100;int sroce; /*游戲得分*/int wmin,wmax,hmin,hmax;/* 用于存儲邏輯坐標(索引) */typedef struct _tagCELL c
4、har x; char y; CELL;CELL focus;/*定義焦點*/enum KEYCODES K_ESC =0x011b, K_UP =0x4800, /* upward arrow */ K_LEFT =0x4b00, K_DOWN =0x5000, K_RIGHT =0x4d00, K_SPACE =0x3920, K_P =0x1970, K_RETURN =0x1c0d, /* Enter */;/* -函數列表- */void InitGame(char *bgiPath); /*初始化游戲方塊*/void PlayGame();void QuitGame();void
5、InitProgressBar(); /*初始化進度條*/void UpdateProgressBar(int percent);void DrawCell(int key,int x,int y,int color);void EraseCell(int x,int y);void DrawBorderRect(CELL *c,int color);void DrawGameOver(char *info,int sroce);int GetKeyCode();int FindPath(CELL *c1);void start();void DrawPath(int x1,int y1,in
6、t x2,int y2,int x3,int y3,int color);void DrawPath3(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int color);void start() int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,""); setcolor(YELLOW); /*中方塊*/ setcolor(RED); rectangle(100,200,120,180); /*上方塊*/ setcolor(WHITE);
7、 rectangle(100,150,120,130); setfillstyle(7, WHITE); floodfill(110,140,WHITE); /*下方塊*/ rectangle(100,250,120,230); setfillstyle(6, WHITE); floodfill(110,240,WHITE); /*左方塊*/ rectangle(50,200,70,180); setfillstyle(6, WHITE); floodfill(60,190,WHITE); /*右方塊*/ rectangle(150,200,170,180); setfillstyle(4,
8、WHITE); floodfill(160,190,WHITE); setcolor(WHITE); moveto(200,190); lineto(230,190); moveto(215,205); lineto(215,175); rectangle(260,200,320,180); outtextxy(270,187,"SPACE"); moveto(350,195); lineto(370,195); moveto(350,185); lineto(370,185); setcolor(RED); rectangle(100+350,200,120+350,18
9、0); /*上方塊*/ setcolor(WHITE); rectangle(100+350,150,120+350,130); setfillstyle(7, WHITE); floodfill(110+350,140,WHITE); /*右方塊*/ rectangle(150+350,200,170+350,180); setfillstyle(4, WHITE); floodfill(160+350,190,WHITE); outtextxy(120,300,"Please do the following tips start the game! "); outte
10、xtxy(200,320,"press any key to continue"); outtextxy(220,340,"-by junjie2012");int AllRemove(CELL *c1) DrawPath(c1->x,c1->y, wmin,c1->y,c1->x,hmin,LineColor); DrawPath(c1->x,c1->y, c1->x,hmax,wmax,c1->y,LineColor); delay(6000); DrawPath(c1->x,c1->y,
11、wmin,c1->y,c1->x,hmin,BkGndColor); DrawPath(c1->x,c1->y, c1->x,hmax,wmax,c1->y, BkGndColor); EraseCell(wmin,c1->y); EraseCell(wmax,c1->y); EraseCell(c1->x,hmin); EraseCell(c1->x,hmax); Boardc1->xhmin1 =0; Boardc1->xhmax1 =0; Boardc1->xhmin0 =0; Boardc1->xhma
12、x0 =0; Boardwminc1->y1 =0; Boardwmaxc1->y1 =0; Boardwminc1->y0 =0; Boardwmaxc1->y0 =0; sroce+=60; return true;int FindPath(CELL *c1) /*-查找水平方向遇到兩個方塊的坐標-*/ wmin=wmax=c1->x; while(wmin>=0) wmin-; if( Boardwminc1->y0!=0) break; while(wmax<BoardWidth) wmax+; if(Boardwmaxc1->y0
13、!=0) break; /*-查找垂直方向遇到的兩個方塊的坐標-*/ hmin=hmax=c1->y; while(hmin>=0) hmin-; if( Boardc1->xhmin0!=0) break; while(hmax<BoardHeight) hmax+; if(Boardc1->xhmax0!=0) break; /*-方塊兩兩相同的情況 -*/ /*(wmin,y)與(wmax,y)相同的情況*/ if(wmin!=-1&&wmax!=BoardWidth&&(Boardwminc1->y1 = Boardw
14、maxc1->y1)&&(Boardwminc1->y1 != Boardc1->xhmin1)&&(Boardwminc1->y1 != Boardc1->xhmax1) if(Boardc1->xhmin1=Boardc1->xhmax1&&hmin!=-1&&hmax!=BoardHeight) AllRemove(&focus) ; else DrawPath(c1->x,c1->y, wmin,c1->y,wmax,c1->y,LineColor)
15、; delay(6000); DrawPath(c1->x,c1->y, wmin,c1->y,wmax,c1->y, BkGndColor); EraseCell(wmin,c1->y); EraseCell(wmax,c1->y); Boardwmaxc1->y0 =0; Boardwmaxc1->y1 =0; Boardwminc1->y0 =0; Boardwminc1->y1 =0; sroce+=20; return true; /*(wmin,y)與(x,hmin)相同的情況*/ if(wmin!=-1&&
16、;hmin!=-1&&Boardwminc1->y1 = Boardc1->xhmin1&&Boardwminc1->y1 != Boardwmaxc1->y1&&Boardwminc1->y1 != Boardc1->xhmax1) if(Boardc1->xhmax1=Boardwmaxc1->y1&&wmax!=BoardWidth&&hmax!=BoardHeight) AllRemove(&focus) ; else DrawPath(c1->
17、x,c1->y, wmin,c1->y,c1->x,hmin,LineColor); delay(6000); DrawPath(c1->x,c1->y, wmin,c1->y,c1->x,hmin,BkGndColor); EraseCell(wmin,c1->y); EraseCell(c1->x,hmin); Boardc1->xhmin0 =0; Boardc1->xhmin1 =0; Boardwminc1->y0 =0; Boardwminc1->y1 =0; sroce+=20; return true
18、; /*(wmin,y)與(x,hmax)相同的情況*/ if(wmin!=-1&&hmax!=BoardHeight&&Boardwminc1->y1 = Boardc1->xhmax1&&Boardwminc1->y1 != Boardwmaxc1->y1&&Boardwminc1->y1 != Boardc1->xhmin1) if(Boardc1->xhmin1=Boardwmaxc1->y1&&hmin!=-1&&wmax!=BoardWid
19、th) AllRemove(&focus) ; else DrawPath(c1->x,c1->y, wmin,c1->y,c1->x,hmax,LineColor); delay(6000); DrawPath(c1->x,c1->y, wmin,c1->y,c1->x,hmax,BkGndColor); EraseCell(wmin,c1->y); EraseCell(c1->x,hmax); Boardc1->xhmax1 =0; Boardc1->xhmax0 =0; Boardwminc1->y1
20、=0; Boardwminc1->y0 =0; sroce+=20; return true; /*(wmax,y)與(x,hmin)相同的情況*/ if(hmin!=-1&&wmax!=BoardWidth&&Boardwmaxc1->y1 = Boardc1->xhmin1&&Boardwmaxc1->y1 != Boardwminc1->y1&&Boardwmaxc1->y1 != Boardc1->xhmax1) if(Boardwminc1->y1=Boardc1->
21、xhmax1&&wmin!=-1&&hmax!=BoardHeight) AllRemove(&focus) ; else DrawPath(c1->x,c1->y, wmax,c1->y,c1->x,hmin,LineColor); delay(6000); DrawPath(c1->x,c1->y, wmax,c1->y,c1->x,hmin,BkGndColor); EraseCell(wmax,c1->y); EraseCell(c1->x,hmin); Boardc1->xhmi
22、n1 =0; Boardc1->xhmin0 =0; Boardwmaxc1->y1 =0; Boardwmaxc1->y0 =0; sroce+=20; return true; /*(wmax,y)與(x,hmax)相同的情況*/ if(wmax!=BoardWidth&&hmax!=BoardHeight&&Boardwmaxc1->y1 = Boardc1->xhmax1&&Boardwmaxc1->y1 != Boardwminc1->y1&&Boardwmaxc1->y1
23、 != Boardc1->xhmin1) if(Boardwminc1->y1=Boardc1->xhmin1&&wmin!=-1&&hmin!=-1) AllRemove(&focus) ; else DrawPath(c1->x,c1->y, wmax,c1->y,c1->x,hmax,LineColor); delay(6000); DrawPath(c1->x,c1->y, wmax,c1->y,c1->x,hmax,BkGndColor); EraseCell(wmax,c1-&
24、gt;y); EraseCell(c1->x,hmax); Boardc1->xhmax1 =0; Boardc1->xhmax0 =0; Boardwmaxc1->y1 =0; Boardwmaxc1->y0 =0; sroce+=20; return true; /*(x,hmin)與(x,hmax)相同的情況*/ if(hmin!=-1&&hmax!=BoardHeight&&Boardc1->xhmin1 = Boardc1->xhmax1&&Boardc1->xhmin1 != Board
25、wminc1->y1&&Boardc1->xhmin1 != Boardwmaxc1->y1) if(Boardwminc1->y1=Boardwmaxc1->y1&&wmin!=-1&&wmax!=BoardWidth) AllRemove(&focus) ; else DrawPath(c1->x,c1->y,c1->x,hmin,c1->x,hmax,LineColor); delay(6000); DrawPath(c1->x,c1->y,c1->x,hmin
26、,c1->x,hmax,BkGndColor); EraseCell(c1->x,hmin); EraseCell(c1->x,hmax); Boardc1->xhmin1 =0; Boardc1->xhmax1 =0; Boardc1->xhmin0 =0; Boardc1->xhmax0 =0; sroce+=20; return true; /*-3個方塊相同的情況-*/ if(hmin!=-1&&Boardc1->xhmin1 = Boardc1->xhmax1&&Boardc1->xhmax1
27、=Boardwminc1->y1&&Boardc1->xhmin1!= Boardwmaxc1->y1) DrawPath3(c1->x,c1->y,c1->x,hmin,c1->x,hmax,wmin,c1->y,LineColor); delay(6000); DrawPath3(c1->x,c1->y,c1->x,hmin,c1->x,hmax,wmin,c1->y,BkGndColor); EraseCell(wmin,c1->y); EraseCell(c1->x,hmin);
28、EraseCell(c1->x,hmax); Boardc1->xhmin1 =0; Boardc1->xhmax1 =0; Boardc1->xhmin0 =0; Boardc1->xhmax0 =0; Boardwminc1->y1 =0; Boardwminc1->y0 =0; sroce+=40; return true; if(hmin!=-1&&Boardc1->xhmin1 = Boardc1->xhmax1&& Boardc1->xhmax1=Boardwmaxc1->y1&
29、;&Boardc1->xhmin1!= Boardwminc1->y1) DrawPath3(c1->x,c1->y,c1->x,hmin,c1->x,hmax,wmax,c1->y,LineColor); delay(6000); DrawPath3(c1->x,c1->y,c1->x,hmin,c1->x,hmax,wmax,c1->y,BkGndColor); EraseCell(wmax,c1->y); EraseCell(c1->x,hmin); EraseCell(c1->x,hmax
30、); Boardc1->xhmin1 =0; Boardc1->xhmax1 =0; Boardc1->xhmin0 =0; Boardc1->xhmax0 =0; Boardwmaxc1->y1 =0; Boardwmaxc1->y0 =0; sroce+=40; return true; if(hmin!=-1&&Boardc1->xhmin1 = Boardwmaxc1->y1&&Boardwmaxc1->y1=Boardwminc1->y1&&Boardc1->xhmin1
31、!= Boardc1->xhmax1) DrawPath3(c1->x,c1->y,c1->x,hmin,wmin,c1->y,wmax,c1->y,LineColor); delay(6000); DrawPath3(c1->x,c1->y,c1->x,hmin,wmin,c1->y,wmax,c1->y,BkGndColor); EraseCell(wmin,c1->y); EraseCell(c1->x,hmin); EraseCell(wmax,c1->y); Boardc1->xhmin1 =0
32、; Boardc1->xhmin0 =0; Boardwmaxc1->y1 =0; Boardwmaxc1->y0 =0; Boardwminc1->y1 =0; Boardwminc1->y0 =0; sroce+=40; return true; if(wmin!=-1&&Boardc1->xhmax1 = Boardwmaxc1->y1&&Boardwmaxc1->y1=Boardwminc1->y1&&Boardc1->xhmax1!= Boardc1->xhmin1) D
33、rawPath3(c1->x,c1->y,c1->x,hmax,wmin,c1->y,wmax,c1->y,LineColor); delay(6000); DrawPath3(c1->x,c1->y,c1->x,hmax,wmin,c1->y,wmax,c1->y,BkGndColor); EraseCell(wmin,c1->y); EraseCell(c1->x,hmax); EraseCell(wmax,c1->y); Boardc1->xhmax1 =0; Boardc1->xhmax0 =0;
34、 Boardwmaxc1->y1 =0; Boardwmaxc1->y0 =0; Boardwminc1->y1 =0; Boardwminc1->y0 =0; sroce+=40; return true; /*-4個方塊相同的情況-*/ if(wmin!=-1&&Boardc1->xhmax1 = Boardwmaxc1->y1&&Boardc1->xhmax1=Boardwminc1->y1 &&Boardc1->xhmax1= Boardc1->xhmin1) AllRemove
35、(&focus); TotalTime-=5; return false;/*取鍵值 */int GetKeyCode() int key=0; if(bioskey(1) key=bioskey(0); return key;/*兩坐標畫線*/void DrawPath(int x1,int y1,int x2,int y2,int x3,int y3,int color) setcolor(color); moveto(BoardX+CellSize/2+CellSize*x1,BoardY+CellSize/2+CellSize*y1); lineto(BoardX+CellSi
36、ze/2+CellSize*x2,BoardY+CellSize/2+CellSize*y2); moveto(BoardX+CellSize/2+CellSize*x1,BoardY+CellSize/2+CellSize*y1); lineto(BoardX+CellSize/2+CellSize*x3,BoardY+CellSize/2+CellSize*y3);/*三坐標畫線*/void DrawPath3(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int color) setcolor(color); moveto
37、(BoardX+CellSize/2+CellSize*x1,BoardY+CellSize/2+CellSize*y1); lineto(BoardX+CellSize/2+CellSize*x2,BoardY+CellSize/2+CellSize*y2); moveto(BoardX+CellSize/2+CellSize*x1,BoardY+CellSize/2+CellSize*y1); lineto(BoardX+CellSize/2+CellSize*x3,BoardY+CellSize/2+CellSize*y3); moveto(BoardX+CellSize/2+CellS
38、ize*x1,BoardY+CellSize/2+CellSize*y1); lineto(BoardX+CellSize/2+CellSize*x4,BoardY+CellSize/2+CellSize*y4);/* congratulations info,the user has success finish the game ! */void DrawGameOver(char* info,int sroce) /*計算棋盤的中心點*/ int cx=BoardX+CellSize*BoardWidth/2; int cy=BoardY+CellSize*BoardHeight/2;
39、struct textsettingstype textInfos; /*獲取此前的文字信息*/ gettextsettings(&textInfos); setcolor(DARKGRAY); setfillstyle(SOLID_FILL,BLUE); /* 文字居中 */ rectangle(cx-102,cy-22,cx+102,cy+22); floodfill(cx,cy,DARKGRAY ); rectangle(cx-100,cy-20,cx+100,cy+20); settextjustify(CENTER_TEXT,CENTER_TEXT); setcolor(LI
40、GHTBLUE); sprintf(buf, "%d", sroce); outtextxy(cx+65,cy,buf); outtextxy(cx,cy,info); /*restore orignal text settings */ settextjustify(textInfos.horiz, textInfos.vert);void DrawGameOver1(char* info) /*計算棋盤的中心點*/ int cx=BoardX+CellSize*BoardWidth/2; int cy=BoardY+CellSize*BoardHeight/2; str
41、uct textsettingstype textInfos; /*獲取此前的文字信息*/ gettextsettings(&textInfos); setcolor(DARKGRAY); setfillstyle(SOLID_FILL,BLUE); /* 文字居中 */ rectangle(cx-102,cy-22,cx+102,cy+22); floodfill(cx,cy,DARKGRAY); rectangle(cx-100,cy-20,cx+100,cy+20); settextjustify(CENTER_TEXT,CENTER_TEXT); setcolor(LIGHTB
42、LUE); outtextxy(cx,cy,info); /*restore orignal text settings */ settextjustify(textInfos.horiz, textInfos.vert);/* 在x,y處用指定顏色繪制鍵為key的 CELL,key在2,3,4,5,6,7,8,9,10,11之間隨機 */void DrawCell(int key,int x,int y,int color) setcolor(color); rectangle(BoardX+x*CellSize+2, BoardY+y*CellSize+2, BoardX+(x+1)*Ce
43、llSize-3, BoardY+(y+1)*CellSize-3); setfillstyle(key, color); floodfill(BoardX+x*CellSize+3, BoardY+y*CellSize+3,color);/* 擦除CELL */void EraseCell(int x,int y) setcolor(EraColor); rectangle(BoardX+x*CellSize+2, BoardY+y*CellSize+2, BoardX+(x+1)*CellSize-3, BoardY+(y+1)*CellSize-3); setfillstyle(SOLI
44、D_FILL, BkGndColor); floodfill(BoardX+x*CellSize+3, BoardY+y*CellSize+3,EraColor); setcolor(BkGndColor); rectangle(BoardX+x*CellSize+2, BoardY+y*CellSize+2, BoardX+(x+1)*CellSize-3, BoardY+(y+1)*CellSize-3);/* 用制定顏色繪制一個選中的外邊框 */void DrawBorderRect(CELL *c,int color) setcolor(color); rectangle(BoardX
45、+(c->x)*CellSize+1, BoardY+(c->y)*CellSize+1, BoardX+(c->x+1)*CellSize-2, BoardY+(c->y+1)*CellSize-2); rectangle(BoardX+(c->x)*CellSize, BoardY+(c->y)*CellSize, BoardX+(c->x+1)*CellSize-1, BoardY+(c->y+1)*CellSize-1);/* 初始化進度條 */void InitProgressBar() int width=CellSize*Board
46、Width; /* progress bar border rect */ setcolor(BorderColor); rectangle(BoardX-2,PbY-2,BoardX+width+2,PbY+PbHeight+2); /* draw a value = 100% progress bar */ setcolor(PbColor); rectangle(BoardX,PbY,BoardX+width,PbY+PbHeight); setfillstyle(SOLID_FILL,PbColor); floodfill(BoardX+1,PbY+1,PbColor);/* 更新進度條,設置為某個百分比 */void UpdateProgressBar(int percent) int p=percent; int width; if(percent<0) p=0; else if(per
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 湘潭醫(yī)衛(wèi)職業(yè)技術學院《交通設施設計》2023-2024學年第二學期期末試卷
- 山東管理學院《化工制圖與AutoCAD》2023-2024學年第二學期期末試卷
- 青海高等職業(yè)技術學院《現代秘書學》2023-2024學年第二學期期末試卷
- 泰山學院《機器學習實驗》2023-2024學年第二學期期末試卷
- 沈陽工程學院《室內專題項目生態(tài)性居住空間設計》2023-2024學年第二學期期末試卷
- 淮北師范大學《食品安全與營養(yǎng)》2023-2024學年第二學期期末試卷
- 鐵門關職業(yè)技術學院《數字特效制作》2023-2024學年第二學期期末試卷
- 廣東舞蹈戲劇職業(yè)學院《特殊學校語文課程與教學》2023-2024學年第二學期期末試卷
- 山西華澳商貿職業(yè)學院《嵌入式系統(tǒng)設計實驗》2023-2024學年第二學期期末試卷
- 云南國土資源職業(yè)學院《數字游戲角色設計》2023-2024學年第二學期期末試卷
- 浸出液的凈化與沉積
- 校本課程《生活中的化學》教案
- 寶典三猿金錢錄
- 苯乙酸安全技術說明書(msds)
- 安徽凌瑋新材料科技有限公司年產2萬噸超細二氧化硅氣凝膠系列產品項目環(huán)境影響報告書
- 聚合物粘彈性
- 幼兒園大班《防欺凌》教案5篇,幼兒園大班防欺凌活動教案
- 華銀鋁項目氧化鋁系統(tǒng)總體投料試車方案
- 《當代網絡文學作品發(fā)展研究6300字(論文)》
- 孟氏骨折與蓋氏骨折講解學習
- GB/T 9386-2008計算機軟件測試文檔編制規(guī)范
評論
0/150
提交評論