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0,1,2,1,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
}
};
void initgr(void) /* BGI初始化 */
{
int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果。分辨率:640*480 */
registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gd, &gm, "");
}
void drawmat(char *mat,int matsize,int x,int y,int color)
/*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/
{
int i, j, k, n;
n = (matsize - 1) / 8 + 1;
for(j = 0; j < matsize; j++)
for(i = 0; i < n; i++)
for(k = 0;k < 8; k++)
if(mat[j * n + i] & (0x80 >> k)) /*测试为1的位则显示*/
putpixel(x + i * 8 + k, y + j, color);
}
void DrawBlock(int y,int x,int flag)
{
int oldcolor=getcolor();
struct fillsettingstype OldInfo;
int xx=GAME_AREA_X+x*BLOCK_X+1;
int yy=GAME_AREA_Y+y*BLOCK_Y+1;
getfillsettings(&OldInfo);
switch(flag)
{
case EMPTY:
setfillstyle(SOLID_FILL, BK_COLOR);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
break;
case WALL:
setfillstyle(SOLID_FILL,BK_COLOR);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
setcolor(WHITE);
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2) ;
line(xx,yy,xx+BLOCK_X-2,yy) ;
line(xx,yy,xx,yy+BLOCK_Y-2) ;
line(xx,yy+BLOCK_Y/2+1,xx+BLOCK_X-2,yy+BLOCK_Y/2) ;
line(xx+BLOCK_X/2,yy+BLOCK_Y/2,xx+BLOCK_X/2,yy+BLOCK_Y-2) ;
setcolor(BLACK);
line(xx,yy+BLOCK_Y/2,xx+BLOCK_X-2,yy+BLOCK_Y/2) ;
break;
case BOX:
setfillstyle(SOLID_FILL, BK_COLOR);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, YELLOW);
bar(xx+2,yy+2,xx+BLOCK_X-4,yy+BLOCK_Y-4);
rectangle(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
break;
case MAN:
setfillstyle(SOLID_FILL, BK_COLOR);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
setcolor(WHITE);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/4,4);
circle(xx+BLOCK_X/2,yy+BLOCK_Y*2/3,8);
line(xx,yy+BLOCK_Y/2,xx+BLOCK_X-2,yy+BLOCK_Y/2);
break;
case BALL:
setfillstyle(SOLID_FILL, BK_COLOR);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
setcolor(GREEN);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/2,6);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/2,10);
break;
case MANBALL:
setfillstyle(SOLID_FILL, BK_COLOR);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
setcolor(GREEN);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/2,6);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/2,10);
setcolor(WHITE);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/4,4);
circle(xx+BLOCK_X/2,yy+BLOCK_Y*2/3,8);
line(xx,yy+BLOCK_Y/2,xx+BLOCK_X-2,yy+BLOCK_Y/2);
break;
case BOXBALL:
setfillstyle(SOLID_FILL, BK_COLOR);
bar(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
setcolor(GREEN);
setfillstyle(SOLID_FILL, YELLOW);
bar(xx+2,yy+2,xx+BLOCK_X-4,yy+BLOCK_Y-4);
rectangle(xx,yy,xx+BLOCK_X-2,yy+BLOCK_Y-2);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/2,6);
circle(xx+BLOCK_X/2,yy+BLOCK_Y/2,10);
break;
}
setcolor(oldcolor);
setfillstyle(OldInfo.pattern,OldInfo.color);
}
void GetManPosition()
{
int i,j;
for (i=0;i<MAP_Y_NUM;i++)
{
for (j=0;j<MAP_X_NUM;j++)
{
if (map[NowLevel][i][j]==MANBALL||map[NowLevel][i][j]==MAN)
{
goto A;
}
}
}
A:
Manx=j;
Many=i;
}
void GameInit()
{
int i,j;
cleardevice();
i=getmaxx()/2;
drawmat(tui32L,32,i-80,10 ,YELLOW);
drawmat(xiang32L,32,i-32,10 ,YELLOW);
drawmat(zi32L,32,i+16,10 ,YELLOW);
for(i=0;i<MAP_Y_NUM;i++)
{
for(j=0;j<MAP_X_NUM;j++)
{
DrawBlock(i,j,map[NowLevel][i][j]);
}
}
GetManPosition();
gotoxy(1,1);
printf("Now Level:%2d",NowLevel+1);
gotoxy(1,2);
printf("Max Level:%2d",MAX_LEVEL);
}
void UpdataMap(int x1,int y1,int x2,int y2,int x3,int y3)
{
switch (map[NowLevel][y2][x2])
{
case EMPTY:
map[NowLevel][y2][x2]=MAN;
if (map[NowLevel][y1][x1]==MAN)
{
map[NowLevel][y1][x1]=EMPTY;
}
else if(map[NowLevel][y1][x1]==MANBALL)
{
map[NowLevel][y1][x1]=BALL;
}
Manx=x2;
Many=y2;
break;
case BALL:
map[NowLevel][y2][x2]=MANBALL;
if (map[NowLevel][y1][x1]==MAN)
{
map[NowLevel][y1][x1]=EMPTY;
}
else if (map[NowLevel][y1][x1]==MANBALL)
{
map[NowLevel][y1][x1]=BALL;
}
Manx=x2;
Many=y2;
break;
case BOX:
if(map[NowLevel][y3][x3]==BALL)
{
map[NowLevel][y3][x3]=BOXBALL;
map[NowLevel][y2][x2]=MAN;
if (map[NowLevel][y1][x1]==MAN)
{
map[NowLevel][y1][x1]=EMPTY;
}
else if (map[NowLevel][y1][x1]==MANBALL)
{
map[NowLevel][y1][x1]=BALL;
}
Manx=x2;
Many=y2;
}
else if (map[NowLevel][y3][x3]==EMPTY)
{
map[NowLevel][y3][x3]=BOX;
map[NowLevel][y2][x2]=MAN;
if (map[NowLevel][y1][x1]==MAN)
{
map[NowLevel][y1][x1]=EMPTY;
}
else if (map[NowLevel][y1][x1]==MANBALL)
{
map[NowLevel][y1][x1]=BALL;
}
Manx=x2;
Many=y2;
}
break;
case BOXBALL:
if (map[NowLevel][y3][x3]==BALL)
{
map[NowLevel][y3][x3]=BOXBALL;
map[NowLevel][y2][x2]=MANBALL;
if (map[NowLevel][y1][x1]==MAN)
{
map[NowLevel][y1][x1]=EMPTY;
}
else if (map[NowLevel][y1][x1]==MANBALL)
{
map[NowLevel][y1][x1]=BALL;
}
Manx=x2;
Many=y2;
}
else if (map[