C语言推箱子游戏
- 格式:ppt
- 大小:959.00 KB
- 文档页数:8
推箱子C语言程序报告推箱子是一种极富智慧和策略性的游戏,是著名的益智游戏之一、它不仅可以锻炼人们的逻辑思维能力和创造力,而且还能提高人们的解决问题的能力和耐心。
本篇报告将介绍一个基于C语言开发的推箱子游戏,包括游戏规则、程序设计思路和实现效果等方面的内容。
一、游戏规则推箱子游戏的规则十分简单,玩家需要操作一个小人将该场景中的木箱全部推到指定位置。
在游戏开始时,场景中会放置一定数量的木箱和一个小人。
玩家可以通过键盘输入上下左右四个方向键来移动小人,小人可以推动场景中的木箱,但不能直接拉动或推动多个箱子。
当所有的木箱都被推到指定位置时,游戏胜利,反之则失败。
二、程序设计思路推箱子游戏的实现涉及到场景的渲染、小人和木箱的移动、游戏的逻辑判断等多个方面。
下面将分别介绍这些方面的程序设计思路。
1.场景渲染2.小人和木箱的移动玩家操作小人的移动,可以通过监听键盘输入的方向键来实现。
根据输入的方向,判断小人与目标位置的关系,如果目标位置是空地或者指定位置,则小人可以移动到目标位置,否则不能移动。
当小人移动后,如果目标位置是木箱,则需要判断木箱与目标位置的关系,如果目标位置是空地或者指定位置,则木箱可以被推动到目标位置,否则不能推动。
3.游戏逻辑判断在每一次小人移动后,需要判断游戏是否胜利或失败。
胜利的条件是所有的木箱都被推到指定位置,判断的方法是在遍历整个场景时,检查是否存在未推到指定位置的木箱。
失败的条件是小人无法再移动,判断的方法是在判断小人是否能够移动时,如果没有可移动的方向,则游戏失败。
三、实现效果通过以上的程序设计思路,可以开发出一个基于C语言的推箱子游戏。
该游戏可以提供丰富的关卡和难度选择,让玩家能够不断挑战和提高自己的智力。
游戏的界面简洁明了,操作方便快捷,给玩家带来舒适的游戏体验。
总结:推箱子是一种极富智慧的益智游戏,本篇报告介绍了一个基于C语言开发的推箱子游戏。
通过对游戏规则、程序设计思路和实现效果的阐述,可以看出该游戏具有多样化的场景和难度选择,能够锻炼玩家的智力和思维能力。
推箱子的c语言代码推箱子(Sokoban)是一种经典的益智游戏,也是计算机程序设计中常用的案例之一。
在这个游戏中,玩家需要移动箱子,将它们推到指定位置上,以完成关卡的目标。
在C语言中,我们可以使用二维数组来表示游戏的地图,其中不同的字符代表不同的元素。
例如,可以使用'#'表示墙壁,'@'表示玩家,'$'表示箱子,'.'表示目标位置。
玩家可以通过控制输入来移动,将箱子推到目标位置上。
为了实现这个游戏,我们可以先定义一个二维数组来表示地图,然后通过循环读取用户的输入,根据输入来移动玩家和箱子,最后判断是否完成了关卡的目标。
我们需要定义一个二维数组来表示地图。
假设地图的大小是10x10,我们可以这样定义:```c#define MAP_SIZE 10char map[MAP_SIZE][MAP_SIZE] = {"##########","# #","# $ #","# @ #","# #","# #","# #","# #","# #","##########"};```其中,'#'表示墙壁,'@'表示玩家,'$'表示箱子,'.'表示目标位置。
空格表示可通行的空地。
接下来,我们可以定义一个函数来打印地图,以便在每一次移动后显示最新的状态:```cvoid printMap() {for (int i = 0; i < MAP_SIZE; i++) {printf("%s\n", map[i]);}}```然后,我们可以定义一个循环,接收用户的输入,并根据输入来移动玩家和箱子。
/* 一个C语言编写的推箱子游戏源代码*//* 本游戏是字符模式的,请不要在中文dos下运行。
本游戏在TURBO C下调试通过*/#include <dos.h>#include <stdio.h>#include <ctype.h>#include <conio.h>#include <bios.h>#include <alloc.h>/* 定义二维数组ghouse来记录屏幕上各点的状态,其中:0表示什么都没有,'b'表示箱子,'w'表示墙壁,'m'表示目的地,'i'表示箱子在目的地。
*/char ghouse[20][20];/* 以下函数为直接写屏函数,很酷的函数哦!是我朋友告诉我的。
*/char far *screen=(char far* )0xb8000000;void putchxy(int y,int x,char ch,char fc,char bc){screen[(x*160)+(y<<1)+0]=ch;screen[(x*160)+(y<<1)+1]=(bc*16)+fc;}/* 定义判断是否胜利的数据结构*/typedef struct winer {int x,y;struct winer *p;}winer;/* 箱子位置的数据结构*/typedef struct boxs {int x,y;struct boxs *next;}boxs;/* 在特定的坐标上画墙壁并用数组记录状态的函数*/void printwall(int x,int y){putchxy(y-1,x-1,219,GREEN,BLACK);ghouse[x][y]='w';}/* 在特定的坐标上画箱子并用数组记录状态的函数*/void printbox(int x,int y){putchxy(y-1,x-1,10,WHITE,BLACK);ghouse[x][y]='b';}/* 在特定的坐标上画目的地并用数组记录状态的函数*/void printwhither1(int x,int y,winer **win,winer **pw){winer *qw;putchxy(y-1,x-1,'*',YELLOW,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;}}/* 在特定的坐标上画目的地并用数组记录状态的函数*/void printwhither(int x,int y){putchxy(y-1,x-1,'*',YELLOW,BLACK);ghouse[x][y]='m';}/* 在特定的坐标上画人的函数*/void printman(int x,int y){gotoxy(y,x);_AL=02;_CX=01;_AH=0xa;geninterrupt(0x10);}/* 在特定的坐标上画箱子在目的地上并用数组记录状态的函数*/ void printboxin(int x,int y){putchxy(y-1,x-1,10,YELLOW,BLACK);ghouse[x][y]='i';}/* 初始化函数,初始化数组和屏幕*/void init(){int i,j;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("Welcome to come box world!");gotoxy(40,6);printf("Press up,down,left,right to play.");gotoxy(40,8);printf("Press Esc to quit it.");gotoxy(40,10);printf("Press space to reset the game.");gotoxy(40,12);printf("Producer : wangdehao.");gotoxy(40,14);printf("Mar. 30th 2003."); }/* 第一关的图象初始化*/winer *inithouse1(){int x,y;winer *win=NULL,*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);printwhither1(4+4,2+10,&win,&pw); printwhither1(5+4,2+10,&win,&pw); printwhither1(6+4,2+10,&win,&pw); printman(2+4,8+10);return win;}/* 第三关的图象初始化*/winer *inithouse3(){int x,y;winer *win=NULL,*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);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);return win;}/* 第二关的图象初始化*/winer *inithouse2(){int x,y;winer *win=NULL,*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);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);return win;}/* 第四关的图象初始化*/winer *inithouse4(){int x,y;winer *win=NULL,*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);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);return win;}/* 移动在空地上的箱子到空地上*/ movebox(int x,int y,char a){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(int x,int y,char a){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(int x,int y,char a){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(int x,int y,char a){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;}}/* 判断特定的坐标上的状态*/int judge(int x,int y){int i;switch(ghouse[x][y]){case 0: 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;}return i;}/* 处理按下键盘后,人物移动的主函数*/move(int x,int y,char a){switch(a){case 'u':if(!judge(x-1,y)) {gotoxy(y,x);break;}else if(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;}}else if(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);}else if(judge(x-2,y)==3){ moveboxin(x,y,'u');if(judge(x,y)==3) printwhither(x,y); gotoxy(y,x-1);}else gotoxy(y,x);break;}else if(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);}else if(judge(x-2,y)==3){ moveinboxin(x,y,'u');if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x-1);}else gotoxy(y,x);break;}case 'd':if(!judge(x+1,y)) {gotoxy(y,x);break;}else if(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;}}else if(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);}else if(judge(x+2,y)==3){moveboxin(x,y,'d');if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);}else gotoxy(y,x);break;}else if(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);}else if(judge(x+2,y)==3) {moveinboxin(x,y,'d');if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);}else gotoxy(y,x);break;}case 'l':if(!judge(x,y-1)) {gotoxy(y,x);break;}else if(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;}}else if(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);}else if(judge(x,y-2)==3){moveboxin(x,y,'l');if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);}else gotoxy(y,x);break;}else if(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);}else if(judge(x,y-2)==3){moveinboxin(x,y,'l');if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);}else gotoxy(y,x);break;}case 'r':if(!judge(x,y+1)) {gotoxy(y,x);break;}else if(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;}}else if(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);}else if(judge(x,y+2)==3){moveboxin(x,y,'r');if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);}else gotoxy(y,x);break;}else if(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);}else if(judge(x,y+2)==3) {moveinboxin(x,y,'r');if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);}else gotoxy(y,x);break;}default: break;}}/* 按下空格键后,回到本关开头的函数*/ void reset(int i){switch(i){case 0: init();inithouse1();break;case 1: init();inithouse2();break;case 2: init();inithouse3();break;case 3: init();inithouse4();break;default:break;}}/* 主函数main */void main(){int key,x,y,s,i=0;winer *win,*pw;_AL=3;_AH=0;geninterrupt(0x10);init();win=inithouse1();do{_AH=3;geninterrupt(0x10);x=_DH+1;y=_DL+1;while(bioskey(1)==0);key=bioskey(0);switch(key){case 0x4800:move(x,y,'u');break; /* 按下向上键后*/case 0x5000:move(x,y,'d');break; /* 按下向下键后*/case 0x4b00:move(x,y,'l');break; /* 按下向左键后*/case 0x4d00:move(x,y,'r');break; /* 按下向右键后*/case 0x3920:reset(i);break; /* 按下空格键后*/default:break;}s=0;pw=win;while(pw){if(ghouse[pw->x][pw->y]=='m') s++;pw=pw->p;}if(s==0){free(win);gotoxy(25,2);printf("congratulate! you did a good job!");getch();i++;switch(i){case 1: init();win=inithouse2();break;case 2: init();win=inithouse3();break;case 3: init();win=inithouse4();break;case 4: gotoxy(15,21);printf("My dear Friend, How smart you are! Welcome to play again!"); key=0x011b;getch();break;default: break;}}}while(key!=0x011b);_AL=3;_AH=0;geninterrupt(0x10);}。
C语⾔实现推箱⼦游戏完整代码C语⾔实现推箱⼦游戏完整代码,供⼤家参考,具体内容如下前⾔⾃⼰做的,可能有些代码不够⼯整,或者有些⼩问题,但游戏的基本操作是可以实现的代码效果代码⼀共分为8个部分,4个控制上下左右移动,2个判断输赢,1个统计归为的个数,⼀个作图。
⼿动设置地图⽤'0'表⽰空格,“1”表⽰墙,“2”表⽰箱⼦,“3”表⽰⼈,“4”表⽰终点这样可以提⾼代码的移植性如需改为⼿动输⼊地图可以直接定义⼀个⼆维数组,在给他赋值就可以了int screen[9][11]={{0,1,1,1,1,1,1,1,1,0,0},{0,1,0,0,0,1,0,0,0,1,0},{0,1,0,2,2,2,2,2,0,1,0},{0,1,0,2,0,2,0,2,0,1,1},{0,1,0,0,0,3,0,0,2,0,1},{1,1,0,1,1,1,1,0,2,0,1},{1,0,4,4,4,4,4,1,0,0,1},{1,0,4,4,4,4,4,0,0,1,1},{1,1,1,1,1,1,1,1,1,1,0}};//定义为全局变量(地图) i表⽰⾏,j表⽰列计算地图中终点的个数这⼀步主要是为了后⾯判断游戏输赢的int cum(){int i,j,k=0;for(i=0;i<9;i++){for(j=0;j<11;j++){if(screen[i][j]==2){k++;}}}//遍历整个⼆维数组return k;}//计算地图中有多少个终点打印地图函数通过switch函数对⼆维数组中的值进⾏可视化,也就是画出地图注意:这⾥还定义出了6和7,是通过重叠的关系来算的,就是箱⼦在终点上,这个位置⼜有箱⼦⼜有终点2个标识,所以让两个的数值加起来,⽅便理解,也⽅便后⾯的计算void print(){int i,j;printf("请⽤wsad代表上下左右来进⾏游戏\n");for(i=0;i<9;i++){for(j=0;j<11;j++){switch(screen[i][j]){case 0:printf(" ");//空break;case 1:printf("■");//墙break;case 2:printf("★");//箱⼦break;case 3:printf("♀");//⼈break;case 4:printf("○");//终点break;case 6:printf("★");break;//箱⼦和终点case 7://⼈和终点显⽰⼈printf("♀");break;}}printf("\n");}}判断游戏输赢这⾥我写了2个函数,⼀个判断赢,⼀个判断输,并返回值,然后在主函数的最后⾯通过判断返回值来确定游戏的输赢判断赢int win(){int i,j,k=0;int t=0;for(i=0;i<9;i++){for(j=0;j<11;j++){if(screen[i][j]==6){k++;}}}//遍历整个⼆维数组,计算箱⼦在终点上的个数if(k==cum()){t=1;}//如果个数等于前⾯计算出的终点个数,则说明所有终点都放了箱⼦,说明游戏胜利return t;} //判断赢判断输int lose(){int i,j;int k=0;for(i=0;i<9;i++){for(j=0;j<11;j++){if(i>0 && j>0 ){if(screen[i][j] == 2 || screen[i][j] == 6){if(((screen[i-1][j] == 1 || screen[i-1][j] == 2 || screen[i-1][j] == 6) && (screen[i][j-1] == 1 || screen[i][j-1] == 2 || screen[i][j-1] == 6))|| ((screen[i][j-1] == 1 || screen[i][j-1] == 2 || screen[i][j-1] == 6) && (screen[i+1][j] == 1 || screen[i+1][j] == 2 || screen[i+1][j] == 6))|| ((screen[i+1][j] == 1 || screen[i+1][j] == 2 || screen[i+1][j] == 6) && (screen[i][j+1] == 1 || screen[i][j+1] == 2 || screen[i][j+1] == 6))|| ((screen[i][j+1] == 1 || screen[i][j+1] == 2 || screen[i][j+1] == 6) && (screen[i-1][j] == 1 || screen[i-1][j] == 2 || screen[i-1][j] == 6))){k++;}}}}/*这⾥也是遍历了整个数组,判断所有的箱⼦四个⽅向的情况,如果有三个⽅向被堵住了说明箱⼦⽆法移动了,也表明这个箱⼦失效了,⽤k来记录失效的个数,当全部失效时游戏失败(这是游戏的玩法,其实有⼀个被堵住就已经不可能胜利了)*/}if(k==cum()){k=1;return k;//返回1说明游戏失败}接下来是最重要的四个控制函数向上移动通过数字的变化来控制⼆维数组的变化,进⽽控制地图的更新这⾥⾮常重要的就是要理解:加1,加2,加3减3都是什么意思加1:箱⼦的值是2,⼈的值是3,所以箱⼦的位置变成⼈需要加1来实现加2:空地的值是0,箱⼦的值是2,箱⼦和终点在⼀起的值是6,所以在推箱⼦的时候,前⽅的空格或者终点放上箱⼦后数值会加2加3减3:⼈的值是3,⼈要动的话,它原先在的格⼦就会因为⼈⾛了导致数值减3,⾛到的那个格⼦就会因为站了⼈⽽加3如果这个理解的话,代码就⾮常简单了void movew(){if(x>0){if(screen[x-1][y]==1){return ;/*如果箱⼦的上⾯是墙,则地图不会发⽣变化,因为推不动嘛*/}else if(screen[x-1][y]==0){screen[x-1][y]+=3;screen[x][y]-=3;x--;/*如果前⾯是空地,则需要向前移动⼀格,也就是原先⼈的位置变成空地,前⽅的空地变成⼈,空地(0)变成⼈(3)需要加3,⼈变成空地需要减3*/}else if(screen[x-1][y]==4){screen[x-1][y]+=3;screen[x][y]-=3;x--;}//⼀样的else if(screen[x-1][y]==2||screen[x-1][y]==6){if(screen[x-2][y]==0){screen[x-2][y]+=2;//箱⼦前⾯的格变成箱⼦(2)screen[x-1][y]+=1;//箱⼦的位置变成⼈(3)screen[x][y]-=3;/*如果前⾯是空地,则需要向前移动⼀格,也就是原先是箱⼦的格⼦变成⼈,⼈的位置变成空地,原先的空地变成箱⼦,箱⼦(2)变成⼈(3)需要减3,空地变成⼈*/x--;}else if(screen[x-2][y]==1){return ;}else if(screen[x-2][y]==2){return;//如果箱⼦的前⾯是墙或者其他的箱⼦,则箱⼦推不动}else if(screen[x-2][y]==4){screen[x-2][y]+=2;screen[x-1][y]+=1;screen[x][y]-=3;x--;}//这个情况别漏了}}}其他三个⽅向的代码思路和这个是⼀样的向下移动void moves(){if(x<9){if(screen[x+1][y]==1){return ;}else if(screen[x+1][y]==0){screen[x+1][y]+=3;screen[x][y]-=3;x++;}else if(screen[x+1][y]==4){screen [x+1][y]+=3;screen[x][y]-=3;}else if(screen[x+1][y]==2||screen[x+1][y]==6){ if(screen[x+2][y]==1){return;}else if(screen[x+2][y]==0){screen[x+2][y]+=2;screen[x+1][y]+=1;screen[x][y]-=3;x++;}else if(screen[x+2][y]==2){return ;}else if(screen[x+2][y]==4){screen[x+2][y]+=2;screen[x+1][y]+=1;screen[x][y]-=3;x++;}}}}向左移动void movea(){if(y>0){if(screen[x][y-1]==1){return;}else if(screen[x][y-1]==4){screen[x][y-1]+=3;screen[x][y]-=3;y--;}else if(screen[x][y-1]==0){screen[x][y-1]+=3;screen[x][y]-=3;y--;}else if(screen[x][y-1]==2||screen[x][y-1]==6){ if(screen[x][y-2]==0){screen[x][y-2]+=2;screen[x][y-1]+=1;screen[x][y]-=3;y--;}else if(screen[x][y-2]==1){return;}else if(screen[x][y-2]==2){return;}else if(screen[x][y-2]=4){screen[x][y-2]+=2;screen[x][y-1]+=1;screen[x][y]-=3;y--;}}}}向右移动void moved(){if(y<9){if(screen[x][y+1]==1){return;}else if(screen[x][y+1]==4){screen[x][y+1]+=3;screen[x][y]-=3;y++;}else if(screen[x][y+1]==0){screen[x][y+1]+=3;screen[x][y]-=3;y++;}elseif(screen[x][y+1]==2||screen[x][y+1]==6){if(screen[x][y+2]==0){screen[x][y+2]+=2;screen[x][y+1]+=1;screen[x][y]-=3;y++;}else if(screen[x][y+2]==4){screen[x][y+2]+=2;screen[x][y+1]+=1;screen[x][y]-=3;y++;}else if(screen[x][y+2]==2){return;}else if(screen[x][y+2]==1){return;}}}}主函数这个主函数写的有点乱,直接看注释吧int main(){int n,t;int j,k;int b=1;here:system("cls");//printf("开始游戏请按1\n退出游戏请按2\n");scanf("%d",&j);if(j==1){printf("请⽤wsad代表上下左右来进⾏游戏\n");//这个就引导进⼊游戏while(1){system("cls");/*在每⼀次移动过后都清除上⼀个地图,不然就会每⾛⼀步⽣成⼀个图*/print();//先打印地图scanf("%c",&n);//读⼊⽤户的操作switch(n){case 'w':movew();break;case 's':moves();break;case 'a':movea();break;case 'd':moved();break;} //控制⼈移动t=win();if(t==1){goto there;}//每次操作完先判断游戏是否胜利,如果胜利了直接跳到函数最后if(b == lose()){system("cls");print();printf("游戏失败");return 0;} //游戏失败提⽰}}else {system("cls");printf("您确认要退出游戏吗\n确认退出按1\t返回上⼀层按2\n");scanf("%d",&k);if(k==1){printf("你已退出游戏,期待你的再次到来,谢谢");return 0;}else {goto here;}}//这⼀块是最前⾯⽤户进⼊游戏那⾥的,如果⽤户选择退出游戏执⾏的操作 there:printf("恭喜你通过了游戏!");return 0;}//主函数所有的代码就到这⾥了,如果需要完整代码可以留⾔以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
#include <stdio.h>#include <stdlib.h>#include <Windows.h>typedef struct MAP//地图{int wall[50][2];//墙int box[9][2];//箱子int des[9][2];//终点int overlap[9][2];//箱子与终点的重叠位置int all,now;//总箱子个数,到位箱子个数int x,y;//起点} MAP,*map;//全局变量//int U=1,D=2,L=3,R=4; //定义按键状态//int jump;int ofx=10,ofy=9; //定义xy偏移量int player[2];//玩家位置int nextp[2],nextb[2];//玩家下一步位置,箱子下一步位置MAP Pass[5];//关卡数组map Group,p;//关卡数组指针,当前关卡指针int level;//关卡等级int status;//玩家状态int boxc[9][2],overlapc[9][2];//箱子状态栈,重叠箱子状态栈int nowbox;//当前到位箱子个数int reset;//是否重玩//声明全部函数//void Pos(int x,int y)//设置光标位置{COORD pos;HANDLE hOutput;pos.X=x;pos.Y=y;hOutput=GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOutput,pos);system("color 3B");}void welcometogame()//开始界面{system("title 2017程序设计之推箱子");Pos(28,3);printf("欢迎来到推箱子!");Pos(50,24);printf(" 软件1603 刘刈16110572087\n");Pos(27,9);printf("用↑.↓.←.→控制人物的移动。
C语⾔完整游戏项⽬推箱⼦详细代码话不多说我们今天就来创造出属于我们⾃⼰的《推箱⼦》,GOGOGO直接开始吧⾸先是我们⽤⼆维数组特定的数字描绘出这个地图int cas = 0;int map[3][8][8] ={1,1,1,1,1,1,1,1,1,3,4,0,0,4,3,1,1,0,1,3,0,1,0,1,1,0,1,4,0,1,0,1,1,0,0,5,0,0,0,1,1,0,1,0,0,1,0,1,1,3,4,0,0,4,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,4,0,0,4,3,1,1,0,1,3,0,1,0,1,1,0,1,4,0,1,0,1,1,3,4,5,0,0,0,1,1,0,1,0,0,1,0,1,1,3,4,0,0,4,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,4,0,0,4,3,1,1,0,1,3,0,1,0,1,1,0,1,4,0,1,0,1,1,3,4,5,0,4,3,1,1,0,1,0,0,1,0,1,1,3,4,0,0,4,3,1,1,1,1,1,1,1,1,1};然后来绘制我们的推箱⼦地图void drawGraph(){for (int i = 0; i < 8; i++){for (int j = 0; j < 8; j++){//算贴图的坐标int x = 50 * j;int y = 50 * i;switch (map[cas][i][j]){case 0://⼀个汉字符号占⽤两个位置//printf(" ");putimage(x, y, img + 0);break;case 1:putimage(x, y, img + 1);//printf("■");break;case 3:putimage(x, y, img + 2);//printf("☆");break;case 4:putimage(x, y, img + 3);//printf("★");break;case 5:case 8:putimage(x, y, img + 4);//printf("⼈");break;case 7:putimage(x, y, img + 5);//printf("●");break;}}//printf("\n");}}之后就是我们的游戏函数,怎样去⽤什么按键去控制我们的⾓⾊void keyDown(){int userKey = _getch(); //不可见输⼊//定位:找到⼈的位置int i = 0;int j = 0;for (i = 1; i < 8; i++){for (j = 1; j < 8; j++){if (map[cas][i][j] == 5 || map[cas][i][j] == 8){goto NEXT;}}}NEXT://我们这个游戏⽤什么按键去玩switch (userKey){case 'W':case 'w':case 72:if (map[cas][i - 1][j] == 0 || map[cas][i - 1][j] == 3){map[cas][i][j] -= 5;map[cas][i - 1][j] += 5;}if (map[cas][i - 1][j] == 4 || map[cas][i - 1][j] == 7){if (map[cas][i - 2][j] == 0 || map[cas][i - 2][j] == 3){map[cas][i][j] -= 5;map[cas][i - 1][j] += 1;map[cas][i - 2][j] += 4;}}break;case 's':case 'S':case 80:if (map[cas][i + 1][j] == 0 || map[cas][i + 1][j] == 3)map[cas][i][j] -= 5;map[cas][i + 1][j] += 5;}if (map[cas][i + 1][j] == 4 || map[cas][i + 1][j] == 7) {if (map[cas][i + 2][j] == 0 || map[cas][i +2][j] == 3) {map[cas][i][j] -= 5;map[cas][i + 1][j] += 1;map[cas][i + 2][j] += 4;}}break;case 'a':case 'A':case 75:if (map[cas][i][j - 1] == 0 || map[cas][i][j - 1] == 3) {//a+=1 a=a+1 复合赋值运算符map[cas][i][j] -= 5;map[cas][i][j - 1] += 5;}if (map[cas][i][j - 1] == 4 || map[cas][i][j - 1] == 7) {if (map[cas][i][j - 2] == 0 || map[cas][i][j - 2] == 3) {map[cas][i][j] -= 5;map[cas][i][j - 1] += 1;map[cas][i][j - 2] += 4;}}break;case 'd':case 'D':case 77:if (map[cas][i][j + 1] == 0 || map[cas][i][j + 1] == 3) {map[cas][i][j] -= 5;map[cas][i][j + 1] += 5;}if (map[cas][i][j + 1] == 4 || map[cas][i][j + 1] == 7) {if (map[cas][i][j + 2] == 0 || map[cas][i][j + 2] == 3) {map[cas][i][j] -= 5;map[cas][i][j + 1] += 1;map[cas][i][j + 2] += 4;}}break;}}再然后就是我们如何去判断游戏的结果//胜负的判断:int gameOver(){//地图上没有箱⼦就可以结束for (int i = 0; i < 8; i++){for (int j = 0; j < 8; j++){if (map[cas][i][j] == 4){return 0;}}}return 1;}最后运⾏我们的主函数就⾏啦int main()loadResource();mciSendString("open 1.mp3", 0, 0, 0);mciSendString("play 1.mp3 repeat", 0, 0, 0);initgraph(50 * 8, 50 * 8);while (1){drawGraph();if (gameOver()){cas++; //变换关卡if(cas==3)break;}keyDown();//system("cls");}closegraph();//printf("GameOver!\n");return 0;}其实代码并不是很多,当然啦,如果同学们想更加完善,可以增加关卡设定,再优化⼀下我们的开始界⾯以及游戏界⾯也是可以的,⼤家快去尝试吧希望看完了的同学可以获得⾃⼰想要的知识,也感谢⼤家的耐⼼观看,在这⾥想得到⼤家⼀波关注,后续UP主还会发布更多的项⽬源码以及学习资料,有什么问题可以回帖留⾔,我尽量回答。
#include <stdio.h>#include <stdlib.h>//用到system()#include <conio.h>//因为需要用到getch()函数//推箱子_C语言版//写了一下午,第一个C语言游戏终于写好了,想想有点小激动....//蔚蓝之链编写//分享给大家参考下(在看得懂的情况下...),代码写得很凌乱.....,勿喷#define X 20#define Y 20#define REN 2 //表示人#define XIANGZI 3 //箱子#define WEIZHI 4 //箱子要推到的位置#define KONG 0 //空位#define QIANG 1 //墙#define RW 6 //人在箱子要推到的位置上#define XW 5 //箱子在箱子要推到的位置上#define bool short#define false 0#define true 1//数组内部数值表示内容:0表示空位,1表示墙体,2表示人,3表示箱子,4表示箱子要推到的位置,5表示既有箱子又有又位置,6表示既有位置又有人//01,2,3,4符号表示://0 :" " 1:■2:♀3:回4:◎void create_map_arr(int _x,int _y,int (*map_arr)[Y]);//创建地图数组void creata_map(int _x,int _y, int (*map)[Y]);//创建地图,重绘游戏画面void amend_map(int _x,int _y,char key , int (* arr_map)[Y]);//接收输入,修改游戏画面bool is_finish(int _x, int _y,int _total ,int (*arr_map)[Y]);//判断是否完成推箱子(地图x,地图y,总箱子数,地图数组)int main(void){int map_arr[X][Y];//存储地图的二维数组create_map_arr(X,Y,map_arr);//创建数组printf("C语言_推箱子v1.0 蔚蓝之链编写\n\n");printf("控制键:W↑,A←,S↓,D→\n");printf("提示:玩本游戏前请先关闭输入法\n");system("pause");system("cls");while(1){creata_map(X,Y,map_arr);//创建地图,重绘游戏画面if(is_finish(X,Y,2,map_arr) == true){printf("恭喜哦,推箱子完成!\n");system("pause");return 0;}amend_map(X,Y,getch(),map_arr);//接收输入,修改画面system("cls");//清空画面}getchar();return 0;}void create_map_arr (int _x,int _y,int (*map_arr)[Y])//创建地图数组{int x,y;for(x=0;x<_x;x++){for (y=0;y<_y;y++){if(y==0 || x==0 || x==_x-1 || y==_y-1){*(*(map_arr+x)+y) = QIANG;//printf ("■");}else{*(*(map_arr+x)+y) = KONG;//printf (" ");}}//printf("\n");}//这里可以修改箱子创建的位置,人创建的位置及箱子要达到的位置,默认两个箱子*(*(map_arr+3)+7)=REN;//人*(*(map_arr+5)+6)=XIANGZI;//箱子*(*(map_arr+5)+7)=XIANGZI;//箱子*(*(map_arr+1)+8)=WEIZHI;//箱子要推到的位置*(*(map_arr+2)+8)=WEIZHI;//箱子要推到的位置}void creata_map(int _x,int _y, int (*map)[Y])//创建地图(地图数组[][]){int x,y;for(x = 0; x < _x; x++){for (y = 0; y < _y; y++){if (*(*(map + x) + y) == QIANG){printf ("■");}else if(*(*(map + x) + y) == KONG){printf (" ");}else if(*(*(map + x) + y)==REN || *(*(map + x) + y)==RW){printf ("♀");}else if (* (*(map + x) + y)==XIANGZI){printf("□");}else if (*(*(map + x) + y)==WEIZHI){printf("◎");}else if(*(*(map + x) + y) == XW){printf("回");}}printf ("\n");}}//这个函数写的太乱了,自己看着也头大,不过还好,总算完成了^_^void amend_map(int _x,int _y,char key , int (* arr_map)[Y])//移动(地图x,地图y,按键值,地图数组){int x,y;for(x = 0; x < _x; x++){for (y = 0; y < _y; y++){if(*( * (arr_map + x ) + y) == REN || *( * (arr_map + x ) + y) == RW){if(key == 'a' || key == 'A')//←{if (y > 0){if(*(*(arr_map + x) +(y)) == RW)//人在最终位置{if(*( * (arr_map + x ) + (y-1)) == WEIZHI)//人左边还是最终位置{*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + y) = WEIZHI;}else if(*( * (arr_map + x ) + (y-1)) == XIANGZI || *( * (arr_map + x ) + (y-1)) == XW){if(*( * (arr_map + x ) + (y-1)) == XW){if (*( * (arr_map + x ) + (y-2)) == KONG){*( * (arr_map + x ) + (y-2)) = XIANGZI;*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + (y)) = WEIZHI;}else if(*( * (arr_map + x ) + (y-2)) == WEIZHI){*( * (arr_map + x ) + (y-2)) = XW;*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if(*(*(arr_map + x) + (y - 1)) == XIANGZI ){if (*( * (arr_map + x ) + (y-2)) == KONG){*( * (arr_map + x ) + (y-2)) = XIANGZI;*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}else if(*( * (arr_map + x ) + (y-2)) == WEIZHI){*( * (arr_map + x ) + (y-2)) = XW;*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}}else if(*(*(arr_map + x) + (y - 1)) == KONG){*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if (*(*(arr_map + x) +(y)) == REN)//人在空位{if(*( * (arr_map + x ) + (y-1)) == WEIZHI)//人左边是最终位置{*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + y) = KONG;}else if(*( * (arr_map + x ) + (y-1)) == XIANGZI || *( * (arr_map + x ) + (y-1)) == XW){if(*( * (arr_map + x ) + (y-1)) == XW){if (*( * (arr_map + x ) + (y-2)) == KONG){*( * (arr_map + x ) + (y-2)) = XIANGZI;*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y-2)) == WEIZHI){*( * (arr_map + x ) + (y-2)) = XW;*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + x) + (y - 1)) == XIANGZI ){if (*( * (arr_map + x ) + (y-2)) == KONG){*( * (arr_map + x ) + (y-2)) = XIANGZI;*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y-2)) == WEIZHI){*( * (arr_map + x ) + (y-2)) = XW;*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}else if(*(*(arr_map + x) + (y - 1)) == KONG){*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}//人在空位ENDelse if (*( * (arr_map + x ) + (y-1)) == XW || *( * (arr_map + x ) + (y-1)) == XIANGZI)//人左边有箱子或箱子在最终位置{if(*( * (arr_map + x ) + (y-1)) == XIANGZI || *( * (arr_map + x ) + (y-1)) == XW){if(*( * (arr_map + x ) + (y-1)) == XW){if (*( * (arr_map + x ) + (y-2)) == KONG){*( * (arr_map + x ) + (y-2)) = XIANGZI;*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y-2)) == WEIZHI){*( * (arr_map + x ) + (y-2)) = XW;*( * (arr_map + x ) + (y-1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + x) + (y - 1)) == XIANGZI ){if (*( * (arr_map + x ) + (y-2)) == KONG){*( * (arr_map + x ) + (y-2)) = XIANGZI;*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y-2)) == WEIZHI){*( * (arr_map + x ) + (y-2)) = XW;*( * (arr_map + x ) + (y-1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}}else if(*(*(arr_map + x) + (y-1)) == WEIZHI){*(*(arr_map + x) + (y-1)) = RW;*(*(arr_map + x) + (y)) = KONG;}else if(*(*(arr_map + x) + (y-1)) == KONG){*(*(arr_map + x) + (y-1)) = REN;*(*(arr_map + x) + (y)) = KONG;}}//IF(Y>0)END}//←else if(key == 'd' || key == 'D')//→{if (y < _y){if(*(*(arr_map + x) +(y)) == RW)//人在最终位置{if(*( * (arr_map + x ) + (y+1)) == WEIZHI)//人右边还是最终位置{*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + y) = WEIZHI;}else if(*( * (arr_map + x ) + (y+1)) == XIANGZI || *( * (arr_map + x ) + (y+1)) == XW){if(*( * (arr_map + x ) + (y+1)) == XW){if (*( * (arr_map + x ) + (y+2)) == KONG){*( * (arr_map + x ) + (y+2)) = XIANGZI;*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + (y)) = WEIZHI;}else if(*( * (arr_map + x ) + (y+2)) == WEIZHI){*( * (arr_map + x ) + (y+2)) = XW;*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if(*(*(arr_map + x) + (y + 1)) == XIANGZI ){if (*( * (arr_map + x ) + (y+2)) == KONG){*( * (arr_map + x ) + (y+2)) = XIANGZI;*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}else if(*( * (arr_map + x ) + (y+2)) == WEIZHI){*( * (arr_map + x ) + (y+2)) = XW;*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}}else if(*(*(arr_map + x) + (y + 1)) == KONG){*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if (*(*(arr_map + x) +(y)) == REN)//人在空位{if(*( * (arr_map + x ) + (y+1)) == WEIZHI)//人右边是最终位置{*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + y) = KONG;}else if(*( * (arr_map + x ) + (y+1)) == XIANGZI || *( * (arr_map + x ) + (y+1)) == XW){if(*( * (arr_map + x ) + (y+1)) == XW){if (*( * (arr_map + x ) + (y+2)) == KONG){*( * (arr_map + x ) + (y+2)) = XIANGZI;*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y-2)) == WEIZHI){*( * (arr_map + x ) + (y+2)) = XW;*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + x) + (y + 1)) == XIANGZI ){if (*( * (arr_map + x ) + (y+2)) == KONG){*( * (arr_map + x ) + (y+2)) = XIANGZI;*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y+2)) == WEIZHI){*( * (arr_map + x ) + (y+2)) = XW;*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}else if(*(*(arr_map + x) + (y + 1)) == KONG){*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}//人在空位ENDelse if (*( * (arr_map + x ) + (y+1)) == XW || *( * (arr_map + x ) + (y+1)) == XIANGZI)//人右边有箱子或箱子在最终位置{if(*( * (arr_map + x ) + (y+1)) == XIANGZI || *( * (arr_map + x ) + (y+1)) == XW){if(*( * (arr_map + x ) + (y+1)) == XW){if (*( * (arr_map + x ) + (y+2)) == KONG){*( * (arr_map + x ) + (y+2)) = XIANGZI;*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y+2)) == WEIZHI){*( * (arr_map + x ) + (y+2)) = XW;*( * (arr_map + x ) + (y+1)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + x) + (y + 1)) == XIANGZI ){if (*( * (arr_map + x ) + (y+2)) == KONG){*( * (arr_map + x ) + (y+2)) = XIANGZI;*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + x ) + (y+2)) == WEIZHI){*( * (arr_map + x ) + (y+2)) = XW;*( * (arr_map + x ) + (y+1)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}}else if(*(*(arr_map + x) + (y+1)) == WEIZHI){*(*(arr_map + x) + (y+1)) = RW;*(*(arr_map + x) + (y)) = KONG;}else if(*(*(arr_map + x) + (y+1)) == KONG){*(*(arr_map + x) + (y+1)) = REN;*(*(arr_map + x) + (y)) = KONG;}}//IF(Y>0)END}//→else if(key == 'w' || key == 'W')//↑{if (x-1 > 0){if(*(*(arr_map + (x)) +(y)) == RW)//人在最终位置{if(*( * (arr_map + (x-1) ) + (y)) == WEIZHI)//人上边还是最终位置{*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + (x) ) + y) = WEIZHI;}else if(*( * (arr_map + (x-1) ) + (y)) == XIANGZI || *( * (arr_map + (x-1) ) + (y)) == XW){if(*( * (arr_map + (x-1) ) + (y)) == XW){if (*( * (arr_map + (x-2) ) + (y)) == KONG){*( * (arr_map + (x-2) ) + (y)) = XIANGZI;*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + (x) ) + (y)) = WEIZHI;}else if(*( * (arr_map + (x-2) ) + (y)) == WEIZHI){*( * (arr_map + (x-2) ) + (y)) = XW;*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if(*(*(arr_map + (x-1)) + (y)) == XIANGZI ){if (*( * (arr_map + (x-2) ) + (y)) == KONG){*( * (arr_map + (x-2) ) + (y)) = XIANGZI;*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}else if(*( * (arr_map + (x-2) ) + (y)) == WEIZHI){*( * (arr_map + (x-2) ) + (y)) = XW;*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}}else if(*(*(arr_map + (x-1)) + (y)) == KONG){*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if (*(*(arr_map + x) +(y)) == REN)//人在空位{if(*( * (arr_map + (x-1) ) + (y)) == WEIZHI)//人上边是最终位置{*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + x ) + y) = KONG;}else if(*( * (arr_map + (x-1) ) + (y)) == XIANGZI || *( * (arr_map + (x-1) ) + (y)) == XW)//人上边是箱子或在最终位置的箱子{if(*( * (arr_map + (x-1) ) + (y)) == XW){if (*( * (arr_map + (x-2) ) + (y)) == KONG){*( * (arr_map + (x-2) ) + (y)) = XIANGZI;*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x-2) ) + (y)) == WEIZHI){*( * (arr_map + (x-2) ) + (y)) = XW;*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + (x-1)) + (y)) == XIANGZI ){if (*( * (arr_map + (x-2) ) + (y)) == KONG){*( * (arr_map + (x-2) ) + (y)) = XIANGZI;*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x-2) ) + (y)) == WEIZHI){*( * (arr_map + (x-2) ) + (y)) = XW;*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}else if(*(*(arr_map + (x-1)) + (y)) == KONG){*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}//人在空位ENDelse if (*( * (arr_map + (x-1) ) + (y)) == XW || *( * (arr_map + (x-1) ) + (y)) == XIANGZI)//人上边有箱子或箱子在最终位置{if(*( * (arr_map + (x-1) ) + (y)) == XIANGZI || *( * (arr_map + (x-1) ) + (y)) == XW){if(*( * (arr_map + (x-1) ) + (y)) == XW){if (*( * (arr_map + (x-2) ) + (y)) == KONG){*( * (arr_map + (x-2) ) + (y)) = XIANGZI;*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x-2) ) + (y)) == WEIZHI){*( * (arr_map + (x-2) ) + (y)) = XW;*( * (arr_map + (x-1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + (x-1)) + (y)) == XIANGZI ){if (*( * (arr_map + (x-2) ) + (y)) == KONG){*( * (arr_map + (x-2) ) + (y)) = XIANGZI;*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x-2) ) + (y)) == WEIZHI){*( * (arr_map + (x-2) ) + (y)) = XW;*( * (arr_map + (x-1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}}else if(*(*(arr_map + (x-1)) + (y)) == WEIZHI){*(*(arr_map + (x-1)) + (y)) = RW;*(*(arr_map + x) + (y)) = KONG;}else if(*(*(arr_map + (x-1)) + (y)) == KONG){*(*(arr_map + (x-1)) + (y)) = REN;*(*(arr_map + x) + (y)) = KONG;}}//IF(Y>0)END}//↑else if(key == 's' || key == 'S')//↓{if (x < _x+1 > 0){if(*(*(arr_map + (x)) +(y)) == RW)//人在最终位置{if(*( * (arr_map + (x+1) ) + (y)) == WEIZHI)//人下边还是最终位置{*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + (x) ) + y) = WEIZHI;}else if(*( * (arr_map + (x+1) ) + (y)) == XIANGZI || *( * (arr_map + (x+1) ) + (y)) == XW){if(*( * (arr_map + (x+1) ) + (y)) == XW){if (*( * (arr_map + (x+2) ) + (y)) == KONG){*( * (arr_map + (x+2) ) + (y)) = XIANGZI;*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + (x) ) + (y)) = WEIZHI;}else if(*( * (arr_map + (x+2) ) + (y)) == WEIZHI){*( * (arr_map + (x+2) ) + (y)) = XW;*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if(*(*(arr_map + (x+1)) + (y)) == XIANGZI ){if (*( * (arr_map + (x+2) ) + (y)) == KONG){*( * (arr_map + (x+2) ) + (y)) = XIANGZI;*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}else if(*( * (arr_map + (x+2) ) + (y)) == WEIZHI){*( * (arr_map + (x+2) ) + (y)) = XW;*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}}else if(*(*(arr_map + (x+1)) + (y)) == KONG){*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = WEIZHI;}}else if (*(*(arr_map + x) +(y)) == REN)//人在空位{if(*( * (arr_map + (x+1) ) + (y)) == WEIZHI)//人下边是最终位置{*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + x ) + y) = KONG;}else if(*( * (arr_map + (x+1) ) + (y)) == XIANGZI || *( * (arr_map + (x+1) ) + (y)) == XW){if(*( * (arr_map + (x+1) ) + (y)) == XW){if (*( * (arr_map + (x+2) ) + (y)) == KONG){*( * (arr_map + (x+2) ) + (y)) = XIANGZI;*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x+2) ) + (y)) == WEIZHI){*( * (arr_map + (x+2) ) + (y)) = XW;*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + (x+1)) + (y)) == XIANGZI ){if (*( * (arr_map + (x+2) ) + (y)) == KONG){*( * (arr_map + (x+2) ) + (y)) = XIANGZI;*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x+2) ) + (y)) == WEIZHI){*( * (arr_map + (x+2) ) + (y)) = XW;*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}else if(*(*(arr_map + (x+1)) + (y)) == KONG){*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}//人在空位ENDelse if (*( * (arr_map + (x+1) ) + (y)) == XW || *( * (arr_map + (x+1) ) + (y)) == XIANGZI)//人下边有箱子或箱子在最终位置{if(*( * (arr_map + (x+1) ) + (y)) == XIANGZI || *( * (arr_map + (x+1) ) + (y)) == XW){if(*( * (arr_map + (x+1) ) + (y)) == XW){if (*( * (arr_map + (x+2) ) + (y)) == KONG){*( * (arr_map + (x+2) ) + (y)) = XIANGZI;*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x+2) ) + (y)) == WEIZHI){*( * (arr_map + (x+2) ) + (y)) = XW;*( * (arr_map + (x+1) ) + (y)) = RW;*( * (arr_map + x ) + (y)) = KONG;}}else if(*(*(arr_map + (x+1)) + (y)) == XIANGZI ){if (*( * (arr_map + (x+2) ) + (y)) == KONG){*( * (arr_map + (x+2) ) + (y)) = XIANGZI;*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}else if(*( * (arr_map + (x+2) ) + (y)) == WEIZHI){*( * (arr_map + (x+2) ) + (y)) = XW;*( * (arr_map + (x+1) ) + (y)) = REN;*( * (arr_map + x ) + (y)) = KONG;}}}}else if(*(*(arr_map + (x+1)) + (y)) == WEIZHI){*(*(arr_map + (x+1)) + (y)) = RW;*(*(arr_map + x) + (y)) = KONG;}else if(*(*(arr_map + (x+1)) + (y)) == KONG){*(*(arr_map + (x+1)) + (y)) = REN;*(*(arr_map + x) + (y)) = KONG;}}//IF(Y>0)END}//↓return;}}}}bool is_finish(int _x, int _y,int _total ,int (*arr_map)[Y])//判断是否完成推箱子(地图x,地图y,总箱子数,地图数组){int x,y,temp = 0;for (x = 0; x < _x; x++){for (y = 0; y < _y; y++){if (*(*(arr_map+x)+y) == XW){temp++;}}}if (_total == temp){return true;}return false;}。
(注:VC运行时,分别新建两个文件BotIt.cpp和Maps.h,再在同一目录下运行其中cpp)代码部分文件“BoxIt.cpp”如下:#include <stdio.h>#include <conio.h>#include <stdlib.h>#include "Maps.h"#define AISLE "" //走廊#define N_AISLE 0#define W ALL "■" //墙壁#define N_W ALL 1#define AIM "※" //未放箱子的目标#define N_AIM 2#define BOX "□" //未在目标位置的箱子#define N_BOX 3#define MAN "♀" //人#define N_MAN 4#define BOX_OK "▢" //■已经在目标位置的箱子[即已放箱子的目标]#define N_BOX_OK 5#define MAN_IN "* "#define N_MAN_IN 6#define ESC 0x1B#define UP 'w'#define DOWN 's'#define LEFT 'a'#define RIGHT 'd'#define RESTART 'r'#define SA VE 'x'#define PF(a) printf("%s",a)struct Point{int x;int y;}man_p;/*小人坐标*///struct Filename{int num;char name[20];}filename[10];//int N;/*存档总人数*/int M;/*关数*/int step;/*步数*/char x;void welcome();void ingame();void playgame(int map[14][16]);/*玩游戏*/void displaymap(int map[14][16]);/*展示当前游戏界面*/void findman(int &a,int &b,int map[14][16]);/*找到小人坐标位置*/unsigned char getKey();/*获得有效按键返回按键值*/int getmap(Point p,int map[14][16]);/*获得点p的地图值*/void moveman(Point man_p,Point manf_p,int X,int Y,int map[14][16]);/*人移动*/ void movebox(Point box_p,Point boxf_p,int map[14][16]);/*移箱子*/int win(int map[14][16]);/*判断当无※时赢*/void choosemap(int map[14][16],int i);/*选关*/void changemap(int map[14][16],int mapx[14][16]);/*换地图*/void save();/*保存当前*/int read();/*读取存档*/int a=0,b=0,c=0,d=0;//system("color a");int main(){x='0';while(x!='4'){welcome();if(x=='3'&&read()==0) continue;if(x!='4') ingame();}return 0;}void displaymap(int map[14][16]){int i,j;system("cls");printf("\t\t\tMisson %d\n\n",M);for(i=0;i<14;i++){for(j=0;j<16;j++){ switch(map[i][j]){case N_AISLE:PF(" ");break;case N_W ALL:PF(W ALL);break;case N_AIM:PF(AIM);break;case N_BOX:PF(BOX);break;case N_MAN:PF(MAN);break;case N_BOX_OK:PF(BOX_OK);break;case N_MAN_IN:PF(MAN_IN);default:;}}if(i==2) printf("Press the key:");if(i==3) printf("'w'、'a'、's'、'd' to control ♀");if(i==5) printf("'r' to replay");if(i==7) printf("'x' to save");if(i==9) printf("'ESC' back to the menu");if(i==12) printf("Step:%d",step);PF("\n");}}void playgame(int map[14][16]){ int X,Y;Point manf_p,manff_p;//findman(man_p.x,man_p.y,map);displaymap(map);step=0;while(win(map)==0){findman(man_p.x,man_p.y,map);//printf("输入:");switch(getKey()){case DOWN://printf("\n下\n");manf_p.x=man_p.x;manff_p.x=man_p.x;manf_p.y=man_p.y+1,manff_p.y=man_p.y+2;X=0,Y=1;break;case UP://printf("\n上\n");manf_p.x=man_p.x;manff_p.x=man_p.x;manf_p.y=man_p.y-1,manff_p.y=man_p.y-2;X=0,Y=-1;break;case LEFT://printf("\n左\n");manf_p.x=man_p.x-1;manff_p.x=man_p.x-2;manf_p.y=man_p.y;manff_p.y=man_p.y;X=-1,Y=0;break;case RIGHT://printf("\n右\n");manf_p.x=man_p.x+1;manff_p.x=man_p.x+2;manf_p.y=man_p.y;manff_p.y=man_p.y;X=1,Y=0;break;case SA VE:save();continue;case RESTART:changemap(map,map0);M--;continue;case ESC:system("cls");changemap(map,map0);M=44;continue;default:;}//printf("\n人位置[%d %d]\n",man_p.y,man_p.x);//printf("\n人前方[%d %d]人前前方[%d %d]\n",manf_p.y,manf_p.x,manff_p.y,manff_p.x);switch(getmap(manf_p,map)){case N_AISLE://0case N_AIM://2moveman(man_p,manf_p,X,Y,map);break;case N_BOX://3case N_BOX_OK://5if(getmap(manff_p,map)==N_AISLE||getmap(manff_p,map)==N_AIM){movebox(manf_p,manff_p,map);moveman(man_p,manf_p,X,Y,map);}break;default:;}displaymap(map);}if(M==42) printf("\n\tCongratulation! Pass All!!!\n\n\n\t");}void findman(int &a,int &b,int map[14][16]){int i,j;for(i=0;i<14;i++)for(j=0;j<16;j++)if(map[i][j]==N_MAN||map[i][j]==N_MAN_IN)a=j,b=i;}unsigned char getKey(){unsigned char key;do{key = getch();}while(key != RESTART && key != ESC && key != LEFT && key != RIGHT && key != UP && key != DOWN && key!='x'&& key!=0x1B &&key!='r');return key;}int getmap(Point p,int map[14][16]){//printf("\n前方值%d\n",map[p.y][p.x]);return map[p.y][p.x];}void moveman(Point man_p,Point manf_p,int X,int Y,int map[14][16]){map[manf_p.y][manf_p.x]=(map[manf_p.y][manf_p.x]==N_AIM||map[manf_p.y][manf_p.x]==N_BOX _OK)?N_MAN_IN:N_MAN;map[man_p.y][man_p.x]=map[man_p.y][man_p.x]==N_MAN_IN?N_AIM:N_AISLE; //printf("\n移动后—小人位置值%d\n",map[manf_p.y][manf_p.x]);//printf("\n移动后—原小人位置值%d\n",map[man_p.y][man_p.x]);man_p.x+=X,man_p.y+=Y;step++;}void movebox(Point box_p,Point boxf_p,int map[14][16]){map[boxf_p.y][boxf_p.x]=map[boxf_p.y][boxf_p.x]==N_AISLE?N_BOX:N_BOX_OK; map[box_p.y][box_p.x]=map[box_p.y][box_p.x]==N_BOX?N_AISLE:N_AIM;}int win(int map[14][16]){int i,j;for(i=0;i<14;i++)for(j=0;j<16;j++)if(map[i][j]==2||map[i][j]==6)return 0;return 1;}void choosemap(int map[14][16],int i){switch(i){case 1:changemap(map,map1);break;case 2:changemap(map,map2);break;case 3:changemap(map,map3);break;case 4:changemap(map,map4);break;case 5:changemap(map,map5);break;case 6:changemap(map,map6);break;case 7:changemap(map,map7);break;case 8:changemap(map,map8);break;case 9:changemap(map,map9);break;case 10:changemap(map,map10);break;case 11:changemap(map,map11);break;case 12:changemap(map,map12);break;case 13:changemap(map,map13);break;case 14:changemap(map,map14);break;case 15:changemap(map,map15);break;case 16:changemap(map,map16);break;case 17:changemap(map,map17);break;case 18:changemap(map,map18);break;case 19:changemap(map,map19);break;case 20:changemap(map,map20);break;case 21:changemap(map,map21);break;case 22:changemap(map,map22);break;case 23:changemap(map,map23);break;case 24:changemap(map,map24);break;case 25:changemap(map,map25);break;case 26:changemap(map,map26);break;case 27:changemap(map,map27);break;case 28:changemap(map,map28);break;case 29:changemap(map,map29);break;case 30:changemap(map,map30);break;case 31:changemap(map,map31);break;case 32:changemap(map,map32);break;case 33:changemap(map,map33);break;case 34:changemap(map,map34);break;case 35:changemap(map,map35);break;case 36:changemap(map,map36);break;case 37:changemap(map,map37);break;case 38:changemap(map,map38);break;case 39:changemap(map,map39);break;case 40:changemap(map,map40);break;case 41:changemap(map,map41);break;case 42:changemap(map,map42);break;default:;}}void changemap(int map[14][16],int mapx[14][16]) {int i,j;for(i=0;i<14;i++)for(j=0;j<16;j++)map[i][j]=mapx[i][j];}void save(){int i,j;FILE *in;/*char filename[10][20];printf("put in the filename:");scanf("%s",filename);*/if((in=fopen("save game","w"))==NULL){printf("cannot open this file\n");exit(0);}for(i=0;i<14;i++)for(j=0;j<16;j++)fwrite(&map[i][j],sizeof(int),1,in);fwrite(&M,sizeof(int),1,in);fwrite(&step,sizeof(int),1,in);printf("\nGame Misson %d saved!\n",M);system("pause");fclose(in);}int read(){int i,j;FILE *out;/*char filename[10][20];printf("put in the filename:");scanf("%s",filename);*/if((out=fopen("save game","r"))==NULL){printf("\ncannot open this file\n");return 0;}else{for(i=0;i<14;i++)for(j=0;j<16;j++)fread(&map[i][j],sizeof(int),1,out);fread(&M,sizeof(int),1,out);fread(&step,sizeof(int),1,out);printf("\nM=%d\n",M);printf("Game read!\n");fclose(out);return 1;}}void welcome(){printf("\t\t ♀Box It \n");printf("\t\t1:New Game.\n\t\t2:Select Misson.\n\t\t3:Read Record.\n\t\t4:Exit Game.\n Choose-- ");switch(x=getch()){case '1':printf("1:");M=1;choosemap(map,M);break;case '2':printf("2:");printf("1-42 Misson to Choose:");scanf("%d",&M);choosemap(map,M);break;case '3':printf("3:");if(read()==1) printf("\n%d misson opened\n",M);break;case '4':printf("4:Exit Game.\n\n"); break;default:printf("Not 1-4\n");}}void ingame(){while(M<43){playgame(map);step=0;M++;choosemap(map,M);}}文件“Maps.h”如下:int map[14][16];int map0[14][16]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, };int map1[14][16]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,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3,2,2,2,3,0,1,0,1,1,0}, {1,0,0,1,1,1,1,1,0,1,1,1,0,1,0,0}, {1,0,0,0,0,0,0,3,0,0,0,3,0,1,0,0}, {1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0}, {0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, };int map37[14][16]={{0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0}, {0,1,2,2,1,0,0,0,0,0,0,1,2,2,1,0}, {0,1,2,2,1,1,1,1,1,1,1,1,2,2,1,0}, {0,1,0,3,0,2,2,2,2,2,2,3,2,3,1,0}, {0,1,3,0,3,0,3,0,3,0,3,0,3,0,1,0}, {0,1,0,3,0,3,0,3,4,3,0,3,0,3,1,0}, {0,1,3,0,3,0,3,0,3,0,3,0,3,0,1,0}, {0,1,0,3,0,3,0,3,0,3,0,3,0,3,1,0}, {0,1,3,2,3,2,2,2,2,2,2,0,3,0,1,0}, {0,1,2,2,1,1,1,1,1,1,1,1,2,2,1,0}, {0,1,2,2,1,0,0,0,0,0,0,1,2,2,1,0}, {0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0},。
C语言实现推箱子Visualc++6.0#include#include#include#include#include#include#include#define qiang 1#define ren 2#define xiang 3#define jia 6#define men 8#define oxiang 9int v[13][17]={0};int fuben[13][17];int num_guan; //现在的关数int num_xiang; //箱子的个数int move_num=0; //人行走的次数int push_num=0; //人推箱子的次数int M[2]; //M[0] 是人所在位置的横坐标M[1]是人所在位置的纵坐标int door[2]; //门所在的坐标int tem=0;int cc;void play();void chushi2();void chushihua_guan1();void chushihua_guan2();void chushihua_guan3();void chushihua_guan4();void chushihua_guan5();void chushihua_guan6();void chushihua_guan7();void chushihua_guan8();void chushihua_guan9();void chushihua_guan10();void chushihua_guan11();void chushihua_guan12();void chushihua_guan13();void chushihua_guan14();void dayin();int control();int wancheng();/**********************************************************主方法******************************************************************* ******/int main(){void jiemian();void shuoming();void xuanguan();void chushi(int nn);void chushi1();int i;char c;chushi1();for(i=0;i<=999;i++){ jiemian();c=getche(); if(c=='1') play();else if(c=='2') xuanguan();else if(c=='3') shuoming();else if(c=='4') break;else system("cls");} }/*************************打印游戏主界面******************************/void jiemian(){printf("\n\n\n\n");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY | FOREGROUND_BLUE);printf(" ╭╮ ■ ■ □ □ ◆◆◆◆◆◆◆◆ \n");printf(" ││ ■ ■ □□□□ □□□□ ◆ \n");printf(" ╭─┘└╮ ■ ■■■■ □ ■ □ ■ ◆ ◆ \n");printf(" ╰─┐┌ ■ ■ ■ □ ┏━━━┓ ◆ ◆ \n");printf(" ││ ■ ■■■ □□□□┃┏━┓┃ ◆◆ \n");printf(" ╭─┘└╮ ■ ■ □ ┃┏━┓┃ ┏━━━━◆━━┓\n");printf(" ╰─┐┌╯ ■ ■■■ □□ ┃┏━┓┃ ┗━━━━◆━━┛\n");p rintf(" ╭─┘│ ■ ■ □ □ □┃┗━┛┃ ◆ \n");printf(" ╰──╯ ■■■■■ □ □ □┗━━━┛ ◆◆◆◆◆◆ \n\n");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);printf(" >>1 开始游戏\n\n");printf(" >>2 选择关卡\n\n");printf(" >>3游戏帮助\n\n");printf(" >>4 退出游戏\n\n");}void chushi1(){int i,j;for(i=0;i<=12;i++)for (j=0;j<=16;j++)fuben[i][j]=0;}void chushi2(){int i,j;move_num=0;push_num=0;for(i=0;i<=12;i++)for(j=0;j<=16;j++) {v[i][j]=0;fuben[i][j]=0;}}/*************************游戏规则及说明******************************/void shuoming(){int i;char c;for(i=0;i<=999;i++){system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);printf("\t\t\t╭───────────╮\n");printf("\t\t\t│ 游戏规则及说明│\n");printf("\t\t\t╰───────────╯\n\n ");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),BACKGROUND_INTENSITY|FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE|FOREGROUND_RED|FOREGROUND_RED);printf("囧");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDL E),FOREGROUND_INTENSITY| FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);printf(" ");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);printf("别看了,这就是你了,还挺cool的吧,嘿嘿\n\n\n");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY | FOREGROUND_INTENSITY);printf(" █ ");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);printf("这个是墙,放心,不是豆腐渣工程,要不你可以去撞撞看,\n");printf(" 你会懂得......\n\n\n");printf(" ■ ");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);printf("这个是箱子,就是要你去推的那个,不要试图一下推两个箱\n");printf(" 子,更不要想推着箱子把墙撞开,没用的...不要沮丧,再免\n");printf(" 费给你一句忠告,要是把箱子推到了死角,呵呵,直接下一\n");printf(" 关吧\n\n\n");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HAN DLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN | FOREGROUND_RED);printf(" ★ ");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);printf("这里就是箱子们的最终归宿了,箱子要是回不到家,哼哼,\n");printf(" 你自己掂量着办吧。
c语言课程设计之推箱子一、教学目标本章节的教学目标是使学生掌握C语言编程基础,学会使用推箱子游戏进行编程实践,培养学生的逻辑思维能力和问题解决能力。
具体目标如下:1.理解C语言的基本语法和数据类型。
2.掌握函数的定义和调用。
3.学习使用指针和数组。
4.了解常用库函数的使用。
5.能够编写简单的C语言程序。
6.学会使用推箱子游戏进行编程实践。
7.培养学生的逻辑思维能力和问题解决能力。
情感态度价值观目标:1.培养学生对计算机编程的兴趣和热情。
2.培养学生勇于尝试、克服困难的精神。
3.培养学生团队合作、共同解决问题的意识。
二、教学内容本章节的教学内容主要包括C语言的基本语法、数据类型、函数、指针和数组。
具体安排如下:1.C语言的基本语法和数据类型:介绍C语言的基本语法规则,包括变量声明、运算符、表达式等,以及常用的数据类型,如整型、浮点型、字符型等。
2.函数的定义和调用:讲解函数的定义、声明和调用方式,以及函数的参数传递和返回值。
3.指针和数组:介绍指针的概念和使用方法,以及一维、多维数组的基本操作。
4.常用库函数的使用:讲解常用库函数的调用方法,如数学函数、输入输出函数等。
5.推箱子游戏的编程实践:通过编写推箱子游戏程序,使学生将所学知识应用于实际编程中,培养学生的逻辑思维能力和问题解决能力。
三、教学方法本章节采用讲授法、案例分析法和实验法相结合的教学方法,以激发学生的学习兴趣和主动性。
1.讲授法:教师通过讲解C语言的基本语法、数据类型、函数、指针和数组等内容,使学生掌握相关知识。
2.案例分析法:教师通过分析推箱子游戏的编程案例,引导学生运用所学知识解决实际问题,培养学生的逻辑思维能力和问题解决能力。
3.实验法:学生通过编写推箱子游戏程序,进行实际操作,巩固所学知识,提高编程技能。
四、教学资源本章节的教学资源包括教材、多媒体资料和实验设备。
1.教材:选用权威、实用的C语言教材,如《C程序设计语言》等。
#include<stdio.h> #include<stdlib.h>#include<windows.h>#include<conio.h>//打印地图void DrawMap();//设置颜色void SetColor(int nColor);//获取玩家坐标POINT GetGamerPosition();//上void Up();//下void Down();//左void Left();//右void Right();//获取空箱子个数int GetSpareBox();//地图//0:空地;3箱子的目的地4箱子// 6人7箱子与目的地的集合//1:墙壁;9人在箱子的目的地int g_map[2][10][12]={{{0,0,0,0,1,1,1,0,0,0,0,0 },{0,0,0,0,1,3,1,0,0,0,0,0 },{0,0,0,0,1,0,1,1,1,1,1,1 },{1,1,1,1,1,4,0,4,0,0,3,1 },{1,3,0,0,0,4,6,1,1,1,1,1 },{1,1,1,1,1,1,4,1,0,0,0,0 },{0,0,0,0,0,1,0,1,0,0,0,0 },{0,0,0,0,0,1,0,1,0,0,0,0 },{0,0,0,0,0,1,3,1,0,0,0,0 },{0,0,0,0,0,1,1,1,0,0,0,0 },},{{1,1,1,1,1,0,0,0,0,0,0,0 },{1,0,0,0,1,0,1,1,1,0,0,0 },{1,0,4,0,1,0,1,1,1,1,1,1 },{1,0,4,6,1,0,1,0,0,0,3,1 },{1,1,1,4,1,1,1,0,0,0,3,1 },{1,1,1,0,0,0,0,0,0,0,3,1 },{0,1,0,0,0,1,0,0,0,0,0,1 },{0,1,0,0,0,1,0,0,0,0,0,1 },{0,1,0,0,0,1,1,1,1,1,1,1 },{1,1,1,1,1,1,0,0,0,0,0,0 },}};int g_nCurrentLevel = 0;//当前管卡int main(){//设置窗口大小system("mode con cols=26 lines=11");//设置标题//SetConsoLeTitle("推箱子");char nInput = 0;//输入字符while(1){//如果箱子推完了过关if (0==GetSpareBox())g_nCurrentLevel++;//清屏system("cls");//如果没有关卡,那就恭喜你成功通关。
c 推箱子游戏课程设计一、课程目标知识目标:1. 学生能够理解推箱子游戏的基本规则及背景,掌握游戏中的关键元素,如箱子、目标点、玩家角色等。
2. 学生能够运用方向键等基本操作完成推箱子游戏,并理解游戏中的坐标表示方法。
3. 学生了解并掌握编程语言中的循环、条件判断等基本概念,并能够将其应用于推箱子游戏的解法设计中。
技能目标:1. 学生能够运用逻辑思维和分析能力,规划出推箱子游戏的解题策略,提高问题解决能力。
2. 学生通过编写简单的程序代码,实现推箱子游戏的自动化求解,培养编程实践能力。
3. 学生能够与他人合作交流,共同探讨推箱子游戏的解决方案,提高团队协作能力。
情感态度价值观目标:1. 学生在推箱子游戏的过程中,体会编程的乐趣,激发对计算机科学的兴趣和热情。
2. 学生通过克服游戏中的困难,培养勇于挑战、不怕失败的积极心态。
3. 学生在团队协作中,学会尊重他人意见,培养合作精神,提高人际沟通能力。
课程性质:本课程为信息技术课程,结合趣味游戏,引导学生学习编程知识,培养其逻辑思维和团队协作能力。
学生特点:本课程针对五年级学生设计,该年龄段学生好奇心强,喜欢探索和挑战,具备一定的逻辑思维能力,但注意力集中时间较短。
教学要求:教师应关注学生的个体差异,因材施教,注重培养学生的动手实践能力和团队协作精神。
在教学过程中,以学生为主体,鼓励学生主动探究,激发学生的学习兴趣。
同时,将课程目标分解为具体的学习成果,以便进行教学设计和评估。
二、教学内容1. 推箱子游戏简介:介绍推箱子游戏的起源、发展及其在计算机科学教育中的应用,使学生了解游戏背后的教育意义。
2. 游戏规则与元素:讲解推箱子游戏的基本规则,引导学生认识游戏中的关键元素,如箱子、目标点、玩家角色等,并学会用坐标表示游戏空间。
3. 编程基础:- 循环结构:学习for、while等循环语句,掌握在程序中重复执行某段代码的方法。
- 条件判断:学习if-else等条件语句,学会根据不同条件执行不同操作。
目录1 摘要.............................................................. .. (3)1.1设计题目............................................. (3)1.2设计内容.............................................. .. (3)1.3开发工具........................................................ . (3)1.4应用平台....................................................... .. (3)2 详细设计 (3)2.1程序结构...................................................... (3)2.2主要功能..................................................... (4)2.3函数实现..................................................... .. (4)2.4开发日志.................................................... (5)3 程序调试及运行 (5)3.1程序运行结果............................................... .. (6)3.2程序使用说明............................................. . (6)3.3程序开发总结.............................................. (7)4 附件(源程序)........................................... . (7)1 摘要1.1 设计题目推箱子游戏1.2 设计内容推箱子是一款经典的益智小游戏,目的是在训练人的逻辑思考能力。
c语言推箱子课程设计一、教学目标本课程旨在通过C语言编程技巧的学习,使学生掌握基本的推箱子游戏设计与实现。
具体目标如下:知识目标:使学生了解C语言编程的基本概念和方法,理解推箱子游戏的规则和逻辑。
技能目标:培养学生使用C语言进行程序设计的能力,学会分析问题、解决问题,并能够独立完成推箱子游戏的设计与实现。
情感态度价值观目标:培养学生对计算机科学的兴趣和热情,增强其对编程学习的自信心,培养良好的编程习惯和团队合作意识。
二、教学内容教学内容主要包括C语言基础知识、推箱子游戏规则讲解、推箱子游戏设计与实现三个部分。
第一部分,C语言基础知识,包括C语言的基本语法、数据类型、运算符、控制结构等。
第二部分,推箱子游戏规则讲解,主要包括推箱子游戏的规则、游戏的目标、游戏元素的属性等。
第三部分,推箱子游戏设计与实现,主要包括游戏地图的表示、游戏逻辑的实现、游戏界面的设计等。
三、教学方法本课程采用讲授法、案例分析法、实验法等多种教学方法相结合的方式进行教学。
通过讲授法,使学生掌握C语言的基本知识和推箱子游戏的规则。
通过案例分析法,使学生了解推箱子游戏设计与实现的具体过程,培养学生分析问题、解决问题的能力。
通过实验法,使学生亲自动手编写代码,实现推箱子游戏的设计与实现,提高学生的编程能力和实践能力。
四、教学资源教学资源包括教材、实验设备、网络资源等。
教材:选用《C语言程序设计》作为主要教材,辅助以相关参考书籍。
实验设备:为学生提供电脑、网络等实验设备,使其能够进行实验操作。
网络资源:提供在线编程平台,供学生进行在线编程实践。
五、教学评估教学评估是检验学生学习成果和教学效果的重要手段。
本课程的评估方式包括以下几个方面:1.平时表现:通过课堂参与、提问、讨论等方式评估学生的学习态度和积极性。
2.作业:布置推箱子游戏设计的相关的编程作业,评估学生的编程能力和对知识的掌握程度。
3.考试:设置期中考试和期末考试,测试学生对C语言编程和推箱子游戏设计的理解和掌握程度。
c语言课程设计 推箱子一、课程目标知识目标:1. 让学生掌握C语言的基本语法和编程结构,特别是数组、循环和条件语句的应用。
2. 使学生理解程序逻辑和算法设计的基本原理,并能将其应用于推箱子游戏的实现中。
3. 帮助学生理解坐标系统和二维数组在表示游戏地图中的应用。
技能目标:1. 培养学生运用C语言编写程序解决实际问题的能力,特别是在逻辑推理和算法实现方面。
2. 提高学生调试程序和解决问题的技巧,通过推箱子游戏的开发,学会逐步测试和优化代码。
3. 增进学生对编程工具的使用,如编译器和调试器,以及版本控制的基本操作。
情感态度价值观目标:1. 培养学生对编程的兴趣和热情,通过完成具有挑战性的推箱子游戏,增强学习C语言的信心和动力。
2. 培养学生的团队合作精神,分组合作完成项目,学会在团队中交流和协作。
3. 增强学生的创新意识和实践能力,鼓励学生尝试不同的解决方案,培养独立思考和问题解决的能力。
课程性质:本课程设计为实践性强的综合课题,结合了C语言编程和游戏设计,旨在通过解决实际问题,提高学生的编程能力和逻辑思维。
学生特点:考虑到学生处于高年级,具备一定的C语言基础,有较强的逻辑思维能力,对编程有较高的兴趣。
教学要求:课程设计需注重理论与实践相结合,强调学生的主动参与和动手实践,注重培养学生的自主学习和问题解决能力。
通过推箱子游戏的实现,将目标分解为具体的学习成果,为教学设计和评估提供明确的方向。
二、教学内容本课程教学内容紧密结合课程目标,确保学生能够系统地掌握C语言编程及相关游戏设计知识。
1. C语言基础语法回顾:包括变量定义、数据类型、运算符、控制结构(如if 语句、循环等)。
- 相关教材章节:第1章至第3章2. 数组和字符串的使用:重点介绍二维数组在表示游戏地图中的应用。
- 相关教材章节:第4章3. 函数的定义与调用:强调模块化编程思想,介绍如何将游戏逻辑分解为多个函数。
- 相关教材章节:第5章4. 算法设计与逻辑推理:介绍推箱子游戏中的算法设计,如深度优先搜索、广度优先搜索等。
推箱子c语言程序代码推箱子游戏是一款益智类游戏,在游戏中需要利用角色推动箱子到指定位置,并通过通关来获得胜利。
在这里,我将为您介绍一个简单的推箱子的C语言程序代码。
首先,我们需要定义一些变量和常量来描述游戏中的元素和状态:```c#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <windows.h>#define ROW 10 //地图行数#define COL 15 //地图列数//定义角色、箱子和目标的符号#define PLAYER 'P'#define BOX '$'#define TARGET '*'#define WALL '#'#define SPACE ' '接下来,我们需要定义一个结构体来表示地图上的每一个位置,包含如下元素:- `type`:表示该位置的类型,可以是空格、墙、箱子、目标或者角色。
- `hasBox`: 表示该位置上是否有箱子,是一个布尔值。
```cstruct Position {char type;bool hasBox;};```- `map`:表示地图,是一个二维数组,每个元素都是一个 `Position` 结构体。
- `playerRow` 和 `playerCol`:表示角色当前的位置。
- `boxRow` 和 `boxCol`:表示当前推动的箱子的位置。
```cint playerRow, playerCol, boxRow, boxCol;Position map[ROW][COL];```接下来,我们需要编写地图的初始化函数。
在这个函数中,我们先将地图上所有的位置都标记为空格,并将所有的箱子标记为 `false`。
然后,我们可以将墙、箱子、目标和角色放置到正确的位置上。
#i n c l u d e<s t d i o.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("\n\n\n\n\n\n\t\t\t\t欢迎进入推箱子游戏\n\n\t\t\t\t 请按a b c选择游戏\n\n\t\t\t\t 按 d 键结束");int t=getch();if(t=='d'){printf("\n\t\t\t "); }else{if(t=='a'){map1();goto loop1;}if(t=='b'){map2();goto loop1;}if(t=='c'){map3();goto loop1;}else{printf("\n\n\t\t\t\t 请重新输入:");goto loop1;}}}time(&b);printf("\n\n\n\n\t\t\t\t 游戏总共用时%.3d秒\n\t\t\t ",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,a[9][9]={ /*为背景设置初始资料*/ {'#','#','#','#','#','#','#','#','#'},{'#','#','#', 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);//调用输出函数move(a,&x,&y,i,j,m,n,t,k,&z);if(a[i][j]=='!'&&a[m][n]=='!'&&a[t][k]=='!'){system("cls");//刷屏show(a);printf("\t\t\t\t YOU ARE WIN!\n");time(&q);printf("\t\t\t\t\t 用时%.3d秒\n",q-p);printf("\t\t\t\t*******回车重新选择*******\n\t\t\t\t");getch();}else{time(&o);if(z=='d'){return;}if(o-p>30){loop1: system("cls");//刷屏printf("\t\t\t\t时间已过请重新回车选关!");int g=getch();if(g==13)//判断是否为回车符{return;}else{goto loop1;}}system("cls");//刷屏show(a);//调用输出函数goto loop;}}void map2(){time_t p,q,o;time(&p);int i=2,j=1,m=1,n=3,t=4,k=6;system("cls");//刷屏system("color 2E");int x=4,y=1;char z,b[9][9]={ /*为背景设置初始资料*/ {'#','#','#','#','#','#','#','#','#'},{'#','#','#', 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 ,'#','#','#'},{'#','#','#','#','#','#','#','#','#'}};show(b);//调用输出函数move(b,&x,&y,i,j,m,n,t,k,&z);if(b[i][j]=='!'&&b[m][n]=='!'&&b[t][k]=='!'){system("cls");//刷屏show(b);printf("\t\t\t\t YOU ARE WIN!\n");time(&q);printf("\t\t\t\t\t 用时%.3d秒\n",q-p);printf("\t\t\t\t*******回车重新选择*******\n\t\t\t\t");getch();}else{time(&o);if(z=='d'){return;}if(o-p>30){loop1: system("cls");//刷屏printf("\t\t\t\t时间已过请重新回车选关!");int g=getch();if(g==13)//判断是否为回车符{return;}else{goto 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,c[9][9]={ /*为背景设置初始资料*/ {'#','#','#','#','#','#','#','#','#'},{'#','#','#','#','#', 0 , 0 , 0 ,'#'},{'#', 3 ,'#', 0 , 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 ,'#'},{'#','#','#', 0 , 0 , 0 , 3 ,'#','#'},{'#','#','#','#','#','#','#','#','#'} };show(c);//调用输出函数move(c,&x,&y,i,j,m,n,t,k,&z);if(c[i][j]=='!'&&c[m][n]=='!'&&c[t][k]=='!'){system("cls");//刷屏show(c);printf("\t\t\t\t YOU ARE WIN!\n");time(&q);printf("\t\t\t\t\t 用时%.3d秒\n",q-p);printf("\t\t\t\t*******回车重新选择*******\n\t\t\t\t");getch();}else{time(&o);if(z=='d'){return;}if(o-p>30){loop1: system("cls");//刷屏printf("\t\t\t\t时间已过请重新回车选关!");int g=getch();if(g==13)//判断是否为回车符{return;}else{goto loop1;}}system("cls");//刷屏show(c);//调用输出函数goto loop;}}void show(char b[9][9]){printf("\t\t\t\t***************************\n");printf("\t\t\t\t 推箱子游戏");printf("\n\t\t\t\t***************************\n");printf("\t\t\t\t 人:★墙:■\n\t\t\t\t 箱子:◎目的地:□\n\t\t\t\t 按d 键退出游戏\n\t\t\t\t 限时30秒!");printf("\n\t\t\t\t***************************\n");int i;int k;for(i=0;i<9;i++) //使用循环将地图转换输出{printf("\t\t\t\t ");for(k=0;k<9;k++){if(b[i][k]=='#'){printf("■");}else{if(b[i][k]==3){printf("□");}else{if(b[i][k]==5){printf("◎");}else{if(b[i][k]==1){printf("★");}else{if(b[i][k]==0){printf(" ");}else{if(b[i][k]=='!'){printf("⊙");}elseprintf("%c ",b[i][k]);}}}}}}printf("\n");}printf("\t\t\t\t***************************\n");}void move(char c[9][9],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]=='!'){}//遇到墙或推两个箱子else{if(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;}}else{if(c[*x][*y-1]==5&&c[*x][*y-2]!='#')//推箱子{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //推着箱子离开目的地{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]==c[X][Y]||c[*x][*y-1]==c[A][B]||c[*x][*y-1]==c[N][M])//进到目的地{c[*x][*y]=0;*y-=1;c[*x][*y]=1;}else{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //离开目的地{c[*x][*y]=3;*y-=1;c[*x][*y]=1;}else //走到空地{c[*x][*y]=0;*y-=1;c[*x][*y]=1;}}}}}}if(c[X][Y]==5||c[A][B]==5||c[N][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]=='!'){}//遇到墙或推两个箱子else{if(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;}}else{if(c[*x][*y+1]==5&&c[*x][*y+2]!='#')//推箱子{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //推着箱子离开目的地{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]==c[X][Y]||c[*x][*y+1]==c[A][B]||c[*x][*y+1]==c[N][M])//进到目的地{c[*x][*y]=0;*y+=1;c[*x][*y]=1;}else{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //离开目的地{c[*x][*y]=3;*y+=1;c[*x][*y]=1;}else //走到空地{c[*x][*y]=0;*y+=1;c[*x][*y]=1;}}}}}}if(c[X][Y]==5||c[A][B]==5||c[N][M]==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]=='!'){}//遇到墙或推两个箱子else{if(c[*x-1][*y]=='!')//把箱子推出目的地{if(c[*x-2][*y]!=0){}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]!='#')//推箱子{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //推着箱子离开目的地{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]==c[X][Y]||c[*x-1][*y]==c[A][B]||c[*x-1][*y]==c[N][M])//进到目的地{c[*x][*y]=0;*x-=1;c[*x][*y]=1;}else{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //离开目的地{c[*x][*y]=3;*x-=1;c[*x][*y]=1;}else //走到空地{c[*x][*y]=0;*x-=1;c[*x][*y]=1;}}}}}}if(c[X][Y]==5||c[A][B]==5||c[N][M]==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]=='!'){}//遇到墙或推两个箱子else{if(c[*x+1][*y]=='!')//把箱子推出目的地{if(c[*x+2][*y]!=0){}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]!='#')//推箱子{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //推着箱子离开目的地{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]==c[X][Y]||c[*x+1][*y]==c[A][B]||c[*x+1][*y]==c[N][M])//进到目的地{c[*x][*y]=0;*x+=1;c[*x][*y]=1;}else{if(c[*x][*y]==c[X][Y]||c[*x][*y]==c[A][B]||c[*x][*y]==c[N][M]) //离开目的地{c[*x][*y]=3;*x+=1;c[*x][*y]=1;}else //走到空地{c[*x][*y]=0;*x+=1;c[*x][*y]=1;}}}}}}if(c[X][Y]==5||c[A][B]==5||c[N][M]==5)//箱子推到目的地{c[*x+1][*y]='!';}}}。