C语言实现『推箱子』

推箱子 是我们小时候在电视机上常见的经典电子游戏,游戏要求玩家在一个狭小的仓库中,把木箱放到指定的位置,稍不小心就会出现箱子无法移动或者通道被堵住的情况,所以需要巧妙的利用有限的空间和通道,合理安排移动的次序和位置,才能顺利的完成任务。

那么,如何通过C语言编程将这一经典游戏再现在控制台上呢?
要求:
1.关卡容易修改、编辑。
2.能用英文输入法中的w、a、s、d控制人物的上、左、下、右。
3.在游戏中能够随时重来关卡。
4.能够记录游戏步数。
5.最大化地还原游戏。(拥有该游戏的基本要素:墙、人物、箱子、目的点等)

我们就试着还原这个关卡吧:
推箱子
我们在玩这个游戏的时候,人物是在一张地图上移动的,在开始游戏前,我们们就要先设计出这张地图,然后才能进行操作。

我们发现人物、箱子、墙等都是由一个一个的小正方形表示的,那么我们进行输出的时候就要输出一个一个正方形字符或图案用来代替游戏中的元素,所以我们最好输出全角字符或者一次性输出两个半角字符(因为在控制台上全角字符占的位置是正方形,而半角的标准字符是一个长宽比为2的长方形)。

我们将地图放在什么地方才好进行输出和处理呢?
这时候我们可以用二维整型数组来存储并随时进行处理这张地图。我们可以用不同的数字来代替不同的方块,用简单的加法处理方块叠加的问题(当人站在目的点的时候、当箱子被推向目的点的时候、当人从目的点离开的时候、当箱子从目的点被推开的时候),例如设人为10、目的点为2、空白点为1,当人站在目的点的时候,人所在的方块数值为10+2=12,当人走开的时候,方块数值恢复为原来的10。但是这些数字之间要避免存在叠加混淆的情况,例如设人为1、目的点为2、箱子为3,这种设计就是不合理的(除非用其他的运算解决叠加问题),因为当人站在目的点的时候人所在的方块数值为3,与箱子混淆。

基于以上的设想,我们定义一个50×50的二维整型数组map[50][50]。然后给数组赋不同的元素的值:
1.可供人物行走的空白以及墙体之外的空间,赋值为1。
2.游戏人物,赋值为3。
3.游戏中的箱子,赋值为7。
4.游戏中的墙体,赋值为13。
5.目的点,赋值为51。
当然,以上赋的值可以自由合理选择。
那么,如何将游戏地图存入数组中便于输出和处理呢?
对比游戏地图和数组各元素之间的输出分布,我们可以以游戏地图的左上角为原点,向右为x轴正方向,向下为y轴正方向建立平面直角坐标系,且定义游戏地图上的左上角的方块的位置为第一行第一列,记作map[1][1]。若是第二行第三列,就记作map[2][3]

还需要考虑几种方块元素叠加的情况:
1.当人物在空白上时,也就是空白和人物叠加时,赋值为3。
2.当人物与箱子的目的点重合时,赋值为3+51=54。
3.当箱子成功推向目的点,箱子与目的点重合时,赋值为7+51=58。
写一个初始化地图的函数,并能返回最大行数和最大列数:

