C语言推箱子游戏
推箱子C语言程序报告

推箱子C语言程序报告推箱子是一种极富智慧和策略性的游戏,是著名的益智游戏之一、它不仅可以锻炼人们的逻辑思维能力和创造力,而且还能提高人们的解决问题的能力和耐心。
本篇报告将介绍一个基于C语言开发的推箱子游戏,包括游戏规则、程序设计思路和实现效果等方面的内容。
一、游戏规则推箱子游戏的规则十分简单,玩家需要操作一个小人将该场景中的木箱全部推到指定位置。
在游戏开始时,场景中会放置一定数量的木箱和一个小人。
玩家可以通过键盘输入上下左右四个方向键来移动小人,小人可以推动场景中的木箱,但不能直接拉动或推动多个箱子。
当所有的木箱都被推到指定位置时,游戏胜利,反之则失败。
二、程序设计思路推箱子游戏的实现涉及到场景的渲染、小人和木箱的移动、游戏的逻辑判断等多个方面。
下面将分别介绍这些方面的程序设计思路。
1.场景渲染2.小人和木箱的移动玩家操作小人的移动,可以通过监听键盘输入的方向键来实现。
根据输入的方向,判断小人与目标位置的关系,如果目标位置是空地或者指定位置,则小人可以移动到目标位置,否则不能移动。
当小人移动后,如果目标位置是木箱,则需要判断木箱与目标位置的关系,如果目标位置是空地或者指定位置,则木箱可以被推动到目标位置,否则不能推动。
3.游戏逻辑判断在每一次小人移动后,需要判断游戏是否胜利或失败。
胜利的条件是所有的木箱都被推到指定位置,判断的方法是在遍历整个场景时,检查是否存在未推到指定位置的木箱。
失败的条件是小人无法再移动,判断的方法是在判断小人是否能够移动时,如果没有可移动的方向,则游戏失败。
三、实现效果通过以上的程序设计思路,可以开发出一个基于C语言的推箱子游戏。
该游戏可以提供丰富的关卡和难度选择,让玩家能够不断挑战和提高自己的智力。
游戏的界面简洁明了,操作方便快捷,给玩家带来舒适的游戏体验。
总结:推箱子是一种极富智慧的益智游戏,本篇报告介绍了一个基于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语言编写的推箱子游戏

