十字消方块源代码Word格式文档下载.docx
《十字消方块源代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《十字消方块源代码Word格式文档下载.docx(23页珍藏版)》请在冰豆网上搜索。
/*开始时间的秒数,只统计分钟,秒*/
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);
floodfill(60,190,WHITE);
/*右方块*/
rectangle(150,200,170,180);
setfillstyle(4,WHITE);
floodfill(160,190,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);
rectangle(100+350,200,120+350,180);
rectangle(100+350,150,120+350,130);
floodfill(110+350,140,WHITE);
rectangle(150+350,200,170+350,180);
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);
y,c1->
x,hmax,wmax,c1->
y,LineColor);
delay(6000);
x,hmin,BkGndColor);
y,BkGndColor);
EraseCell(wmin,c1->
y);
EraseCell(wmax,c1->
EraseCell(c1->
x,hmin);
x,hmax);
Board[c1->
x][hmin][1]=0;
x][hmax][1]=0;
x][hmin][0]=0;
x][hmax][0]=0;
Board[wmin][c1->
y][1]=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]!
break;
}
while(wmax<
BoardWidth)
wmax++;
if(Board[wmax][c1->
/*---------------查找垂直方向遇到的两个方块的坐标----------*/
hmin=hmax=c1->
y;
while(hmin>
hmin--;
if(Board[c1->
x][hmin][0]!
while(hmax<
BoardHeight)
hmax++;
if(Board[c1->
x][hmax][0]!
/*---------------方块两两相同的情况------------*/
/*(wmin,y)与(wmax,y)相同的情况*/
if(wmin!
=-1&
&
wmax!
=BoardWidth&
(Board[wmin][c1->
y][1]==Board[wmax][c1->
y][1])&
y][1]!
=Board[c1->
x][hmin][1])&
x][hmax][1]))
x][hmin][1]==Board[c1->
x][hmax][1]&
hmin!
hmax!
=BoardHeight)
AllRemove(&
focus);
else
y,wmax,c1->
sroce+=20;
/*(wmin,y)与(x,hmin)相同的情况*/
Board[wmin][c1->
y][1]==Boa