十字消方块源代码.docx
- 文档编号:2438229
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:23
- 大小:19.29KB
十字消方块源代码.docx
《十字消方块源代码.docx》由会员分享,可在线阅读,更多相关《十字消方块源代码.docx(23页珍藏版)》请在冰豆网上搜索。
十字消方块源代码
/*方块十字消游戏源代码*/
#include
#include
#include
#include
#include
#definetrue1
#definefalse0
/*---------------------全局变量------------------------------------*/
intBkGndColor=BLACK;
intBorderColor=LIGHTGRAY;
intLineColor=LIGHTBLUE;/*消除一对方块时时候的连线颜色*/
/*Pb-ProgressBar*/
intPbColor=YELLOW;
intPbY=30;
intPbHeight=4;
intPbValue;/*进度条百分比,初始值为100.*/
longStartTime;/*开始时间的秒数,只统计分钟,秒*/
longTotalTime;/*游戏总共的最大秒数!
,*/
/*BoardDatas:
asmall-sizeboard*/
/*Board[x][y][0]-0:
empty,1:
filled*/
/*Board[x][y][1]-cell'skey;*/
unsignedcharBoard[15][15][2];
intCellSize=20;
intBoardX=170;
intBoardY=70;
intBoardWidth=15;
intBoardHeight=15;
intCellColor=WHITE;
intFocus=RED;/*focus'sborderrectcolor*/
intEraColor=CYAN;/*用于擦除cell的颜色!
*/
intPairsCount;/*方块对的数量*/
intCellCount=0;/*剩余方块的数量*/
charbuf[100];
intsroce;/*游戏得分*/
intwmin,wmax,hmin,hmax;
/*用于存储逻辑坐标(索引)*/
typedefstruct_tagCELL
{
charx;
chary;
}CELL;
CELLfocus;/*定义焦点*/
enumKEYCODES
{
K_ESC=0x011b,
K_UP=0x4800,/*upwardarrow*/
K_LEFT=0x4b00,
K_DOWN=0x5000,
K_RIGHT=0x4d00,
K_SPACE=0x3920,
K_P=0x1970,
K_RETURN=0x1c0d,/*Enter*/
};
/*---------------------函数列表------------------------------------*/
voidInitGame(char*bgiPath);/*初始化游戏方块*/
voidPlayGame();
voidQuitGame();
voidInitProgressBar();/*初始化进度条*/
voidUpdateProgressBar(intpercent);
voidDrawCell(intkey,intx,inty,intcolor);
voidEraseCell(intx,inty);
voidDrawBorderRect(CELL*c,intcolor);
voidDrawGameOver(char*info,intsroce);
intGetKeyCode();
intFindPath(CELL*c1);
voidstart();
voidDrawPath(intx1,inty1,intx2,inty2,intx3,inty3,intcolor);
voidDrawPath3(intx1,inty1,intx2,inty2,intx3,inty3,intx4,inty4,intcolor);
voidstart()
{
intgdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
setcolor(YELLOW);
/*中方块*/
setcolor(RED);
rectangle(100,200,120,180);
/*上方块*/
setcolor(WHITE);
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,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,180);
/*上方块*/
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,"Pleasedothefollowingtipsstartthegame!
");
outtextxy(200,320,"pressanykeytocontinue");
outtextxy(220,340,"--byjunjie2012");
}
intAllRemove(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,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);
Board[c1->x][hmin][1]=0;
Board[c1->x][hmax][1]=0;
Board[c1->x][hmin][0]=0;
Board[c1->x][hmax][0]=0;
Board[wmin][c1->y][1]=0;
Board[wmax][c1->y][1]=0;
Board[wmin][c1->y][0]=0;
Board[wmax][c1->y][0]=0;
sroce+=60;
returntrue;
}
intFindPath(CELL*c1)
{
/*---------------查找水平方向遇到两个方块的坐标-----------*/
wmin=wmax=c1->x;
while(wmin>=0)
{
wmin--;
if(Board[wmin][c1->y][0]!
=0)
break;
}
while(wmax { wmax++; if(Board[wmax][c1->y][0]! =0) break; } /*---------------查找垂直方向遇到的两个方块的坐标----------*/ hmin=hmax=c1->y; while(hmin>=0) { hmin--; if(Board[c1->x][hmin][0]! =0) break; } while(hmax { hmax++; if(Board[c1->x][hmax][0]! =0) break; } /*---------------方块两两相同的情况------------*/ /*(wmin,y)与(wmax,y)相同的情况*/ if(wmin! =-1&&wmax! =BoardWidth&&(Board[wmin][c1->y][1]==Board[wmax][c1->y][1])&&(Board[wmin][c1->y][1]! =Board[c1->x][hmin][1])&&(Board[wmin][c1->y][1]! =Board[c1->x][hmax][1])) { if(Board[c1->x][hmin][1]==Board[c1->x][hmax][1]&&hmin! =-1&&hmax! =BoardHeight) { AllRemove(&focus); } else { DrawPath(c1->x,c1->y,wmin,c1->y,wmax,c1->y,LineColor); delay(6000); DrawPath(c1->x,c1->y,wmin,c1->y,wmax,c1->y,BkGndColor); EraseCell(wmin,c1->y); EraseCell(wmax,c1->y); Board[wmax][c1->y][0]=0; Board[wmax][c1->y][1]=0; Board[wmin][c1->y][0]=0; Board[wmin][c1->y][1]=0; sroce+=20; returntrue; } } /*(wmin,y)与(x,hmin)相同的情况*/ if(wmin! =-1&&hmin! =-1&&Board[wmin][c1->y][1]==Boa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 十字 方块 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)