void interface_v3(int a[50][50],int* max_Lines,int* max_Rows)//初始化地图。 
{	
	//地图中的元素能够自由编辑
	//空白为1;人为3;墙为13;箱子为7;目的点为51;
	//以地图左上角为原点,向右为x轴正方向,向下为y轴正方向建立平面直角坐标系
	//第2行第3列记作a[2][3]。 
	int b,c;
	for(b=0;b<50;b++)
		for(c=0;c<50;c++)
			a[b][c]=1;//赋空白地图为1。
	
	//设置墙
	for(b=4;b<=10;b++)
		a[1][b]=13;
	for(b=1;b<=4;b++)
		a[2][b]=13;
	for(b=2;b<=13;b++)
		a[11][b]=13;
	for(b=6;b<=8;b++)
		a[3][b]=13;
	for(b=4;b<=6;b++)
		a[9][b]=13;
	for(b=8;b<=9;b++)
		a[10][b]=13;
	for(b=3;b<=8;b++)
		a[b][1]=13;
	for(b=8;b<=10;b++)
		a[b][2]=13;
	for(b=2;b<=4;b++)
		a[b][10]=13;
	for(b=4;b<=8;b++)
		a[b][11]=13;
	for(b=8;b<=10;b++)
		a[b][13]=13;
	for(b=4;b<=6;b++)
		a[b][3]=13;
	for(b=6;b<=8;b++)
		a[b][9]=13;
	a[4][5]=13;
	a[5][8]=13;
	a[7][4]=13;
	a[8][7]=13;
	a[8][12]=13;
	//设置墙
	
	//设置箱子
	a[5][5]=7;
	a[5][7]=7;
	a[7][5]=7;
	a[7][7]=7;
	//设置箱子
	
	//设置已经摆放好的箱子 
	a[6][6]=58;
	//设置已经摆放好的箱子
	
	//设置目的点 
	a[3][5]=51;
	a[5][9]=51;
	a[7][3]=51;
	a[9][7]=51;
	//设置目的点 
	
	//设置人物初始位置
	a[9][12]=3;
	//设置人物初始位置
	
	//设置地图的最大行数和最大列数 
	*max_Lines=11;//行数 
	*max_Rows=13; //列数 
	//设置地图的最大行数和最大列数 
}

这样,我们还需设定一些全角字符来代替不同的元素,可按个人喜好来:
1.空白空间:“ ”(双空格)
2.人:“
3.箱子:“
4.墙:“×
5.目的点:“
6.已经成功推好的箱子:“
然后再写一个函数进行输出:

void ofOutput(int a[50][50],int max_Lines,int max_Rows)
{
	int b,c;
	for(b=1;b<=max_Lines;b++)
		{
			printf("\n");
			for(c=1;c<=max_Rows;c++)
				{
					if(a[b][c]==1)
						printf("  ");//空白
					if(a[b][c]==3||a[b][c]==54)
						printf("£");//人
					if(a[b][c]==13)
						printf("×");//墙
					if(a[b][c]==7)
						printf("☆");//箱子 
					if(a[b][c]==58)
						printf("★");//成功的箱子
					if(a[b][c]==51)
						printf("●");//目的点 
				}
		}
	printf("\n");
}

现在地图的输出问题解决了,还有操控人物的问题,这也是程序的关键所在。
这时我们需要一个自动读取键值、无需回车并且不回显的函数:
getch( )←(点击这里查看详情)
不过这个函数并不是标准函数,需要头文件:conio.h

#include<conio.h>

当我们按下w或W时,这是控制人物向上运动的指令,我们用1来代替这个指令并写一个函数返回这个指令;同理,a或A代表左,返回2……我们顺便再让z或Z来表示重来游戏,返回5。

int check_inputs(int a)
{//a代表getch()函数的返回值。
	while(1)
		{
			if(a==87||a==119)
				return 1;//上
			if(a==65||a==97)
				return 2;//左
			if(a==83||a==115)
				return 3;//下
			if(a==68||a==100)
				return 4;//右
			if(a==90||a==122)
				return 5;//重来 
			a=getch();
		}	 
}

最重要的来了,人物动了之后,之前定义的数组里面的数据发生了怎样的变化?

先要确定人物的当前位置,我们可以定义一个positioning( )函数来确定人物的位置,返回人物的列数和行数。但是我们一般认为返回多个数值需要借助于指针,但是对于这种简单的数据,我们可以返回一个四位数:万位和千位是行数、十位和个位是列数,这样同样也可以返回我们想要的结果:

int positioning(int a[][50])
{
	int b,c,d=0;
	for(b=1;b<50;b++)
		{
			
			for(c=1;c<50;c++)
				{
					if(a[b][c]==3||a[b][c]==54)
						{
							d=1;
							break;
						}
				}
			if(d)
				return (100*b+c);
		}
}

然后再定义两个变量LinesRows来获取positioning( )函数返回值中的行数和列数:

int Rows,Lines;
Rows=positioning(map)%100;//列数
Lines=(positioning(map)-Rows)/100;//行数

无论人物往哪里动,只要分析人物下一个落脚点的方块元素即可:

1.当下一个方块是空白(值为1)时,两种情况:
人物本来就站在目的点上(值为54),那么下一个方块就会被赋值为3(人),本来的方块就会被赋值为51(目的点)。
人物本来站在空地上,那么下一个方块就会被赋值为3,本来的方块就会被赋值为1。

2.当下一个方块是目的点(值为51)时,两种情况:
人物本来就站在目的点上(值为54),那么下一个方块就会被赋值为54,本来的方块就会被赋值为51(目的点)。
人物本来站在空地上,那么下一个方块就会被赋值为54,本来的方块就会被赋值为1。

3.当下一个方块是箱子(值为7)时,四种情况:
箱子的后面(人在箱子前面)是目的点并且人也站在目的点时,那么箱子后面的方块就会被赋值为58(箱子与目的点重合),箱子所在的方块赋值为3(人),人原本所在的方块被赋值为51(目的点)。
箱子的后面(人在箱子前面)是空白并且人站在目的点时,那么箱子后面的方块就会被赋值为7(箱子),箱子所在的方块赋值为3(人),人原本所在的方块被赋值为51(目的点)。
箱子的后面(人在箱子前面)是目的点并且人站在空白时,那么箱子后面的方块就会被赋值为58(箱子与目的点重合),箱子所在的方块赋值为3(人),人原本所在的方块被赋值为1(空白)。
箱子的后面(人在箱子前面)是空白并且人也站在空白时,那么箱子后面的方块就会被赋值为7(箱子),箱子所在的方块赋值为3(人),人原本所在的方块被赋值为1(空白)。

4.当下一个方块是箱子与目的点重合的成功箱子(值为58)时,也有四种情况:
箱子的后面(人在箱子前面)是目的点并且人也站在目的点时,那么箱子后面的方块就会被赋值为58(箱子与目的点重合),箱子所在的方块赋值为54(人与目的点重合),人原本所在的方块被赋值为51(目的点)。
箱子的后面(人在箱子前面)是空白并且人站在目的点时,那么箱子后面的方块就会被赋值为7(箱子),箱子所在的方块赋值为54(人与目的点重合),人原本所在的方块被赋值为51(目的点)。
箱子的后面(人在箱子前面)是目的点并且人站在空白时,那么箱子后面的方块就会被赋值为58(箱子与目的点重合),箱子所在的方块赋值为54(人与目的点重合),人原本所在的方块被赋值为1(空白)。
箱子的后面(人在箱子前面)是空白并且人也站在空白时,那么箱子后面的方块就会被赋值为7(箱子),箱子所在的方块赋值为54(人与目的点重合),人原本所在的方块被赋值为1(空白)。

要是有其余的情况,则不予理会,数组中的值也不会发生变动。

若按下w或W,人物就会向上运动,程序就这样可以编写:(以下程序只是人物向上运动一种情况)