/* 一个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语⾔实现推箱⼦游戏完整代码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;}//主函数所有的代码就到这⾥了,如果需要完整代码可以留⾔以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
C语言推箱子源代码推箱子代码完善

#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语言完整游戏项目推箱子详细代码

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主还会发布更多的项⽬源码以及学习资料,有什么问题可以回帖留⾔,我尽量回答。
推箱子-C语言源码

#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;}。
C语言推箱子课程设计(附报告)

(注: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,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,1,1,1,0,0}, {1,1,0,1,1,0,2,2,2,0,0,0,0,1,1,0}, {0,1,0,1,4,1,2,2,2,1,1,1,3,0,1,0},{1,1,0,1,0,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},。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实现过程
运行Turbo C,新建一个C源文件,命名为PushBox.c,在这个源文件中编写程序代码。下面是主要的 实现过程。
(1)游戏界面实现。
玩家可以使用上下左右键来控制推箱子的方向,如果游戏无法继续,可以按下空格键,回到本关游 戏的开始,重新游戏。如果顺利完成游戏,玩家只要按下任意键即可进入游戏下一关。具体实现代置后,如果为了下面步骤的需要,需要将箱子再次从目标位置移动到空地位置, 具体实现函数如下:
/* 移动在目的地上的箱子到空地上 */ goaltoarea(int x,int y,char a) { switch(a) { case 'u':state[x-1][y]='g'; printf(" "); box(x-2,y); man(x-1,y); state[x-2][y]='b'; break; case 'd':state[x+1][y]='g'; printf(" "); box(x+2,y); man(x+1,y); state[x+2][y]='b'; break; case 'l':state[x][y-1]='g'; printf(" "); box(x,y-2); man(x,y-1); state[x][y-2]='b'; break; case 'r':state[x][y+1]='g'; printf(" "); box(x,y+2); man(x,y+1); state[x][y+2]='b'; break; default: break; } }
同样的方法可以绘制后面关卡的界面。
(2)游戏控制模块的实现。
玩家在进入游戏后,使用上下左右键来操作游戏,在不同位置,游戏程序会调用不同的自定义函数来移动箱子,下面 具体介绍不同的自定义控制函数。
将箱子在空地之间进行移动,如果推动方向是空地则向前移动一个位置,如果推动方向是墙,箱子则原地不动,实现
函数如下所示:
for(y=9,x=2;x<=5;x++)
wall(x+4,y+10);
for(y=1,x=3;x<=8;x++)
wall(x+4,y+10);
for(x=3,y=3;x<=5;x++)
wall(x+4,y+10);
for(x=5,y=8;x<=9;x++)
wall(x+4,y+10);
for(x=7,y=4;x<=9;x++)
/* 移动在空地上的箱子到空地上 */ movebox(int x,int y,char a) {
switch(a)
{
/*按下上键的操作*/
case 'u':state[x-1][y]=0; /*空地位置的状态标识*/
printf(" ");
box(x-2,y);
/*输出箱子*/
man(x-1,y);
技术要点
由于游戏中,要不停移动人物和箱子,那么也就要不停地对光标进行定位,下面就对光标的定 位函数gotoxy()进行介绍。 gotoxy()函数用于在文本窗口中设置光标,函数原型如下:
void gotoxy(int x, int y);
参数说明:x为窗口中的行,y为窗口的列。 本函数没有返回值,只是将光标定位到窗口中的指定位置。
(3)游戏说明模块的实现。 玩家在进入游戏后,游戏界面的右侧就会显示出游戏的操作使用说明,如使用上下左右键来控制
小人推箱子的方向以及如何回到本关游戏的开始。实现函数如下所示:
void init() { int i,j; for(i=0;i<20;i++) for(j=0;j<20;j++) state[i][j]=0; _AL=3; _AH=0; geninterrupt(0x10); gotoxy(30,4); printf("Welcome to BIGBOX world!"); gotoxy(30,6); printf("You can press up,down,left,right to control."); gotoxy(30,8); printf("Press Esc to quit it."); gotoxy(30,10); printf("Press space to reset the game."); }
printf(" "); box(x,y-2); man(x,y-1);
state[x][y-2]='b'; break; /*按下右键的操作*/ case 'r':state[x][y+1]=0; printf(" "); box(x,y+2);
man(x,y+1);
state[x][y+2]='b'; break; default: break;
概述
推箱子是一个很有情趣的益智游戏,也是一个经典的游戏。这款游戏需要玩家有着综合性的思维去考虑 每一步的行走路线,可以培养玩家的综合性思维,提高远性思考的能力,使人在考虑问题的时候要全面考虑, 而不只考虑眼前的问题,行一时之便,可能后继无路。所以开发了本游戏供人们娱乐和训练思维之用。本游 戏通过操作键盘的上下左右键来操控游戏中游戏中的小人来推动箱子到目标位置。当玩家把所有的箱子都推 到目标位置,游戏会提示玩家进入下一关,本游戏共分四关。 推箱子游戏运行效果如图19.1所示。
wall(x+4,y+10);
for(x=9,y=5;y<=7;y++)
wall(x+4,y+10);
for(x=8,y=2;y<=3;y++)
wall(x+4,y+10);
wall(5+4,4+10);
wall(5+4,7+10);
wall(3+4,2+10);
/*初始化箱子位置*/ box(3+4,6+10); box(3+4,7+10); box(4+4,7+10); /*初始化目标位置*/ goal1(4+4,2+10,&win,&pw); goal1(5+4,2+10,&win,&pw); goal1(6+4,2+10,&win,&pw); /*初始化人的位置*/ man(2+4,8+10); return win; }
winer *pass1()/* 第一关的图象初始化 */
{
int x,y;
winer *win=NULL,*pw;/*初始化胜利标志*/ /*对围墙进行输出*/
for(x=1,y=5;y<=9;y++)
wall(x+4,y+10);
/*纵向画墙*/
for(y=5,x=2;x<=5;x++)
wall(x+4,y+10);
/*输出小人*/
state[x-2][y]='b'; /*墙体位置的状态标识*/
break;
/*按下下键的操作*/
case 'd':state[x+1][y]=0;
printf(" "); box(x+2,y); man(x+1,y);
state[x+2][y]='b'; break; /*按下左键的操作*/ case 'l':state[x][y-1]=0;
图19.1 推箱子游戏运行界面
设计思路
制作推箱子游戏的设计思路如下: (1)明确推箱子游戏的游戏规则,如将空地上的箱子全部推到目标位置即可过关,推到墙角的箱 子不能再被推动。 (2)主函数中用一个while循环来实现游戏的运行。 (3)使用bioskey()函数检测键盘按键,并执行相应的动作。 (4)定义二维数组ghouse用来记录屏幕上各点的状态。 (5)自定义move()函数处理按下键盘后,人物移动。