推箱子 C语言程序 报告.docx
- 文档编号:11854095
- 上传时间:2023-04-06
- 格式:DOCX
- 页数:21
- 大小:52.27KB
推箱子 C语言程序 报告.docx
《推箱子 C语言程序 报告.docx》由会员分享,可在线阅读,更多相关《推箱子 C语言程序 报告.docx(21页珍藏版)》请在冰豆网上搜索。
推箱子C语言程序报告
课程设计
设计课题:
推箱子程序编写
一.课程设计要求
1.初始化模块
2.画图模块
3.移动箱子模块
4.移动小人模块
5.选关模块
二.心得体会
三.设计流程图
四.源程序清单
#include
#include
#include
#include
#include
#include
#include
charghouse[20][20];
charfar*screen=(charfar*)0xb8000000;
voidputchxy(inty,intx,charch,charfc,charbc)
{
screen[(x*160)+(y<<1)+0]=ch;
screen[(x*160)+(y<<1)+1]=(bc*16)+fc;
}
/*定义判断是否胜利的数据结构*/
typedefstructwiner{
intx,y;
structwiner*p;
}winer;
/*箱子位置的数据结构*/
typedefstructboxs{
intx,y;
structboxs*next;
}boxs;
/*在特定的坐标上画墙壁并用数组记录状态的函数*/
voidprintwall(intx,inty)
{
putchxy(y-1,x-1,21,RED,BLACK);
ghouse[x][y]='w';
}
/*在特定的坐标上画箱子并用数组记录状态的函数*/
voidprintbox(intx,inty)
{
putchxy(y-1,x-1,9,WHITE,BLACK);
ghouse[x][y]='b';
}
/*在特定的坐标上画目的地并用数组记录状态的函数*/
voidprintwhither1(intx,inty,winer**win,winer**pw)
{
winer*qw;
putchxy(y-1,x-1,'*',GREEN,BLACK);
ghouse[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;
}
}
/*在特定的坐标上画目的地并用数组记录状态的函数*/
voidprintwhither(intx,inty)
{
putchxy(y-1,x-1,'*',GREEN,BLACK);
ghouse[x][y]='m';
}
/*在特定的坐标上画人的函数*/
voidprintman(intx,inty)
{
gotoxy(y,x);
_AL=02;_CX=01;_AH=0xa;
geninterrupt(0x10);
}
/*在特定的坐标上画箱子在目的地上并用数组记录状态的函数*/
voidprintboxin(intx,inty)
{
putchxy(y-1,x-1,10,GREEN,BLACK);
ghouse[x][y]='i';
}
/*初始化函数,初始化数组和屏幕*/
voidinit()
{
inti,j;
system("cls");
for(i=0;i<20;i++)
for(j=0;j<20;j++)
ghouse[i][j]=0;
_AL=3;
_AH=0;
geninterrupt(0x10);
gotoxy(40,4);
printf("GameStar!
");
gotoxy(40,8);
printf("Pressup,down,left,righttoplay.");
gotoxy(40,12);
printf("PressEsctoquitit.");
gotoxy(40,10);
printf("Pressspacetoresetthegame.");
gotoxy(40,6);
printf("Youcanpress1-3tochiocethegame.");
}
/*第一关的图象初始化*/
winer*inithouse1()
{intx,y;
winer*win=NULL,*pw;
gotoxy(8,3);
printf("LevelNo.1");
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);
printwhither1(2+4,5+10,&win,&pw);
printwhither1(2+4,6+10,&win,&pw);
printwhither1(2+4,7+10,&win,&pw);
printman(2+4,4+10);
returnwin;
}
/*第二关的图象初始化*/
winer*inithouse2()
{intx,y;
winer*win=NULL,*pw;
gotoxy(8,2);
printf("LevelNo.2");
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);
printwhither1(5+4,7+10,&win,&pw);
printwhither1(6+4,7+10,&win,&pw);
printwhither1(7+4,7+10,&win,&pw);
printman(2+4,6+10);
returnwin;
}
/*第三关的图象初始化*/
winer*inithouse3()
{intx,y;
winer*win=NULL,*pw;
gotoxy(8,2);
printf("LevelNo.3");
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);
printwhither1(3+4,7+10,&win,&pw);
printwhither1(4+4,7+10,&win,&pw);
printwhither1(5+4,7+10,&win,&pw);
printwhither1(4+4,8+10,&win,&pw);
printwhither1(5+4,8+10,&win,&pw);
printman(2+4,2+10);
returnwin;
}
/*移动在空地上的箱子到空地上*/
movebox(intx,inty,chara)
{switch(a)
{
case'u':
ghouse[x-1][y]=0;printf("");
printbox(x-2,y);printman(x-1,y);
ghouse[x-2][y]='b';break;
case'd':
ghouse[x+1][y]=0;printf("");
printbox(x+2,y);printman(x+1,y);
ghouse[x+2][y]='b';break;
case'l':
ghouse[x][y-1]=0;printf("");
printbox(x,y-2);printman(x,y-1);
ghouse[x][y-2]='b';break;
case'r':
ghouse[x][y+1]=0;printf("");
printbox(x,y+2);printman(x,y+1);
ghouse[x][y+2]='b';break;
default:
break;
}
}
/*移动在目的地上的箱子到空地上*/
moveinbox(intx,inty,chara)
{switch(a)
{
case'u':
ghouse[x-1][y]='m';printf("");
printbox(x-2,y);printman(x-1,y);
ghouse[x-2][y]='b';break;
case'd':
ghouse[x+1][y]='m';printf("");
printbox(x+2,y);printman(x+1,y);
ghouse[x+2][y]='b';break;
case'l':
ghouse[x][y-1]='m';printf("");
printbox(x,y-2);printman(x,y-1);
ghouse[x][y-2]='b';break;
case'r':
ghouse[x][y+1]='m';printf("");
printbox(x,y+2);printman(x,y+1);
ghouse[x][y+2]='b';break;
default:
break;
}
}
/*移动在空地上的箱子到目的地上*/
moveboxin(intx,inty,chara)
{switch(a)
{
case'u':
ghouse[x-1][y]=0;printf("");
printboxin(x-2,y);printman(x-1,y);
ghouse[x-2][y]='i';break;
case'd':
ghouse[x+1][y]=0;printf("");
printboxin(x+2,y);printman(x+1,y);
ghouse[x+2][y]='i';break;
case'l':
ghouse[x][y-1]=0;printf("");
printboxin(x,y-2);printman(x,y-1);
ghouse[x][y-2]='i';break;
case'r':
ghouse[x][y+1]=0;printf("");
printboxin(x,y+2);printman(x,y+1);
ghouse[x][y+2]='i';break;
default:
break;
}
}
/*移动在目的地上的箱子到目的地*/
moveinboxin(intx,inty,chara)
{switch(a)
{
case'u':
ghouse[x-1][y]='m';printf("");
printboxin(x-2,y);printman(x-1,y);
ghouse[x-2][y]='i';break;
case'd':
ghouse[x+1][y]='m';printf("");
printboxin(x+2,y);printman(x+1,y);
ghouse[x+2][y]='i';break;
case'l':
ghouse[x][y-1]='m';printf("");
printboxin(x,y-2);printman(x,y-1);
ghouse[x][y-2]='i';break;
case'r':
ghouse[x][y+1]='m';printf("");
printboxin(x,y+2);printman(x,y+1);
ghouse[x][y+2]='i';break;
default:
break;
}
}
/*判断特定的坐标上的状态*/
intjudge(intx,inty)
{inti;
switch(ghouse[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;
}
/*处理按下键盘后,人物移动的主函数*/
move(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)
{printwhither(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)
{movebox(x,y,'u');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x-1);
}
elseif(judge(x-2,y)==3)
{moveboxin(x,y,'u');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x-1);
}
elsegotoxy(y,x);
break;
}
elseif(judge(x-1,y)==4)
{if(judge(x-2,y)==1)
{moveinbox(x,y,'u');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x-1);
}
elseif(judge(x-2,y)==3)
{moveinboxin(x,y,'u');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x-1);
}
elsegotoxy(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)
{printwhither(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)
{movebox(x,y,'d');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x+1);
}
elseif(judge(x+2,y)==3)
{moveboxin(x,y,'d');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x+1);
}
elsegotoxy(y,x);
break;
}
elseif(judge(x+1,y)==4)
{if(judge(x+2,y)==1)
{moveinbox(x,y,'d');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x+1);
}
elseif(judge(x+2,y)==3)
{moveinboxin(x,y,'d');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y,x+1);
}
elsegotoxy(y,x);
break;
}
case'l':
if(!
judge(x,y-1)){gotoxy(y,x);break;}
elseif(judge(x,y-1)==1||judge(x,y-1)==3)
{if(judge(x,y)==3)
{printwhither(x,y);printman(x,y-1);break;}
else
{printf("");printman(x,y-1);break;}
}
elseif(judge(x,y-1)==2)
{if(judge(x,y-2)==1)
{movebox(x,y,'l');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y-1,x);
}
elseif(judge(x,y-2)==3)
{moveboxin(x,y,'l');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y-1,x);
}
elsegotoxy(y,x);
break;
}
elseif(judge(x,y-1)==4)
{if(judge(x,y-2)==1)
{moveinbox(x,y,'l');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y-1,x);
}
elseif(judge(x,y-2)==3)
{moveinboxin(x,y,'l');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y-1,x);
}
elsegotoxy(y,x);
break;
}
case'r':
if(!
judge(x,y+1)){gotoxy(y,x);break;}
elseif(judge(x,y+1)==1||judge(x,y+1)==3)
{if(judge(x,y)==3)
{printwhither(x,y);printman(x,y+1);break;}
else
{printf("");printman(x,y+1);break;}
}
elseif(judge(x,y+1)==2)
{if(judge(x,y+2)==1)
{movebox(x,y,'r');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y+1,x);
}
elseif(judge(x,y+2)==3)
{moveboxin(x,y,'r');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y+1,x);
}
elsegotoxy(y,x);
break;
}
elseif(judge(x,y+1)==4)
{if(judge(x,y+2)==1)
{moveinbox(x,y,'r');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y+1,x);
}
elseif(judge(x,y+2)==3)
{moveinboxin(x,y,'r');
if(judge(x,y)==3)printwhither(x,y);gotoxy(y+1,x);
}
elsegotoxy(y,x);
break;
}
default:
break;
}
}
/*按下空格键后,回到本关开头的函数*/
voidreset(inti)
{switch(i)
{
case0:
init();
inithouse1();break;
case1:
init();
init
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 推箱子 C语言程序 报告 箱子 语言 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)