int Keyboards;
Keyboards=getch();
Keyboards=check_inputs(Keyboards);
Rows=positioning(map)%100;//列数
Lines=(positioning(map)-Rows)/100;//行数
if(Keyboards==1)//假如按下w或W,人物向上运动
	{
		isNext=map[Lines-1][Rows];
		if(isNext==1)
			{
				if(map[Lines][Rows]==54)
					{
						map[Lines-1][Rows]=3;
						map[Lines][Rows]=51;
					}
				else 
					{
						map[Lines-1][Rows]=3;
						map[Lines][Rows]=1;
					}
			}
		if(isNext==51)
			{
				if(map[Lines][Rows]==54)
					{
						map[Lines-1][Rows]=54;
						map[Lines][Rows]=51;
					}
				else
					{
						map[Lines-1][Rows]=54;
						map[Lines][Rows]=1;
					}
			}
		if(isNext==7)
			{
				if(map[Lines][Rows]==54&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
					if(map[Lines-2][Rows]==51)
						{
							map[Lines-2][Rows]=58;
							map[Lines-1][Rows]=3;
							map[Lines][Rows]=51;
						}
					else
						{
							map[Lines-2][Rows]=7;
							map[Lines-1][Rows]=3;
							map[Lines][Rows]=51;
						}
				if(map[Lines][Rows]==3&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
					if(map[Lines-2][Rows]==51)
						{
							map[Lines-2][Rows]=58;
							map[Lines-1][Rows]=3;
							map[Lines][Rows]=1;
						}
					else
						{
							map[Lines-2][Rows]=7;
							map[Lines-1][Rows]=3;
							map[Lines][Rows]=1;
						}
			}
		if(isNext==58)
			{
				if(map[Lines][Rows]==54&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
					if(map[Lines-2][Rows]==51)
						{
							map[Lines-2][Rows]=58;
							map[Lines-1][Rows]=54;
							map[Lines][Rows]=51;
						}
					else
						{
							map[Lines-2][Rows]=7;
							map[Lines-1][Rows]=54;
							map[Lines][Rows]=51;
						}
				if(map[Lines][Rows]==3&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
					if(map[Lines-2][Rows]==51)
						{
							map[Lines-2][Rows]=58;
							map[Lines-1][Rows]=54;
							map[Lines][Rows]=1;
						}
					else
						{
							map[Lines-2][Rows]=7;
							map[Lines-1][Rows]=54;
							map[Lines][Rows]=1;
						}
			}
	}

然后再循环输出数组就可以了。

当然,每操作一次,我们都要判断游戏是否结束了:
定义pos_victory_6( )函数判断结束:

void pos_victory_6(int a[][50])
{
	int b,c,d=0;
	for(b=1;b<50;b++)
		for(c=1;c<50;c++)
			if(a[b][c]==7)
				d=1;
	if(!d)
		{
			printf("\n恭喜你,胜利了!\n\n按任意键结束程序……");
			getch();
			exit (0);
		}
}

还要能随时按z或Z重来游戏:

haha:interface_v3(map,&max_Lines,&max_Rows);
//
	游戏处理
//
if(Keyboards==5)
	goto haha;

这里用到了goto无条件转移语句

为了能够将数组在同一块区域中不停刷新输出,我们还需要gotoxy( )函数:

#include<windows.h>
void gotoxy(short x, short y)
{
	COORD coord = {x, y};
  	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

还有最后一个功能就是计步功能:

int count;
count=0;
//
	游戏处理
//
if(Rows!=positioning(map)%100||Lines!=(positioning(map)-Rows)/100)
	count=count+1;

综合以上,最终完成的代码完成了!

#include<stdio.h>
#include<conio.h>
#include<windows.h>
void gotoxy(short x, short y)
{
	COORD coord = {x, y};
  	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void interface_v3(int a[50][50],int* max_Lines,int* max_Rows)//初始化地图。 
{	
	//空白为1;人为3;墙为13;箱子为7;目的点为51;
	//以地图左上角为原点,向右为x轴正方向,向下为y轴正方向建立平面直角坐标系
	//第2行第3列记作a[2][3]。 
	int b,c;
	for(b=0;b<50;b++)
		for(c=0;c<50;c++)
			a[b][c]=1;//赋空白地图为1。
	
	//设置墙
	for(b=4;b<=10;b++)
		a[1][b]=13;
	for(b=1;b<=4;b++)
		a[2][b]=13;
	for(b=2;b<=13;b++)
		a[11][b]=13;
	for(b=6;b<=8;b++)
		a[3][b]=13;
	for(b=4;b<=6;b++)
		a[9][b]=13;
	for(b=8;b<=9;b++)
		a[10][b]=13;
	for(b=3;b<=8;b++)
		a[b][1]=13;
	for(b=8;b<=10;b++)
		a[b][2]=13;
	for(b=2;b<=4;b++)
		a[b][10]=13;
	for(b=4;b<=8;b++)
		a[b][11]=13;
	for(b=8;b<=10;b++)
		a[b][13]=13;
	for(b=4;b<=6;b++)
		a[b][3]=13;
	for(b=6;b<=8;b++)
		a[b][9]=13;
	a[4][5]=13;
	a[5][8]=13;
	a[7][4]=13;
	a[8][7]=13;
	a[8][12]=13;
	//设置墙
	
	//设置箱子
	a[5][5]=7;
	a[5][7]=7;
	a[7][5]=7;
	a[7][7]=7;
	//设置箱子
	
	//设置已经摆放好的箱子 
	a[6][6]=58;
	//设置已经摆放好的箱子
	
	//设置目的点 
	a[3][5]=51;
	a[5][9]=51;
	a[7][3]=51;
	a[9][7]=51;
	//设置目的点 
	
	//设置人物初始位置
	a[9][12]=3;
	//设置人物初始位置
	
	//设置地图的最大行数和最大列数 
	*max_Lines=11;//行数 
	*max_Rows=13; //列数 
	//设置地图的最大行数和最大列数 
}
void ofOutput(int a[50][50],int max_Lines,int max_Rows)
{
	int b,c;
	for(b=1;b<=max_Lines;b++)
		{
			printf("\n");
			for(c=1;c<=max_Rows;c++)
				{
					if(a[b][c]==1)
						printf("  ");//空白
					if(a[b][c]==3||a[b][c]==54)
						printf("£");//人
					if(a[b][c]==13)
						printf("×");//墙
					if(a[b][c]==7)
						printf("☆");//箱子 
					if(a[b][c]==58)
						printf("★");//成功的箱子
					if(a[b][c]==51)
						printf("●");//目的点 
				}
		}
	printf("\n");
}
int check_inputs(int a)
{
	while(1)
		{
			if(a==87||a==119)
				return 1;//上
			if(a==65||a==97)
				return 2;//左
			if(a==83||a==115)
				return 3;//下
			if(a==68||a==100)
				return 4;//右
			if(a==90||a==122)
				return 5;//重来 
			a=getch();
		}	 
}
int positioning(int a[][50])
{
	int b,c,d=0;
	for(b=1;b<50;b++)
		{
			
			for(c=1;c<50;c++)
				{
					if(a[b][c]==3||a[b][c]==54)
						{
							d=1;
							break;
						}
				}
			if(d)
				return (100*b+c);//个位是列数 
		}
}
void pos_victory_6(int a[][50])
{
	int b,c,d=0;
	for(b=1;b<50;b++)
		for(c=1;c<50;c++)
			if(a[b][c]==7)
				d=1;
	if(!d)
		{
			printf("\n恭喜你,胜利了!\n\n按任意键结束程序……");
			getch();
			exit (0);
		}
}
int main()
{
	int map[50][50],Keyboards,Lines,Rows,isNext,count,max_Rows,max_Lines;
	haha:interface_v3(map,&max_Lines,&max_Rows);
	count=0;
	while(1)
		{
			gotoxy(0,0);
			printf("用英文输入法的w(W)、a(A)、s(S)、d(D)进行控制\n将☆全部推至●即可\n输入z(Z)可重来\n");
			ofOutput(map,max_Lines,max_Rows);
			printf("\n步数:%d\t",count);
			pos_victory_6(map);
			Keyboards=getch();
			Keyboards=check_inputs(Keyboards);
			
			Rows=positioning(map)%100;//列数
			Lines=(positioning(map)-Rows)/100;//行数
			
			if(Keyboards==1)
				{
					isNext=map[Lines-1][Rows];
					if(isNext==1)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines-1][Rows]=3;
									map[Lines][Rows]=51;
								}
							else 
								{
									map[Lines-1][Rows]=3;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==51)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines-1][Rows]=54;
									map[Lines][Rows]=51;
								}
							else
								{
									map[Lines-1][Rows]=54;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==7)
						{
							if(map[Lines][Rows]==54&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
								if(map[Lines-2][Rows]==51)
									{
										map[Lines-2][Rows]=58;
										map[Lines-1][Rows]=3;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines-2][Rows]=7;
										map[Lines-1][Rows]=3;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
								if(map[Lines-2][Rows]==51)
									{
										map[Lines-2][Rows]=58;
										map[Lines-1][Rows]=3;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines-2][Rows]=7;
										map[Lines-1][Rows]=3;
										map[Lines][Rows]=1;
									}
						}
					if(isNext==58)
						{
							if(map[Lines][Rows]==54&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
								if(map[Lines-2][Rows]==51)
									{
										map[Lines-2][Rows]=58;
										map[Lines-1][Rows]=54;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines-2][Rows]=7;
										map[Lines-1][Rows]=54;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines-2][Rows]==1||map[Lines-2][Rows]==51))
								if(map[Lines-2][Rows]==51)
									{
										map[Lines-2][Rows]=58;
										map[Lines-1][Rows]=54;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines-2][Rows]=7;
										map[Lines-1][Rows]=54;
										map[Lines][Rows]=1;
									}
						}
				}
			if(Keyboards==3)
				{
					isNext=map[Lines+1][Rows];
					if(isNext==1)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines+1][Rows]=3;
									map[Lines][Rows]=51;
								}
							else 
								{
									map[Lines+1][Rows]=3;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==51)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines+1][Rows]=54;
									map[Lines][Rows]=51;
								}
							else
								{
									map[Lines+1][Rows]=54;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==7)
						{
							if(map[Lines][Rows]==54&&(map[Lines+2][Rows]==1||map[Lines+2][Rows]==51))
								if(map[Lines+2][Rows]==51)
									{
										map[Lines+2][Rows]=58;
										map[Lines+1][Rows]=3;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines+2][Rows]=7;
										map[Lines+1][Rows]=3;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines+2][Rows]==1||map[Lines+2][Rows]==51))
								if(map[Lines+2][Rows]==51)
									{
										map[Lines+2][Rows]=58;
										map[Lines+1][Rows]=3;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines+2][Rows]=7;
										map[Lines+1][Rows]=3;
										map[Lines][Rows]=1;
									}
						}
					if(isNext==58)
						{
							if(map[Lines][Rows]==54&&(map[Lines+2][Rows]==1||map[Lines+2][Rows]==51))
								if(map[Lines+2][Rows]==51)
									{
										map[Lines+2][Rows]=58;
										map[Lines+1][Rows]=54;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines+2][Rows]=7;
										map[Lines+1][Rows]=54;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines+2][Rows]==1||map[Lines+2][Rows]==51))
								if(map[Lines+2][Rows]==51)
									{
										map[Lines+2][Rows]=58;
										map[Lines+1][Rows]=54;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines+2][Rows]=7;
										map[Lines+1][Rows]=54;
										map[Lines][Rows]=1;
									}
						}
				}
			if(Keyboards==2)
				{
					isNext=map[Lines][Rows-1];
					if(isNext==1)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines][Rows-1]=3;
									map[Lines][Rows]=51;
								}
							else 
								{
									map[Lines][Rows-1]=3;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==51)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines][Rows-1]=54;
									map[Lines][Rows]=51;
								}
							else
								{
									map[Lines][Rows-1]=54;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==7)
						{
							if(map[Lines][Rows]==54&&(map[Lines][Rows-2]==1||map[Lines][Rows-2]==51))
								if(map[Lines][Rows-2]==51)
									{
										map[Lines][Rows-2]=58;
										map[Lines][Rows-1]=3;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines][Rows-2]=7;
										map[Lines][Rows-1]=3;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines][Rows-2]==1||map[Lines][Rows-2]==51))
								if(map[Lines][Rows-2]==51)
									{
										map[Lines][Rows-2]=58;
										map[Lines][Rows-1]=3;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines][Rows-2]=7;
										map[Lines][Rows-1]=3;
										map[Lines][Rows]=1;
									}
						}
					if(isNext==58)
						{
							if(map[Lines][Rows]==54&&(map[Lines][Rows-2]==1||map[Lines][Rows-2]==51))
								if(map[Lines][Rows-2]==51)
									{
										map[Lines][Rows-2]=58;
										map[Lines][Rows-1]=54;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines][Rows-2]=7;
										map[Lines][Rows-1]=54;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines][Rows-2]==1||map[Lines][Rows-2]==51))
								if(map[Lines][Rows-2]==51)
									{
										map[Lines][Rows-2]=58;
										map[Lines][Rows-1]=54;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines][Rows-2]=7;
										map[Lines][Rows-1]=54;
										map[Lines][Rows]=1;
									}
						}
				}
			if(Keyboards==4)
				{
					isNext=map[Lines][Rows+1];
					if(isNext==1)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines][Rows+1]=3;
									map[Lines][Rows]=51;
								}
							else 
								{
									map[Lines][Rows+1]=3;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==51)
						{
							if(map[Lines][Rows]==54)
								{
									map[Lines][Rows+1]=54;
									map[Lines][Rows]=51;
								}
							else
								{
									map[Lines][Rows+1]=54;
									map[Lines][Rows]=1;
								}
						}
					if(isNext==7)
						{
							if(map[Lines][Rows]==54&&(map[Lines][Rows+2]==1||map[Lines][Rows+2]==51))
								if(map[Lines][Rows+2]==51)
									{
										map[Lines][Rows+2]=58;
										map[Lines][Rows+1]=3;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines][Rows+2]=7;
										map[Lines][Rows+1]=3;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines][Rows+2]==1||map[Lines][Rows+2]==51))
								if(map[Lines][Rows+2]==51)
									{
										map[Lines][Rows+2]=58;
										map[Lines][Rows+1]=3;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines][Rows+2]=7;
										map[Lines][Rows+1]=3;
										map[Lines][Rows]=1;
									}
						}
					if(isNext==58)
						{
							if(map[Lines][Rows]==54&&(map[Lines][Rows+2]==1||map[Lines][Rows+2]==51))
								if(map[Lines][Rows+2]==51)
									{
										map[Lines][Rows+2]=58;
										map[Lines][Rows+1]=54;
										map[Lines][Rows]=51;
									}
								else
									{
										map[Lines][Rows+2]=7;
										map[Lines][Rows+1]=54;
										map[Lines][Rows]=51;
									}
							if(map[Lines][Rows]==3&&(map[Lines][Rows+2]==1||map[Lines][Rows+2]==51))
								if(map[Lines][Rows+2]==51)
									{
										map[Lines][Rows+2]=58;
										map[Lines][Rows+1]=54;
										map[Lines][Rows]=1;
									}
								else
									{
										map[Lines][Rows+2]=7;
										map[Lines][Rows+1]=54;
										map[Lines][Rows]=1;
									}
						}
				}
			if(Keyboards==5)
				goto haha; 
			if(Rows!=positioning(map)%100||Lines!=(positioning(map)-Rows)/100)
				count=count+1;
		}
}

运行:
推箱子
看你过关需要多少步,快来挑战吧!

  • 9
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lias Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值