版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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;/* 消除一對(duì)方塊時(shí)時(shí)候的連線顏色 */* Pb - ProgressBar */int PbColor
2、=YELLOW;int PbY=30;int PbHeight=4;int PbValue; /* 進(jìn)度條百分比,初始值為100.*/long StartTime; /* 開(kāi)始時(shí)間的秒數(shù),只統(tǒng)計(jì)分鐘,秒 */long TotalTime; /* 游戲總共的最大秒數(shù)!,*/* 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; /*方塊對(duì)的數(shù)量*/int CellCount=0; /*剩余方塊的數(shù)量*/char buf100;int sroce; /*游戲得分*/int wmin,wmax,hmin,hmax;/* 用于存儲(chǔ)邏輯坐標(biāo)(索引) */typedef struct _tagCELL c
4、har x; char y; CELL;CELL focus;/*定義焦點(diǎn)*/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 */;/* -函數(shù)列表- */void InitGame(char *bgiPath); /*初始化游戲方塊*/void PlayGame();void QuitGame();void
5、InitProgressBar(); /*初始化進(jìn)度條*/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) /*-查找水平方向遇到兩個(gè)方塊的坐標(biāo)-*/ wmin=wmax=c1->x; while(wmin>=0) wmin-; if( Boardwminc1->y0!=0) break; while(wmax<BoardWidth) wmax+; if(Boardwmaxc1->y0
13、!=0) break; /*-查找垂直方向遇到的兩個(gè)方塊的坐標(biāo)-*/ 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個(gè)方塊相同的情況-*/ 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個(gè)方塊相同的情況-*/ 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;/*兩坐標(biāo)畫線*/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);/*三坐標(biāo)畫線*/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) /*計(jì)算棋盤的中心點(diǎn)*/ 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) /*計(jì)算棋盤的中心點(diǎn)*/ 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之間隨機(jī) */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);/* 用制定顏色繪制一個(gè)選中的外邊框 */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);/* 初始化進(jìn)度條 */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);/* 更新進(jìn)度條,設(shè)置為某個(gè)百分比 */void UpdateProgressBar(int percent) int p=percent; int width; if(percent<0) p=0; else if(per
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- A證(企業(yè)負(fù)責(zé)人)-安全員A證考試模擬題練習(xí)
- 滬科版九年級(jí)物理全一冊(cè)《第十七章從指南針到磁浮列車》章末測(cè)試卷含答案
- 國(guó)企工會(huì)換屆上的領(lǐng)導(dǎo)講話-凝聚奮進(jìn)力量 彰顯工會(huì)作為
- 科技孵化器入駐企業(yè)潛力篩選
- 電力系統(tǒng)設(shè)備故障預(yù)防與處理流程
- 高一化學(xué)二第三章有機(jī)化合物練習(xí)
- 2024屆安徽省示范高中培優(yōu)聯(lián)盟高考化學(xué)三模試卷含解析
- 2024高中地理第3章地理信息技術(shù)應(yīng)用第2節(jié)遙感技術(shù)及其應(yīng)用學(xué)案湘教版必修3
- 2024高中物理第二章交變電流第二節(jié)交變電流的描述達(dá)標(biāo)作業(yè)含解析粵教版選修3-2
- 2024高中語(yǔ)文第一單元以意逆志知人論世書憤訓(xùn)練含解析新人教版選修中國(guó)古代詩(shī)歌散文欣賞
- 紫草科旋花科馬鞭草科唇形科茄科課件
- 物品移交登記表格模板
- 超市會(huì)員流程制度
- 干部履歷表(A4版)
- 電梯維修協(xié)議書
- 安徽省安慶市四中學(xué)2023-2024學(xué)年七年級(jí)數(shù)學(xué)第一學(xué)期期末學(xué)業(yè)質(zhì)量監(jiān)測(cè)試題含解析
- 礦工睡崗檢查書
- 《道德經(jīng)》(老子)課件
- 仁恒江灣城修建幕墻工程監(jiān)理實(shí)施細(xì)則
- 廣東省佛山南海區(qū)四校聯(lián)考2023屆中考試題猜想數(shù)學(xué)試卷含解析
- 2023年江蘇蘇州工業(yè)園區(qū)管委會(huì)招聘筆試參考題庫(kù)附帶答案詳解
評(píng)論
0/150
提交評(píng)論