c语言推箱子代码_第1页
c语言推箱子代码_第2页
c语言推箱子代码_第3页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include <stdio.h>#include <stdlib.h>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 键结束”);in

2、t t=getch();if(t='d')printf("nttt");elseif(t='a')map1();goto loop1;if(t='b')map2();goto loop1;if(t='c')map3();goto loop1;elseprintf("nntttt 请重新输入 :");goto loop1;time(&b);",b-a);printf("nnnntttt 游戏总共用时 %.3d 秒 nttt getch();/ 等待读取回车符以结束程

3、序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= /* 为背景设置初始资料 */'#','#','#','#','#','#','#','#','#','#','#','

4、;#', 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 ,'#','#

5、9;,'#', '#','#', 3 , 0 , 0 , 0 ,'#','#','#', '#','#','#','#','#','#','#','#','#', '#','#','#','#','#','#','#','#',&#

6、39;#'show(a);/ 调用输出函数loop:/ 语句标号 move(a,&x,&y,i,j,m,n,t,k,&z); if(aij='!'&&amn='!'&&atk='!') system("cls");/ 刷屏show(a); printf("tttt YOU ARE WIN!n"); time(&q);printf("ttttt用时 .3d 秒n”,q-p);printf("tttt* 回车重 新选择

7、*ntttt"); getch();elsetime(&o);if(z='d')return;if(o-p>30)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

8、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 ,'#','#'

9、,'#','#', '#', 3 ,'#', 0 , 0 , 0 , 0 ,'#','#', '#', 0 , 5 , 0 ,'#','#', 0 , 0 ,'#', '#', 1 , 0 , 5 , 0 , 0 , 3 , 0 ,'#', '#', 0 , 0 , 0 , 0 , 0 , 0 ,'#','#', '#','#'

10、;,'#', 0 , 0 , 5 ,'#','#','#', '#','#','#','#', 0 , 0 ,'#','#','#', '#','#','#','#','#','#','#','#','#'show(b);/ 调用输出函数loop:/ 语句标号move(b,&am

11、p;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='

12、;d')return;if(o-p>30)loop1:system("cls");/ 刷屏printf("tttt 时间已过请重新回车选关 !"); int 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"

13、);/ 刷屏 system("color 2E");int x=3,y=6;char z,c99= /* 为背景设置初始资料 */ '#','#','#','#','#','#','#','#','#', '#','#','#','#','#', 0 , 0 , 0 ,'#', '#', 3 ,'#', 0

14、 , 0 , 0 , 0 , 0 ,'#', '#', 0 , 5 , 0 , 5 ,'#', 1 ,'#','#', '#', 0 , 0 , 0 , 0 , 0 , 5 , 0 ,'#', '#','#', 0 , 0 , 0 , 0 , 0 , 0 ,'#', '#','#', 3 , 0 ,'#', 0 ,'#', 0 ,'#', '#

15、9;,'#','#', 0 , 0 , 0 , 3 ,'#','#', '#','#','#','#','#','#','#','#','#'show(c);/ 调用输出函数loop:/ 语句标号move(c,&x,&y,i,j,m,n,t,k,&z); if(cij='!'&&cmn='!'&&ctk

16、='!') system("cls");/ 刷屏 show(c);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-p>30) loop1:system("cls");/ 刷屏printf("tttt 时间

17、已过请重新回车选关 !"); int g=getch();if(g=13)/ 判断是否为回车符return;elsegoto loop1; system("cls");/ 刷屏 show(c);/ 调用输出函数 goto loop;void show(char b99)printf("tttt* *printf("tttt 推箱子游戏 ");printf("ntttt*n");printf("tttt人:墙: ntttt 箱子:出游戏 ntttt 限时 30 秒!");目的地: ntttt 按d

18、键退printf("ntttt*n");int i;int k;for(i=0;i<9;i+)/ 使用循环将地图转换输出printf("tttt");for(k=0;k<9;k+)if(bik='#')printf(" ");elseif(bik=3)printf(" ");elseif(bik=5)printf(" ");elseif(bik=1)printf(" "); elseif(bik=0)printf(" ");el

19、seif(bik='!')printf(” O ”);elseprintf("%c ",bik);printf("n");printf("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

20、*x*y-1='#'|c*x*y-1=5&&c*x*y-2=5|c*x*y-1=5&&c*x*y-2='!')/ 遇到墙或推两个箱子else if(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*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;

21、c*x*y=1;c*x*y-1=5;elsec*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;elseif(c*x*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|cN

22、M=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)else c*x*y=0; *y+=1; c*x*y=1; c*x*y+1=5;elseif(c*x*y+1=5&&c*x*y+2!='#')/ 推箱子if(c*x*y=c

23、XY|c*x*y=cAB |c*x*y=cNM) / 推着箱子离开目的地c*x*y=3;*y+=1;c*x*y=1;c*x*y+1=5;elsec*x*y=0;*y+=1;c*x*y=1;c*x*y+1=5;elseif(c*x*y+1=5&&c*x*y+2='#')/ 推不动箱子elseif(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;elseif(c*x*y=cXY|c*x*y=cAB|c*x*y=cNM) / 离开目的地 c*x*y=3;*y+=1;c*x*y=1;els

24、e / 走到空地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;else if(c*x-1*y=5&&c*x-2*y!='#')/ 推箱子 if(c*x*y=cXY|c*x*y=cAB |c*x*y=cNM) / 推着箱子离开目的地c*x*y=3;*x-=1;c*x*y=1;c*x-1*y=5;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='#')/ 推不动箱子 elseif(c*x-1*y=cXY|c*x-1*y=cAB|c*x-1*y=c

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论