推箱子游戏代码.docx
- 文档编号:30143296
- 上传时间:2023-08-05
- 格式:DOCX
- 页数:30
- 大小:17.23KB
推箱子游戏代码.docx
《推箱子游戏代码.docx》由会员分享,可在线阅读,更多相关《推箱子游戏代码.docx(30页珍藏版)》请在冰豆网上搜索。
推箱子游戏代码
#include
#include
#include
#include
#include
#include
typedefstructwiner
{
intx,y;
structwiner*p;
}winer;
charstatus[20][20];
charfar*printScreen=(charfar*)0xB8000000;
voidputoutChar(inty,intx,charch,charfc,charbc);
voidprintWall(intx,inty);
voidprintBox(intx,inty);
voidprintBoxDes(intx,inty);
voidprintDestination(intx,inty);
voidprintDestination1(intx,inty,winer**win,winer**pw);
voidprintMan(intx,inty);
voidinit();
winer*initStep1();
winer*initStep2();
winer*initStep3();
winer*initStep4();
voidmoveBoxSpacetoSpace(intx,inty,chara);
voidmoveBoxDestoSpace(intx,inty,chara);
voidmoveBoxSpacetoDes(intx,inty,chara);
voidmoveBoxDestoDes(intx,inty,chara);
intjudge(intx,inty);
voidmove(intx,inty,chara);
voidreset(inti);
voidputoutChar(inty,intx,charch,charfc,charbc)
{
printScreen[(x*160)+(y<<1)+0]=ch;
printScreen[(x*160)+(y<<1)+1]=(bc*16)+fc;
}
voidprintWall(intx,inty)
{
putoutChar(y-1,x-1,219,GREEN,BLACK);
status[x][y]='w';
}
voidprintBox(intx,inty)
{
putoutChar(y-1,x-1,10,WHITE,BLACK);
status[x][y]='b';
}
voidprintDestination1(intx,inty,winer**win,winer**pw)
{
winer*qw;
putoutChar(y-1,x-1,003,YELLOW,BLACK);
status[x][y]='m';
if(*win==NULL)
{
*win=*pw=qw=(winer*)malloc(sizeof(winer));
(*pw)->x=x;
(*pw)->y=y;
(*pw)->p=NULL;
}
else
{
qw=(winer*)malloc(sizeof(winer));
qw->x=x;
qw->y=y;
(*pw)->p=qw;
(*pw)=qw;qw->p=NULL;
}
}
voidprintDestination(intx,inty)
{
putoutChar(y-1,x-1,003,YELLOW,BLACK);
status[x][y]='m';
}
voidprintMan(intx,inty)
{
gotoxy(y,x);
_AL=02;
_CX=01;
_AH=0xa;
geninterrupt(0x10);
}
voidprintBoxDes(intx,inty)
{
putoutChar(y-1,x-1,10,YELLOW,BLACK);
status[x][y]='i';
}
voidinit()
{
inti,j;
for(i=0;i<20;i++)
for(j=0;j<20;j++)
status[i][j]=0;
_AL=3;
_AH=0;
geninterrupt(0x10);
gotoxy(40,4);
printf("Welcometotheboxworld!
");
gotoxy(40,6);
printf("Youcanuseup,down,left,");
gotoxy(40,8);
printf("rightkeytocontrolit,or");
gotoxy(40,10);
printf("youcanpressEsctoquitit.");
gotoxy(40,12);
printf("Pressspacetoresetthegame.");
gotoxy(40,14);
printf("Wishyouhaveagoodtime!
");
gotoxy(40,16);
printf("December,2015");
}
winer*initStep1()
{
intx;
inty;
winer*win=NULL;
winer*pw;
for(x=1,y=5;y<=9;y++)
printWall(x+4,y+10);
for(y=5,x=2;x<=5;x++)
printWall(x+4,y+10);
for(y=9,x=2;x<=5;x++)
printWall(x+4,y+10);
for(y=1,x=3;x<=8;x++)
printWall(x+4,y+10);
for(x=3,y=3;x<=5;x++)
printWall(x+4,y+10);
for(x=5,y=8;x<=9;x++)
printWall(x+4,y+10);
for(x=7,y=4;x<=9;x++)
printWall(x+4,y+10);
for(x=9,y=5;y<=7;y++)
printWall(x+4,y+10);
for(x=8,y=2;y<=3;y++)
printWall(x+4,y+10);
printWall(5+4,4+10);
printWall(5+4,7+10);
printWall(3+4,2+10);
printBox(3+4,6+10);
printBox(3+4,7+10);
printBox(4+4,7+10);
printDestination1(4+4,2+10,&win,&pw);
printDestination1(5+4,2+10,&win,&pw);
printDestination1(6+4,2+10,&win,&pw);
printMan(2+4,8+10);
returnwin;
}
winer*initStep2()
{
intx;
inty;
winer*win=NULL;
winer*pw;
for(x=1,y=4;y<=7;y++)
printWall(x+4,y+10);
for(x=2,y=2;y<=4;y++)
printWall(x+4,y+10);
for(x=2,y=7;x<=4;x++)
printWall(x+4,y+10);
for(x=4,y=1;x<=8;x++)
printWall(x+4,y+10);
for(x=8,y=2;y<=8;y++)
printWall(x+4,y+10);
for(x=4,y=8;x<=8;x++)
printWall(x+4,y+10);
for(x=4,y=6;x<=5;x++)
printWall(x+4,y+10);
for(x=3,y=2;x<=4;x++)
printWall(x+4,y+10);
for(x=4,y=4;x<=5;x++)
printWall(x+4,y+10);
printWall(6+4,3+10);
printBox(3+4,5+10);
printBox(6+4,6+10);
printBox(7+4,3+10);
printDestination1(5+4,7+10,&win,&pw);
printDestination1(6+4,7+10,&win,&pw);
printDestination1(7+4,7+10,&win,&pw);
printMan(2+4,6+10);
returnwin;
}
winer*initStep3()
{
intx;
inty;
winer*win=NULL;
winer*pw;
for(x=1,y=2;y<=8;y++)
printWall(x+4,y+10);
for(x=2,y=2;x<=4;x++)
printWall(x+4,y+10);
for(x=4,y=1;y<=3;y++)
printWall(x+4,y+10);
for(x=5,y=1;x<=8;x++)
printWall(x+4,y+10);
for(x=8,y=2;y<=5;y++)
printWall(x+4,y+10);
for(x=5,y=5;x<=7;x++)
printWall(x+4,y+10);
for(x=7,y=6;y<=9;y++)
printWall(x+4,y+10);
for(x=3,y=9;x<=6;x++)
printWall(x+4,y+10);
for(x=3,y=6;y<=8;y++)
printWall(x+4,y+10);
printWall(2+4,8+10);
printWall(5+4,7+10);
printBox(6+4,3+10);
printBox(4+4,4+10);
printBox(5+4,6+10);
printDestination1(2+4,5+10,&win,&pw);
printDestination1(2+4,6+10,&win,&pw);
printDestination1(2+4,7+10,&win,&pw);
printMan(2+4,4+10);
returnwin;
}
winer*initStep4()
{
intx;
inty;
winer*win=NULL;
winer*pw;
for(x=1,y=1;y<=6;y++)
printWall(x+4,y+10);
for(x=2,y=7;y<=8;y++)
printWall(x+4,y+10);
for(x=2,y=1;x<=7;x++)
printWall(x+4,y+10);
for(x=7,y=2;y<=4;y++)
printWall(x+4,y+10);
for(x=6,y=4;y<=9;y++)
printWall(x+4,y+10);
for(x=3,y=9;x<=5;x++)
printWall(x+4,y+10);
for(x=3,y=3;y<=4;y++)
printWall(x+4,y+10);
printWall(3+4,8+10);
printBox(3+4,5+10);
printBox(4+4,4+10);
printBox(4+4,6+10);
printBox(5+4,5+10);
printBox(5+4,3+10);
printDestination1(3+4,7+10,&win,&pw);
printDestination1(4+4,7+10,&win,&pw);
printDestination1(5+4,7+10,&win,&pw);
printDestination1(4+4,8+10,&win,&pw);
printDestination1(5+4,8+10,&win,&pw);
printMan(2+4,2+10);
returnwin;
}
voidmoveBoxSpacetoSpace(intx,inty,chara)
{
switch(a)
{
case'u':
status[x-1][y]=0;
printf("");
printBox(x-2,y);
printMan(x-1,y);
status[x-2][y]='b';
break;
case'd':
status[x+1][y]=0;
printf("");
printBox(x+2,y);
printMan(x+1,y);
status[x+2][y]='b';
break;
case'l':
status[x][y-1]=0;
printf("");
printBox(x,y-2);
printMan(x,y-1);
status[x][y-2]='b';
break;
case'r':
status[x][y+1]=0;
printf("");
printBox(x,y+2);
printMan(x,y+1);
status[x][y+2]='b';
break;
default:
break;
}
}
voidmoveBoxDestoSpace(intx,inty,chara)
{
switch(a)
{
case'u':
status[x-1][y]='m';
printf("");
printBox(x-2,y);
printMan(x-1,y);
status[x-2][y]='b';
break;
case'd':
status[x+1][y]='m';
printf("");
printBox(x+2,y);
printMan(x+1,y);
status[x+2][y]='b';
break;
case'l':
status[x][y-1]='m';
printf("");
printBox(x,y-2);
printMan(x,y-1);
status[x][y-2]='b';
break;
case'r':
status[x][y+1]='m';
printf("");
printBox(x,y+2);
printMan(x,y+1);
status[x][y+2]='b';
break;
default:
break;
}
}
voidmoveBoxSpacetoDes(intx,inty,chara)
{
switch(a)
{
case'u':
status[x-1][y]=0;
printf("");
printBoxDes(x-2,y);
printMan(x-1,y);
status[x-2][y]='i';
break;
case'd':
status[x+1][y]=0;
printf("");
printBoxDes(x+2,y);
printMan(x+1,y);
status[x+2][y]='i';
break;
case'l':
status[x][y-1]=0;
printf("");
printBoxDes(x,y-2);
printMan(x,y-1);
status[x][y-2]='i';
break;
case'r':
status[x][y+1]=0;
printf("");
printBoxDes(x,y+2);
printMan(x,y+1);
status[x][y+2]='i';
break;
default:
break;
}
}
voidmoveBoxDestoDes(intx,inty,chara)
{
switch(a)
{
case'u':
status[x-1][y]='m';
printf("");
printBoxDes(x-2,y);
printMan(x-1,y);
status[x-2][y]='i';
break;
case'd':
status[x+1][y]='m';
printf("");
printBoxDes(x+2,y);
printMan(x+1,y);
status[x+2][y]='i';
break;
case'l':
status[x][y-1]='m';
printf("");
printBoxDes(x,y-2);
printMan(x,y-1);
status[x][y-2]='i';
break;
case'r':
status[x][y+1]='m';
printf("");
printBoxDes(x,y+2);
printMan(x,y+1);
status[x][y+2]='i';
break;
default:
break;
}
}
intjudge(intx,inty)
{
inti;
switch(status[x][y])
{
case0:
i=1;
break;
case'w':
i=0;
break;
case'b':
i=2;
break;
case'i':
i=4;
break;
case'm':
i=3;
break;
default:
break;
}
returni;
}
voidmove(intx,inty,chara)
{
switch(a)
{
case'u':
if(!
judge(x-1,y))
{
gotoxy(y,x);
break;
}
elseif(judge(x-1,y)==1||judge(x-1,y)==3)
{
if(judge(x,y)==3)
{
printDestination(x,y);
printMan(x-1,y);
break;
}
else
{
printf("");
printMan(x-1,y);
break;
}
}
elseif(judge(x-1,y)==2)
{
if(judge(x-2,y)==1)
{
moveBoxSpacetoSpace(x,y,'u');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x-1);
}
elseif(judge(x-2,y)==3)
{
moveBoxSpacetoDes(x,y,'u');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x-1);
}
else
gotoxy(y,x);
break;
}
elseif(judge(x-1,y)==4)
{
if(judge(x-2,y)==1)
{
moveBoxDestoSpace(x,y,'u');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x-1);
}
elseif(judge(x-2,y)==3)
{
moveBoxDestoDes(x,y,'u');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x-1);
}
else
gotoxy(y,x);
break;
}
case'd':
if(!
judge(x+1,y))
{
gotoxy(y,x);
break;
}
elseif(judge(x+1,y)==1||judge(x+1,y)==3)
{
if(judge(x,y)==3)
{
printDestination(x,y);
printMan(x+1,y);
break;
}
else
{
printf("");
printMan(x+1,y);
break;
}
}
elseif(judge(x+1,y)==2)
{
if(judge(x+2,y)==1)
{
moveBoxSpacetoSpace(x,y,'d');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x+1);
}
elseif(judge(x+2,y)==3)
{
moveBoxSpacetoDes(x,y,'d');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x+1);
}
else
gotoxy(y,x);
break;
}
elseif(judge(x+1,y)==4)
{
if(judge(x+2,y)==1)
{
moveBoxDestoSpace(x,y,'d');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x+1);
}
elseif(judge(x+2
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 箱子 游戏 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)