C语言 实现推箱子游戏

#include <stdio.h>
#include <stdlib.h>//用到system()
#include <conio.h>//因为需要用到getch()函数

#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      蔚蓝之链编写    QQ:2454238510\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;
								}
						}//人在空位END
						else 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;
							}
						}//人在空位END
						else 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;
							}
						}//人在空位END
						else 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;
							}
						}//人在空位END
						else 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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值