收藏 分销(赏)

c语言推箱子代码.doc

上传人:丰**** 文档编号:4315083 上传时间:2024-09-05 格式:DOC 页数:20 大小:22.16KB
下载 相关 举报
c语言推箱子代码.doc_第1页
第1页 / 共20页
c语言推箱子代码.doc_第2页
第2页 / 共20页
c语言推箱子代码.doc_第3页
第3页 / 共20页
c语言推箱子代码.doc_第4页
第4页 / 共20页
c语言推箱子代码.doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

1、#include #include void map1();void map2();void map3();void show();void move();void main(int argc,char*argv)time_t a,b;time(&a);system(color 1E);loop1:system(cls);/刷屏printf(nnnnnntttt欢迎进入推箱子游戏nntttt 请按a b c选择游戏nntttt 按 d 键 结束);int t=getch();if(t=d)printf(nttt );elseif(t=a)map1();goto loop1;if(t=b)map

2、2();goto loop1;if(t=c)map3();goto loop1;elseprintf(nntttt 请重新输入:);goto loop1;time(&b);printf(nnnntttt 游戏总共用时%.3d秒nttt ,b-a);getch();/等待读取回车符以结束程序void map1()time_t p,q,o;time(&p);int i=4,j=4,m=6,n=2,t=1,k=3;system(cls);/刷屏system(color 2E);int x=1,y=7;char z,a99= /*为背景设置初始资料*/#,#,#,#,#,#,#,#,#,#,#,#,

3、3, 0 , 0 , 0 , 1 ,#,#,#, 0 , 0 , 0 ,#, 0 ,#,#,#, 0 , 0 ,#, 0 , 0 , 5 , 0 ,#,#, 0 , 5 , 5 , 3 , 0 , 0 , 0 ,#,#,#, 0 ,#, 0 , 0 ,#,#,#,#,#, 3 , 0 , 0 , 0 ,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#;show(a);/调用输出函数loop:/语句标号move(a,&x,&y,i,j,m,n,t,k,&z);if(aij=!&amn=!&atk=!)system(cls);/刷屏show(a);printf(t

4、ttt YOU ARE WIN!n);time(&q);printf(ttttt 用时%.3d秒n,q-p);printf(tttt*回车重 新选择*ntttt);getch();elsetime(&o);if(z=d)return;if(o-p30)loop1:system(cls);/刷屏printf(tttt时间已过请重新回车选关!);int g=getch();if(g=13)/判断是否为回车符return;elsegoto loop1;system(cls);/刷屏show(a);/调用输出函数goto loop;void map2() time_t p,q,o;time(&p);i

5、nt i=2,j=1,m=1,n=3,t=4,k=6;system(cls);/刷屏system(color 2E);int x=4,y=1;char z,b99= /*为背景设置初始资料*/#,#,#,#,#,#,#,#,#,#,#,#, 3 , 0 ,#,#,#,#,#, 3 ,#, 0 , 0 , 0 , 0 ,#,#,#, 0 , 5 , 0 ,#,#, 0 , 0 ,#,#, 1 , 0 , 5 , 0 , 0 , 3 , 0 ,#,#, 0 , 0 , 0 , 0 , 0 , 0 ,#,#,#,#,#, 0 , 0 , 5 ,#,#,#,#,#,#,#, 0 , 0 ,#,#,#,

6、#,#,#,#,#,#,#,#,#;show(b);/调用输出函数loop:/语句标号move(b,&x,&y,i,j,m,n,t,k,&z);if(bij=!&bmn=!&btk=!)system(cls);/刷屏show(b);printf(tttt YOU ARE WIN!n);time(&q);printf(ttttt 用时%.3d秒n,q-p);printf(tttt*回车重 新选择*ntttt);getch();elsetime(&o);if(z=d)return;if(o-p30)loop1:system(cls);/刷屏printf(tttt时间已过请重新回车选关!);int

