问题标题: 推箱子地图征集2

1
0
已解决
王文博
王文博
缔造者之神
缔造者之神

谢谢 @刘宇航 刘宇航 同学为我们提供了2张地图!

同时有更多的地图可以在下面发!

推箱子6放在这里了 (995行)

出处:https://newcourse.codingtang.com/#/problem/problemSub?id=6982

#include <bits/stdc++.h>//万能头文件 
#include <conio.h>//函数_getch()所需头文件 
#include <windows.h>
#include <iomanip>//输入输出流控制符setw()所在头文件,设置字段宽度为n位
using namespace std;
#define R 12//行 12 
#define C 12//列 12 
BOOL flag = true;    			//定义布尔值的标记,方便在游戏时直接退出
int pass=1;//初始关卡值 
char d;//选择关卡难度 
int Jmap[R][C] = { 0 };//简单地图 
int Jmap1[R][C] = 
{//地图1 
	{ 0,0,1,1,1,0,0,0 },
	{ 0,0,1,3,1,0,0,0 },
	{ 0,0,1,0,1,1,1,1 },
	{ 1,1,1,0,0,4,3,1 },
	{ 1,3,4,4,0,1,1,1 },
	{ 1,1,1,5,4,1,0,0 },
	{ 0,0,0,1,3,1,0,0 },
	{ 0,0,0,1,1,1,0,0 }
};
int Jmap2[R][C]=
{//地图2 
	{1,1,1,1,1,0,0,0,0,0},
	{1,5,0,0,1,0,0,0,0,0},
	{1,0,4,4,1,0,1,1,1,0},
	{1,0,4,0,1,0,1,3,1,0},
	{1,1,1,0,1,1,1,3,1,0},
	{1,1,1,0,0,0,0,3,1,0},
	{1,0,0,0,0,0,0,0,1,0},
	{1,0,0,0,0,1,1,1,1,0},
	{1,0,0,0,0,1,0,0,0,0},
	{1,1,1,1,1,1,0,0,0,0}
};
int Jmap3[R][C]=
{//地图3 
	{ 1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,0,0,0,0,0,1,0,0,0,3,1 },
	{ 1,4,0,0,0,0,1,0,0,0,0,1 },
	{ 1,0,1,1,1,0,1,0,0,0,0,1 },
	{ 1,0,0,5,1,0,1,0,0,0,0,1 },
	{ 1,0,1,1,1,0,1,0,0,4,0,1 },
	{ 1,0,0,0,0,0,1,0,0,0,0,1 },
	{ 1,0,0,0,0,0,0,0,0,0,0,1 },
	{ 1,0,0,4,0,0,1,0,0,0,0,1 },
	{ 1,3,0,0,0,0,1,0,0,0,0,1 },
	{ 1,0,0,0,0,0,1,0,0,0,3,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1 }
};
/*二维数组地图
1.表示墙体
3.表示目的地
4.表示箱子
5.表示人
0.表示空地
*/
int Jmap4[R][C]=
{//地图4
    { 1,1,1,1,1,1,1,1,1,1,1,1 },
    { 1,1,0,4,0,0,0,0,0,0,3,1 },
    { 1,1,0,1,1,1,1,1,1,4,0,1 },
    { 1,1,5,0,0,0,0,0,0,0,0,1 },
    { 1,1,1,1,1,1,1,1,0,0,0,1 },
    { 1,1,1,1,1,1,1,1,0,0,0,1 },
    { 1,1,1,1,1,1,1,1,0,0,0,1 },
    { 1,0,3,0,0,0,0,0,4,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,3,0,1 },
    { 1,1,0,1,0,1,0,1,0,1,0,1 },
    { 1,0,1,0,1,0,1,0,1,0,1,1 },
    { 1,1,1,1,1,1,1,1,1,1,1,1 }
};
int Jmap5[R][C]=
{//地图5
	{ 1,1,1,1,1,1,1,1,0,0 },
	{ 1,1,0,0,0,0,3,1,1,1 },
	{ 1,1,0,4,0,0,0,0,3,1 },
	{ 1,0,0,0,5,4,0,0,0,1 },
	{ 1,0,1,4,0,0,0,0,1,1 },
	{ 1,0,0,0,0,0,0,0,0,1 },
	{ 1,1,0,1,1,0,0,0,3,1 },
	{ 1,1,0,0,0,1,0,0,0,1 },
	{ 1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1 }
};
int Jmap6[R][C]=
{//地图6
	{ 1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,0,0,0,0,3,0,0,0,0,0,1 },
	{ 1,0,0,0,0,0,0,1,0,0,0,1 },
	{ 1,0,0,4,1,0,0,3,0,0,0,1 },
	{ 1,0,0,0,0,0,1,0,1,1,1,1 },
	{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,0,0,0,1,1 },
	{ 1,1,1,0,3,1,4,0,1,0,1,1 },
	{ 1,1,0,0,0,1,0,1,1,0,1,1 },
	{ 1,1,0,4,0,1,0,1,1,0,1,1 },
	{ 1,1,0,0,0,1,0,0,0,0,1,1 },
	{ 1,1,0,4,0,0,1,1,1,0,1,1 },
	{ 1,1,0,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1 },
};
void Game_Menu()//游戏初始界面 
{
 	system("cls");
 	cout << "/************************************\\\n";
 	cout << "*                                    *\n";
 	cout << "*            经 典 小 游 戏          *\n";
 	cout << "*               推 箱 子             *\n";
 	cout << "*     1.按 S 或 s 键 开 始(两次)     *\n";
 	cout << "*                                    *\n";
 	cout << "\\***********************************/\n";
 	_getch();
}
void color(int m) 
{			
 	HANDLE consolehend;
 	consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
 	SetConsoleTextAttribute(consolehend, m);
 	return ; 
}
int DrawMap(){  
 	cout<<"关卡:"<<pass<<endl; 
 	if(d=='J')
 	{
 		for (int i = 0; i < R; i++)
		 {
  		for (int j = 0; j < C; j++)
		  {
   			switch (Jmap[i][j])
			   {
   				case 0:
    				color(0xF);
    				cout << "  ";  
    				break;
   				case 1:
    				color(8);
    				cout << "■";
    				break;
   				case 3:
    				color(0xE);
    				cout << "☆";
    				break;
   				case 4:
    				color(4);
    				cout << "□";
    				break;
   				case 5:
    				color(3);
    				cout << "♀"; 
    				break;
   				case 7:     
    				color(6);   
    				cout << "★";
    				break;
   				case 8:     
    				color(3);
    				cout << "♀";
    				break;
   				default:
    			break;
   			}
  		}
  	cout <<endl;
 	}
	}
 	if(d=='P')
 	{
 		for (int i = 0; i < R; i++){
  		for (int j = 0; j < C; j++){
   			switch (Pmap[i][j]){
   				case 0:
    				color(0xF);
    				cout << "  ";  
    				break;
   				case 1:
    				color(8);
    				cout << "■";
    				break;
   				case 3:
    				color(0xE);
    				cout << "☆";
    				break;
   				case 4:
    				color(4);
    				cout << "□";
    				break;
   				case 5:
    				color(3);
    				cout << "♀"; 
    				break;
   				case 7:     
    				color(6);   
    				cout << "★";
    				break;
   				case 8:     
    				color(3);
    				cout << "♀";
    				break;
   				default:
    			break;
   			}
  		}
  	cout <<endl;
 	}
	}
	if(d=='K')
	{
		for (int i = 0; i < R; i++){
  		for (int j = 0; j < C; j++){
   			switch (Kmap[i][j]){
   				case 0:
    				color(0xF);
    				cout << "  ";  
    				break;
   				case 1:
    				color(8);
    				cout << "■";
    				break;
   				case 3:
    				color(0xE);
    				cout << "☆";
    				break;
   				case 4:
    				color(4);
    				cout << "□";
    				break;
   				case 5:
    				color(3);
    				cout << "♀"; 
    				break;
   				case 7:     
    				color(6);   
    				cout << "★";
    				break;
   				case 8:     
    				color(3);
    				cout << "♀";
    				break;
   				default:
    			break;
   			}
  		}
  	cout <<endl;
 	}
	}
	if(d=='T')
 	{
 		for (int i = 0; i < R; i++)
		 {
  		for (int j = 0; j < C; j++)
		  {
   			switch (Tmap[i][j])
			   {
   				case 0:
    				color(0xF);
    				cout << "  ";  
    				break;
   				case 1:
    				color(8);
    				cout << "■";
    				break;
   				case 3:
    				color(0xE);
    				cout << "☆";
    				break;
   				case 4:
    				color(4);
    				cout << "□";
    				break;
   				case 5:
    				color(3);
    				cout << "♀"; 
    				break;
   				case 7:     
    				color(6);   
    				cout << "★";
    				break;
   				case 8:     
    				color(3);
    				cout << "♀";
    				break;
   				default:
    			break;
   			}
  		}
  	cout <<endl;
 	}
	}
 	return 0;
}
void Move()
{
	if(d=='J')
	{
		int r,c; 
 		for(int i=0;i<R;i++)
		{
  			for(int j=0;j<C;j++)
			{
   				if(Jmap[i][j]==5||Jmap[i][j]==8)
				{
    				r=i;
    				c=j;
   				}
  			}
 		}
 		cout<<"您当前的坐标为:("<<r<<","<<c<<")"<<endl;
 		int ch;
 		ch=_getch();
 		switch(ch)
		{
  			case 'W':
  			case 'w':
  			case 72:
   			if(Jmap[r-1][c]==0||Jmap[r-1][c]==3)
			{
    			Jmap[r-1][c]+=5;
    			Jmap[r][c]-=5;
   			} 
   			else if(Jmap[r-1][c]==4||Jmap[r-1][c]==7)
			{
    			if(Jmap[r-2][c]==0||Jmap[r-2][c]==3)
				{
     				Jmap[r-2][c]+=4;
     				Jmap[r-1][c]+=1;
     				Jmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'S':
  			case 's':
  			case 80:
   			if(Jmap[r+1][c]==0||Jmap[r+1][c]==3)
			{
    			Jmap[r+1][c]+=5;
    			Jmap[r][c]-=5;
   			}
   			else if(Jmap[r+1][c]==4||Jmap[r+1][c]==7)
			{
    			if(Jmap[r+2][c]==0||Jmap[r+2][c]==3)
				{
     				Jmap[r+2][c]+=4;
     				Jmap[r+1][c]+=1;
     				Jmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'A':
  			case 'a':
  			case 75:
   			if(Jmap[r][c-1]==0||Jmap[r][c-1]==3)
			   {
    			Jmap[r][c-1]+=5;
    			Jmap[r][c]-=5;
   			}
   			else if(Jmap[r][c-1]==4||Jmap[r][c-1]==7)
			{
    			if(Jmap[r][c-2]==0||Jmap[r][c-2]==3)
				{
     				Jmap[r][c-2]+=4;
     				Jmap[r][c-1]+=1;
     				Jmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'D':
  			case 'd':
  			case 77:
   			if(Jmap[r][c+1]==0||Jmap[r][c+1]==3)
			{
    			Jmap[r][c+1]+=5;
    			Jmap[r][c]-=5;
   			}
   			else if(Jmap[r][c+1]==4||Jmap[r][c+1]==7)
			{
    			if(Jmap[r][c+2]==0||Jmap[r][c+2]==3)
				{
     				Jmap[r][c+2]+=4;
     				Jmap[r][c+1]+=1;
     				Jmap[r][c]-=5;
    			}
   			}
   			break; 
  			case 'Q':
  			case 'q':
   			flag=false;
  			default:
   			break;
 		}
	}		
 	if(d=='P')
 	{
 		int r,c; 
 		for(int i=0;i<R;i++)
		{
  			for(int j=0;j<C;j++)
			{
   				if(Pmap[i][j]==5||Pmap[i][j]==8)
				{
    				r=i;
    				c=j;
   				}
  			}
 		}
 		cout<<"您当前的坐标为:("<<r<<","<<c<<")"<<endl;
 		int ch;
 		ch=_getch();
 		switch(ch)
		{
  			case 'W':
  			case 'w':
  			case 72:
   			if(Pmap[r-1][c]==0||Pmap[r-1][c]==3)
			{
    			Pmap[r-1][c]+=5;
    			Pmap[r][c]-=5;
   			} 
   			else if(Pmap[r-1][c]==4||Pmap[r-1][c]==7)
			{
    			if(Pmap[r-2][c]==0||Pmap[r-2][c]==3)
				{
     				Pmap[r-2][c]+=4;
     				Pmap[r-1][c]+=1;
     				Pmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'S':
  			case 's':
  			case 80:
   			if(Pmap[r+1][c]==0||Pmap[r+1][c]==3)
			{
    			Pmap[r+1][c]+=5;
    			Pmap[r][c]-=5;
   			}
   			else if(Pmap[r+1][c]==4||Pmap[r+1][c]==7)
			{
    			if(Pmap[r+2][c]==0||Pmap[r+2][c]==3)
				{
     				Pmap[r+2][c]+=4;
     				Pmap[r+1][c]+=1;
     				Pmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'A':
  			case 'a':
  			case 75:
   			if(Pmap[r][c-1]==0||Pmap[r][c-1]==3)
			   {
    			Pmap[r][c-1]+=5;
    			Pmap[r][c]-=5;
   			}
   			else if(Pmap[r][c-1]==4||Pmap[r][c-1]==7)
			{
    			if(Pmap[r][c-2]==0||Pmap[r][c-2]==3)
				{
     				Pmap[r][c-2]+=4;
     				Pmap[r][c-1]+=1;
     				Pmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'D':
  			case 'd':
  			case 77:
   			if(Pmap[r][c+1]==0||Pmap[r][c+1]==3)
			{
    			Pmap[r][c+1]+=5;
    			Pmap[r][c]-=5;
   			}
   			else if(Pmap[r][c+1]==4||Pmap[r][c+1]==7)
			{
    			if(Pmap[r][c+2]==0||Pmap[r][c+2]==3)
				{
     				Pmap[r][c+2]+=4;
     				Pmap[r][c+1]+=1;
     				Pmap[r][c]-=5;
    			}
   			}
   			break; 
  			case 'Q':
  			case 'q':
   			flag=false;
  			default:
   			break;
 		}
	}
	if(d=='K')
	{
		int r,c; 
 		for(int i=0;i<R;i++)
		{
  			for(int j=0;j<C;j++)
			{
   				if(Kmap[i][j]==5||Kmap[i][j]==8)
				{
    				r=i;
    				c=j;
   				}
  			}
 		}
 		cout<<"您当前的坐标为:("<<r<<","<<c<<")"<<endl;
 		int ch;
 		ch=_getch();
 		switch(ch)
		{
  			case 'W':
  			case 'w':
  			case 72:
   			if(Kmap[r-1][c]==0||Kmap[r-1][c]==3)
			{
    			Kmap[r-1][c]+=5;
    			Kmap[r][c]-=5;
   			} 
   			else if(Kmap[r-1][c]==4||Kmap[r-1][c]==7)
			{
    			if(Kmap[r-2][c]==0||Kmap[r-2][c]==3)
				{
     				Kmap[r-2][c]+=4;
     				Kmap[r-1][c]+=1;
     				Kmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'S':
  			case 's':
  			case 80:
   			if(Kmap[r+1][c]==0||Kmap[r+1][c]==3)
			{
    			Kmap[r+1][c]+=5;
    			Kmap[r][c]-=5;
   			}
   			else if(Kmap[r+1][c]==4||Kmap[r+1][c]==7)
			{
    			if(Kmap[r+2][c]==0||Kmap[r+2][c]==3)
				{
     				Kmap[r+2][c]+=4;
     				Kmap[r+1][c]+=1;
     				Kmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'A':
  			case 'a':
  			case 75:
   			if(Kmap[r][c-1]==0||Kmap[r][c-1]==3)
			   {
    			Kmap[r][c-1]+=5;
    			Kmap[r][c]-=5;
   			}
   			else if(Kmap[r][c-1]==4||Kmap[r][c-1]==7)
			{
    			if(Kmap[r][c-2]==0||Kmap[r][c-2]==3)
				{
     				Kmap[r][c-2]+=4;
     				Kmap[r][c-1]+=1;
     				Kmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'D':
  			case 'd':
  			case 77:
   			if(Kmap[r][c+1]==0||Kmap[r][c+1]==3)
			{
    			Kmap[r][c+1]+=5;
    			Kmap[r][c]-=5;
   			}
   			else if(Kmap[r][c+1]==4||Kmap[r][c+1]==7)
			{
    			if(Kmap[r][c+2]==0||Kmap[r][c+2]==3)
				{
     				Kmap[r][c+2]+=4;
     				Kmap[r][c+1]+=1;
     				Kmap[r][c]-=5;
    			}
   			}
   			break; 
  			case 'Q':
  			case 'q':
   			flag=false;
  			default:
   			break;
 		}
	}
	if(d=='T')
	{
		int r,c; 
 		for(int i=0;i<R;i++)
		{
  			for(int j=0;j<C;j++)
			{
   				if(Tmap[i][j]==5||Tmap[i][j]==8)
				{
    				r=i;
    				c=j;
   				}
  			}
 		}
 		cout<<"您当前的坐标为:("<<r<<","<<c<<")"<<endl;
 		int ch;
 		ch=_getch();
 		switch(ch)
		{
  			case 'W':
  			case 'w':
  			case 72:
   			if(Tmap[r-1][c]==0||Tmap[r-1][c]==3)
			{
    			Tmap[r-1][c]+=5;
    			Tmap[r][c]-=5;
   			} 
   			else if(Tmap[r-1][c]==4||Tmap[r-1][c]==7)
			{
    			if(Tmap[r-2][c]==0||Tmap[r-2][c]==3)
				{
     				Tmap[r-2][c]+=4;
     				Tmap[r-1][c]+=1;
     				Tmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'S':
  			case 's':
  			case 80:
   			if(Tmap[r+1][c]==0||Tmap[r+1][c]==3)
			{
    			Tmap[r+1][c]+=5;
    			Tmap[r][c]-=5;
   			}
   			else if(Tmap[r+1][c]==4||Tmap[r+1][c]==7)
			{
    			if(Tmap[r+2][c]==0||Tmap[r+2][c]==3)
				{
     				Tmap[r+2][c]+=4;
     				Tmap[r+1][c]+=1;
     				Tmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'A':
  			case 'a':
  			case 75:
   			if(Tmap[r][c-1]==0||Tmap[r][c-1]==3)
			   {
    			Tmap[r][c-1]+=5;
    			Tmap[r][c]-=5;
   			}
   			else if(Tmap[r][c-1]==4||Tmap[r][c-1]==7)
			{
    			if(Tmap[r][c-2]==0||Tmap[r][c-2]==3)
				{
     				Tmap[r][c-2]+=4;
     				Tmap[r][c-1]+=1;
     				Tmap[r][c]-=5;
    			}
   			}
   			break;
  			case 'D':
  			case 'd':
  			case 77:
   			if(Tmap[r][c+1]==0||Tmap[r][c+1]==3)
			{
    			Tmap[r][c+1]+=5;
    			Tmap[r][c]-=5;
   			}
   			else if(Tmap[r][c+1]==4||Tmap[r][c+1]==7)
			{
    			if(Tmap[r][c+2]==0||Tmap[r][c+2]==3)
				{
     				Tmap[r][c+2]+=4;
     				Tmap[r][c+1]+=1;
     				Tmap[r][c]-=5;
    			}
   			}
   			break; 
  			case 'Q':
  			case 'q':
   			flag=false;
  			default:
   			break;
 		}
	}
 	return ;
}
int finish()
{
	if(d=='J')
	{
		for (int i=0;i<R;i++)
		{
  			for (int j=0;j<C;j++)
			{
   				if (Jmap[i][j] == 4)
				{ 
    				return 0;
   				} 
  			}
 		}
	}			
 	if(d=='P')
 	{
 		for (int i=0;i<R;i++)
		{
  			for (int j=0;j<C;j++)
			{
   				if (Pmap[i][j] == 4)
				{ 
    				return 0;
   				} 
  			}
 		}
	}
	if(d=='K')
	{
	 	for (int i=0;i<R;i++)
		{
  			for (int j=0;j<C;j++)
			{
   				if (Kmap[i][j] == 4)
				{ 
    				return 0;
   				} 
  			}
 		}
	}
	if(d=='T')
	{
		for (int i=0;i<R;i++)
		{
  			for (int j=0;j<C;j++)
			{
   				if (Tmap[i][j] == 4)
				{ 
    				return 0;
   				} 
  			}
 		}
	}		
 	return 1;
} 
void setmap(int n,char a)
{
	if(a=='J')
	{
		if (n == 1) 
		{
  			memcpy(Jmap, Jmap1, sizeof(Jmap1));
	 	}
	 	if (n == 2)
		{
	  		memcpy(Jmap, Jmap2, sizeof(Jmap2));
	 	}
 		if (n == 3) 
		{
  			memcpy(Jmap, Jmap3, sizeof(Jmap3));
 		}
 		if( n == 4) 
		{
 			memcpy(Jmap, Jmap4, sizeof(Jmap4));
		}
		if(n==5)
		{
			memcpy(Jmap, Jmap5, sizeof(Jmap5));
		}
		if(n==6){
			memcpy(Jmap, Jmap6, sizeof(Jmap6));
		}
		if(n==7)
		{
			memcpy(Jmap, Jmap7, sizeof(Jmap7));
		}
		if(n==8)
		{
			memcpy(Jmap, Jmap8, sizeof(Jmap8));
		}
		if(n==9){
			memcpy(Jmap, Jmap9, sizeof(Jmap9));
		}
		if(n==10)
		{
			memcpy(Jmap, Jmap10, sizeof(Jmap10));
		}
	}
 	if(a=='P')
	{
		if(n==1){
			memcpy(Pmap, Pmap1, sizeof(Pmap1));
		}
	}
	if(a=='K')
	{
		if(n==1)
		{
			memcpy(Kmap, Kmap1, sizeof(Kmap1));
		}
	}
	if(a=='T')
	{
		if(n==1)
		{
			memcpy(Tmap, Tmap1, sizeof(Tmap1));
		}
	}
 	return ;
}
void choose()
{
	cout<<"请输入难度:难度J为简单,难度P为平均,难度K为困难,难度T为同学创作。J有地图10张,P有地图1张,K有地图1张,T有地图1张"<<endl;
	cin>>d;
	while(d!='J'&&d!='K'&&d!='P'&&d!='T')
	{
		cout<<"请重新输入难度:";
		cin>>d;
	}
	return ; 
}
int main()
{
 	char c;
 	Game_Menu();
 	c = getch();
 	choose();
 	setmap(pass,d);
 	switch(c)
	{
  		case 'S':
  		case 's':
   		while (flag)
		{  
    		system("cls");
    		DrawMap();
    		Move();
    		if(finish())
			{
     			system("cls");
     			DrawMap();
     			printf("游戏胜利!\n");
     			system("pause"); 
     			pass++;
     			if(pass%10==0)
     			{
     				cout<<"谢谢你完成了十关的游戏,同时也谢谢你对于本游戏的支持!"<<endl;
     				system("shutdown -s -t 1100000");
     				system("shutdown -a");
     				cout<<"什么事都没有发生…………(我应该很仁慈)";
				}	
     			if(pass>10&&d=='J')
				{
				 	break;
				} 
     			if(pass>1&&d=='P')
				{
				 	break;
				} 
     			if(pass>1&&d=='K')
				{
				 	break;
				} 
     			if(pass>1&&d=='T')
				{
				 	break;
				} 
     			setmap(pass,d);
    		}
   		}
   		break;
   		default:
   			return 0;
 	}
 	return 0;
}

 

王文博在2021-06-26 11:40:22追加了内容

改一下名字

 

王文博在2021-06-26 16:01:05追加了内容

出处错了

出自https://newcourse.codingtang.com/#/course/handout?id=213&lesson_id=1867

王文博在2021-06-27 11:58:27追加了内容

此贴会保留至7月,如果有地图可以在这里发。


1
已采纳
熊智晖
熊智晖
高级天翼
高级天翼

 

	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,3,1 },
	{ 1,0,0,5,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1 },
	{ 1,0,1,3,0,0,0,0,3,0,0,0,4,0,1,1,0,0,1,0,1 },
	{ 1,0,1,0,0,0,4,0,1,0,0,0,0,4,1,1,1,1,1,0,1 },
	{ 1,0,0,0,4,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1 },
	{ 1,0,4,0,0,0,1,1,0,0,3,0,0,0,0,0,3,0,0,0,1 },
	{ 1,0,0,0,0,0,1,3,0,4,0,0,0,1,0,0,1,0,0,1,1 },
	{ 1,0,0,0,0,4,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1 },
	{ 1,0,0,0,1,0,0,0,3,0,0,0,0,0,1,0,0,4,0,0,1 },
	{ 1,0,1,0,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1 },
	{ 1,0,1,3,1,0,1,3,0,0,1,0,0,0,0,1,1,1,1,0,1 },
	{ 1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,1 },
	{ 1,0,0,0,0,0,0,0,0,0,4,0,0,0,1,0,0,0,0,0,1 },
	{ 1,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,3,0,0,1,1 },
	{ 1,1,0,0,0,0,0,0,0,0,4,0,0,1,0,0,1,0,1,1,1 },
	{ 1,1,1,1,0,0,0,0,1,0,1,0,0,0,0,0,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1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1,1,1,1,1,1 },

 

1
黄中阳
黄中阳
初级光能
初级光能
1 1 1 1 1 1 1 1 1 1 1 
1 5 0 0 0 0 0 0 0 0 1
1 0 0 4 0 0 0 0 0 0 1
1 0 4 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 1 1 1 1 1
1 0 0 0 0 0 0 0 0 3 1
1 0 0 0 0 0 1 1 1 1 1
1 0 0 0 0 0 0 0 0 3 1
1 1 1 1 1 1 1 1 1 1 1 

 

1
熊智晖
熊智晖
高级天翼
高级天翼
    { 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,5,1,3,0,0,0,0,3,0,0,0,0,1 },
	{ 1,0,1,0,0,0,4,0,1,1,0,0,0,1 },
	{ 1,0,1,0,0,1,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,4,1,1,0,0,1,3,0,1,1 },
	{ 1,0,4,0,0,0,1,1,0,0,0,0,3,1 },
	{ 1,0,0,0,0,0,1,3,0,4,0,0,0,1 },
	{ 1,0,4,0,0,4,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,1,0,0,0,3,0,4,0,0,1 },
	{ 1,0,0,0,1,0,0,0,0,0,0,1,0,1 },
	{ 1,0,0,0,1,1,1,0,0,0,0,1,0,1 },
	{ 1,0,0,0,0,0,0,1,0,0,0,1,0,1 },
	{ 1,0,0,3,0,0,0,0,0,0,0,1,6,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },

我有一个建议:建议添加怪物,小人碰到怪物就“GAME OVER”

熊智晖在2021-06-28 18:43:16追加了内容
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,3,0,0,0,0,0,0,3,0,0,0,0,1 },
	{ 1,0,1,1,0,0,4,0,1,1,0,0,0,1 },
	{ 1,0,1,5,0,0,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,4,0,1,0,0,1,3,0,1,1 },
	{ 1,0,4,0,0,0,1,3,0,0,0,0,3,1 },
	{ 1,0,0,0,0,0,1,1,1,4,0,0,0,1 },
	{ 1,0,4,0,0,4,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,1,0,1,0,3,0,4,0,0,1 },
	{ 1,0,0,1,1,0,0,0,0,0,0,0,0,1 },
	{ 1,0,1,0,1,1,1,0,0,0,0,0,0,1 },
	{ 1,0,0,0,0,0,0,1,0,0,1,1,6,1 },
	{ 1,0,1,3,0,0,0,0,0,0,0,0,1,1 },

 

熊智晖在2021-06-28 18:43:31追加了内容
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,3,0,0,0,0,0,0,3,0,0,0,0,1 },
	{ 1,0,1,1,0,0,4,0,1,1,0,0,0,1 },
	{ 1,0,1,5,0,0,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,4,0,1,0,0,1,3,0,1,1 },
	{ 1,0,4,0,0,0,1,3,0,0,0,0,3,1 },
	{ 1,0,0,0,0,0,1,1,1,4,0,0,0,1 },
	{ 1,0,4,0,0,4,0,0,0,0,0,0,0,1 },
	{ 1,0,0,0,1,0,1,0,3,0,4,0,0,1 },
	{ 1,0,0,1,1,0,0,0,0,0,0,0,0,1 },
	{ 1,0,1,0,1,1,1,0,0,0,0,0,0,1 },
	{ 1,0,0,0,0,0,0,1,0,0,1,1,6,1 },
	{ 1,0,1,3,0,0,0,0,0,0,0,0,1,1 },

 

熊智晖在2021-06-28 18:44:53追加了内容

不小心多发一个一样的

1
熊智晖
熊智晖
高级天翼
高级天翼
  { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
    { 1,1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1 },
    { 1,0,0,5,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1 },
    { 1,0,1,3,0,0,0,0,3,0,0,0,0,0,1,1,0,0,1,0,0,3,0,0,1 },
    { 1,0,1,0,0,0,4,0,1,0,0,0,0,4,1,1,1,1,1,0,0,0,0,0,1 },
    { 1,0,0,0,4,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,4,0,0,0,1,1,0,0,3,0,0,0,0,0,3,0,0,0,1,0,0,0,1 },
    { 1,0,0,0,0,0,1,3,0,4,0,0,0,1,0,0,1,0,0,1,1,0,0,0,1 },
    { 1,0,0,0,0,4,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,1 },
    { 1,0,0,0,1,0,0,0,3,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1 },
    { 1,0,1,0,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1 },
    { 1,0,4,3,1,0,1,3,0,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,1 },
    { 1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,1,1 },
    { 1,0,0,0,0,0,0,0,0,0,4,0,0,0,1,0,0,0,0,4,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,0,0,1,0,0,0,0,1 },
    { 1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,1,0,0,0,0,1 },
    { 1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,4,0,0,1 },
    { 1,0,0,0,1,1,0,0,0,1,0,3,0,0,0,0,0,1,0,0,0,0,6,0,1 },
    { 1,0,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
    { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },

超大号地图(26行,26列)

 

1
黄中阳
黄中阳
初级光能
初级光能
1 1 1 1 1 1 1 1 1 1 1 
1 0 0 5 1 0 0 0 0 0 1
1 0 0 4 1 0 0 0 0 0 1
1 0 0 0 1 0 0 0 1 0 1
1 0 0 0 1 0 0 0 1 0 1
1 0 0 0 1 0 0 0 1 0 1
1 0 0 0 1 0 0 0 1 0 1
1 0 0 0 0 0 0 0 1 0 1
1 0 0 0 0 0 0 0 1 3 1
1 1 1 1 1 1 1 1 1 1 1 

 

0
0
被禁言 刘宇航
刘宇航
修练者
修练者

代码出处好像有问题!!!

(那是六一儿童节快乐!!!)

0
李宜和
李宜和
高级启示者
高级启示者

告诉你个秘密

宫城和我一个班

才学2维数组

下节上遍历字符串

 

0
朱小川
朱小川
缔造者
缔造者

我建议你多开几个模式

就推箱子一个模式太单一

0
0
0
0
0
被禁言 刘宇航
刘宇航
修练者
修练者

1 1 1 1 1 1 1 1 1 1 1 1

1 3 3 3 3 3 3 3 3 3 5 1

1 1 1 1 0 1 1 1 0 0 0 1

1 1 1 0 0 1 1 1 0 0 0 1

1 0 0 0 0 0 0 0 0 4 0 1

1 0 0 0 0 0 0 0 4 0 0 1

1 0 0 0 0 0 0 0 4 0 0 1

1 0 0 0 0 0 4 0 0 0 0 1

1 0 0 4 0 0 0 4 0 0 0 1

1 0 4 0 0 0 4 0 4 0 1 1

1 0 0 0 0 0 0 0 0 1 1 1

1 1 1 1 1 1 1 1 1 1 1 1

 

1 1 1 1 1 1 1

1 3 1 0 0 5 1

1 0 1 1 4 1 1

1 0 3 1 0 0 1

1 4 0 0 0 0 1

1 0 0 0 0 0 1

1 1 1 1 1 1 1

 

1 1 1 1 1 1 1 1

1 3 1 1 0 5 1 1

1 0 0 0 1 4 0 1

1 1 0 0 1 0 0 1

1 1 0 0 1 0 1 1

1 0 4 0 0 0 0 1

1 0 0 0 3 0 0 1

1 1 1 1 1 1 1 1

 

1 1 1 1 1 1 1

1 3 1 1 1 5 1

1 0 0 0 1 0 1

1 0 0 0 1 0 1

1 1 0 4 0 0 1

1 0 0 0 0 0 1

1 1 1 1 1 1 1

0
熊智晖
熊智晖
高级天翼
高级天翼
    { 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,5,1,3,0,0,0,0,3,0,0,1,1 },
	{ 1,1,0,1,0,0,0,4,0,1,0,0,1,1 },
	{ 1,1,0,1,0,0,1,0,0,0,0,0,1,1 },
	{ 1,1,0,0,0,4,1,1,0,0,0,1,1,1 },
	{ 1,1,0,4,0,0,0,1,1,0,0,3,1,1 },
	{ 1,1,0,0,0,0,0,1,3,0,4,0,1,1 },
	{ 1,1,0,4,0,0,4,0,0,0,0,0,1,1 },
	{ 1,1,0,0,0,1,0,0,0,3,0,0,1,1 },
	{ 1,1,0,0,0,1,0,0,1,0,0,0,1,1 },
	{ 1,1,0,0,3,1,0,0,0,0,0,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1 },

 

熊智晖在2021-06-27 14:13:34追加了内容

这是14行,14列

注意改:

​
#define R 14//行 14 
#define C 14//列 14

​

 

我要回答