7、g=getch();if(g=13)/判断是否为回车符return;elsegoto loop1;system(cls);/刷屏show(b);/调用输出函数goto loop;void map3()time_t p,q,o;time(&p);int i=2,j=1,m=6,n=2,t=7,k=6;system(cls);/刷屏system(color 2E);int x=3,y=6;char z,c99= /*为背景设置初始资料*/#,#,#,#,#,#,#,#,#,#,#,#,#,#, 0 , 0 , 0 ,#,#, 3 ,#, 0 , 0 , 0 , 0 , 0 ,#,#, 0 , 5

8、, 0 , 5 ,#, 1 ,#,#,#, 0 , 0 , 0 , 0 , 0 , 5 , 0 ,#,#,#, 0 , 0 , 0 , 0 , 0 , 0 ,#,#,#, 3 , 0 ,#, 0 ,#, 0 ,#,#,#,#, 0 , 0 , 0 , 3 ,#,#,#,#,#,#,#,#,#,#,#;show(c);/调用输出函数loop:/语句标号move(c,&x,&y,i,j,m,n,t,k,&z);if(cij=!&cmn=!&ctk=!)system(cls);/刷屏show(c);printf(tttt YOU ARE WIN!n);time(&q);printf(ttttt 用时

9、%.3d秒n,q-p);printf(tttt*回车重 新选择*ntttt);getch();elsetime(&o);if(z=d)return;if(o-p30)loop1:system(cls);/刷屏printf(tttt时间已过请重新回车选关!);int g=getch();if(g=13)/判断是否为回车符return;elsegoto loop1;system(cls);/刷屏show(c);/调用输出函数goto loop;void show(char b99)printf(tttt*n);printf(tttt 推箱子游戏 );printf(ntttt*n);printf(t

10、ttt 人: 墙:ntttt 箱子: 目的地:ntttt 按 d 键 退出游戏ntttt 限时30秒!);printf(ntttt*n);int i;int k;for(i=0;i9;i+) /使用循环将地图转换输出printf(tttt );for(k=0;k9;k+)if(bik=#)printf();elseif(bik=3)printf();elseif(bik=5)printf();elseif(bik=1)printf();elseif(bik=0)printf( );elseif(bik=!) printf(); elseprintf(%c ,bik); printf(n); p

11、rintf(tttt*n);void move(char c99,int *x,int *y,int X,int Y,int A,int B,int N,int M,char *t) *t=getch();/用getch()得到上下左右键,要调用二次getch(),上键72,下键80,左键75,右键77. if(*t=d)/遇到d返回if(*t=75)/左键if(c*x*y-1=#|c*x*y-1=5&c*x*y-2=5 |c*x*y-1=5&c*x*y-2=!)/遇到墙或推两个箱子elseif(c*x*y-1=!)/把箱子推出目的地if(c*x*y-2!=0)elsec*x*y=0;*y-=

12、1;c*x*y=1;c*x*y-1=5;elseif(c*x*y-1=5&c*x*y-2!=#)/推箱子 if(c*x*y=cXY|c*x*y=cAB |c*x*y=cNM) /推着箱子离开目的地 c*x*y=3; *y-=1; c*x*y=1; c*x*y-1=5; else c*x*y=0; *y-=1; c*x*y=1; c*x*y-1=5; else if(c*x*y-1=5&c*x*y-2=#)/推不动箱子 else if(c*x*y-1=cXY|c*x*y-1=cAB |c*x*y-1=cNM)/进到目的地 c*x*y=0; *y-=1; c*x*y=1; else if(c*x*

13、y=cXY|c*x*y=cAB |c*x*y=cNM) /离开目的地 c*x*y=3; *y-=1; c*x*y=1; else /走到空地 c*x*y=0; *y-=1; c*x*y=1; if(cXY=5|cAB=5|cNM=5)/箱子推到目的地 c*x*y-1=!; if(*t=77)/右键if(c*x*y+1=#|c*x*y+1=5&c*x*y+2=5 |c*x*y+1=5&c*x*y+2=!)/遇到墙或推两个箱子elseif(c*x*y+1=!)/把箱子推出目的地if(c*x*y+2!=0)elsec*x*y=0;*y+=1;c*x*y=1;c*x*y+1=5;elseif(c*x*

14、y+1=5&c*x*y+2!=#)/推箱子 if(c*x*y=cXY|c*x*y=cAB |c*x*y=cNM) /推着箱子离开目的地 c*x*y=3; *y+=1; c*x*y=1; c*x*y+1=5; else c*x*y=0; *y+=1; c*x*y=1; c*x*y+1=5; else if(c*x*y+1=5&c*x*y+2=#)/推不动箱子 else if(c*x*y+1=cXY|c*x*y+1=cAB |c*x*y+1=cNM)/进到目的地 c*x*y=0; *y+=1; c*x*y=1; else if(c*x*y=cXY|c*x*y=cAB |c*x*y=cNM) /离开

15、目的地 c*x*y=3; *y+=1; c*x*y=1; else /走到空地 c*x*y=0; *y+=1; c*x*y=1; if(cXY=5|cAB=5|cNM=5)/箱子推到目的地 c*x*y+1=!; if(*t=72)/上键if(c*x-1*y=#|c*x-1*y=5&c*x-2*y=5 |c*x-1*y=5&c*x-2*y=!)/遇到墙或推两个箱子elseif(c*x-1*y=!)/把箱子推出目的地if(c*x-2*y!=0)elsec*x*y=0;*x-=1;c*x*y=1;c*x-1*y=5;elseif(c*x-1*y=5&c*x-2*y!=#)/推箱子 if(c*x*y=

16、cXY|c*x*y=cAB |c*x*y=cNM) /推着箱子离开目的地 c*x*y=3; *x-=1; c*x*y=1; c*x-1*y=5; else c*x*y=0; *x-=1; c*x*y=1; c*x-1*y=5; else if(c*x-1*y=5&c*x-2*y=#)/推不动箱子 else if(c*x-1*y=cXY|c*x-1*y=cAB |c*x-1*y=cNM)/进到目的地 c*x*y=0; *x-=1; c*x*y=1; else if(c*x*y=cXY|c*x*y=cAB |c*x*y=cNM) /离开目的地 c*x*y=3; *x-=1; c*x*y=1; el

17、se /走到空地 c*x*y=0; *x-=1; c*x*y=1; if(cXY=5|cAB=5|cNM=5)/箱子推到目的地 c*x-1*y=!; if(*t=80)/下键if(c*x+1*y=#|c*x+1*y=5&c*x+2*y=5 |c*x+1*y=5&c*x+2*y=!)/遇到墙或推两个箱子elseif(c*x+1*y=!)/把箱子推出目的地if(c*x+2*y!=0)elsec*x*y=0;*x+=1;c*x*y=1;c*x+1*y=5;elseif(c*x+1*y=5&c*x+2*y!=#)/推箱子 if(c*x*y=cXY|c*x*y=cAB |c*x*y=cNM) /推着箱子

18、离开目的地 c*x*y=3; *x+=1; c*x*y=1; c*x+1*y=5; else c*x*y=0; *x+=1; c*x*y=1; c*x+1*y=5; else if(c*x+1*y=5&c*x+2*y=#)/推不动箱子 else if(c*x+1*y=cXY|c*x+1*y=cAB |c*x+1*y=cNM)/进到目的地 c*x*y=0; *x+=1; c*x*y=1; else if(c*x*y=cXY|c*x*y=cAB |c*x*y=cNM) /离开目的地 c*x*y=3; *x+=1; c*x*y=1; else /走到空地 c*x*y=0; *x+=1; c*x*y=1; if(cXY=5|cAB=5|cNM=5)/箱子推到目的地 c*x+1*y=!; 20

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服