跳到正文

剪贴板

剪贴板 lyqricmo

原文
剪贴板信息

剪贴板信息

收录
更新

地图

C++
#include <bits/stdc++.h>
#include<windows.h>
using namespace std;
const int block_kind=100;
const int d_hel=50,d_space=50,d_ground=40,d_under_ground=60,wide_=800,length_=200;
struct block
{
	char name;
	int num;
	string sib;
	int color;
	int hard;
}s[length_][wide_];
struct node
{
	int x;
	int y;
};
int id[block_kind];
struct info
{
	char name;
	int num;
	string sib;
	int color;
	int hard;
}nf[block_kind];
void set_s(int i,int j,char ch)
{
	if(i<0||i>=200||j<0||j>=800)
	{
		return;
	}
	s[i][j].name=nf[id[ch]].name;
	s[i][j].num=nf[id[ch]].num;
	s[i][j].sib=nf[id[ch]].sib;
	s[i][j].color=nf[id[ch]].color;
	s[i][j].hard=nf[id[ch]].hard;
}
char get_(int x,int y)
{
	return s[x][y].name;
}
void bfs_o(int n,int x,int y,char ch,int pos,int up)
{
	if(x>up) return;
	queue <node> q;
	int cnt=0;
	int dx[5]={0,0,0,0,0},dy[5]={0,0,0,0,0};
	bool vis[length_][wide_];
	memset(vis,0,sizeof vis);
	int rp=rand()%4+1,rq=rand()%4+1;
	while(rp==rq) rq=rand()%4+1;
	dy[rp]=1;
	dy[rq]=-1;
	bool flag;
	flag=rand()%2;
	for(int i=1;i<=4;i++)
	{
		if(i==rp||i==rq) continue;
		if(flag==1) dx[i]=1,flag=0;
		else dx[i]=-1,flag=1;
	}
	dx[rp]=dx[rq]=0;
	q.push({x,y});
	int plus,y_plus;
	while(!q.empty())
	{
		node t=q.front();q.pop();
		cnt++;
		if(cnt>n) break;
		if(t.x+pos>up) continue;
		set_s(t.x+pos,t.y,ch);
		for(int i=1;i<=4;i++)
		{
			plus=rand()%5;
			y_plus=rand()%10;
			if(vis[t.x+dx[i]][t.y+dy[i]]) continue;
			if(t.x+dx[i]<0||t.x+dx[i]>length_-1||t.x+dx[i]>up) continue;
			if(t.y+dy[i]<1||t.y+dy[i]>wide_-1) continue;

			if(plus>=i) q.push({t.x+dx[i],t.y+dy[i]});
			else if((dy[i]!=0)&&y_plus>2) q.push({t.x+dx[i],t.y+dy[i]});
		}
	}
}
void dfs_l(int x,int y,int n,int m,int r,char ch,int pos,int up)
{
	int dx[10]={0,1,0,1,0,-1,0,-1,0};
	int dy[10]={0,-1,1,1,1,1,-1,-1,-1};
	for(int i=1;i<=m;i++)
	{
		int change=rand()%5;
		if(!change)
		{
			r=rand()%8+1;
		}
		bfs_o(n,x,y,ch,pos,up);
		int mv=rand()%5+1;
		for(int j=1;j<=mv;j++)
		{
			int ism=rand()%3;
			int rdr=rand()%8;
			if(ism)
			{
				x+=dx[r];
				y+=dy[r];
			}
			else
			{
				x+=dx[rdr];
				y+=dy[rdr];
			}
		}
		if(y>wide_-1||x>length_-1||y<1||x<1||x>up) return;
	}
}
void stone_birth()
{
	int nob,pob,noc;
	for(int i=1;i<d_ground;i++)
	{
		noc=rand()%15+5;
		for(int j=1;j<=noc;j++)
		{
			nob=rand()%(60*length_*wide_/200/800)+20*length_*wide_/200/800;
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,'S',d_space+d_ground,d_space+d_ground+d_under_ground);
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,'S',d_space+d_ground,d_space+d_ground+d_under_ground);
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,'S',d_space+d_ground,d_space+d_ground+d_under_ground);
		}
	}
}
void dirt_birth()
{
	int nob,pob,noc;
	int dx[9]={-1,-1,-1,0,0,0,1,1,1},dy[9]={-1,0,1,-1,0,1,-1,0,1};
	for(int i=1;i<d_ground;i++)
	{
		noc=rand()%8+4;
		for(int j=1;j<=noc;j++)
		{
			nob=rand()%(80*length_*wide_/200/800)+30*length_*wide_/200/800;
			pob=rand()%(wide_-2)+1;
			bfs_o(nob,i,pob,'D',d_space,d_space+d_ground);
			pob=rand()%(wide_-2)+1;
			bfs_o(nob,i,pob,'D',d_space,d_space+d_ground);
			pob=rand()%(wide_-2)+1;
			bfs_o(nob,i,pob,'D',d_space,d_space+d_ground);
			pob=rand()%(wide_-2)+1;
			bfs_o(nob,i,pob,'D',d_space,d_space+d_ground);
		}
	}
	for(int i=1;i<wide_;i++)
	{
		if(s[d_space+1][i].name!=' ') set_s(d_space,i,'D');
	}
	bool plc=1;
	for(int i=1;i<wide_;i++)
	{
		int isd=rand()%8;
		if(!(plc||(!(rand()%40))))
		{
			plc=0;
			continue;
		}
		if((plc&&(rand()%3))||isd) set_s(d_space-1,i,'D');
		plc=isd;
	}
	plc=0;
	for(int i=2;i<wide_-1;i++)
	{
		int isd=rand()%5;
		if(((plc&&(rand()%3))||isd)&&s[d_space-1][i].name=='D'&&s[d_space-1][i-1].name=='D'&&s[d_space-1][i+1].name=='D') set_s(d_space-2,i,'D');
		plc=isd;
	}
	for(int i=-2;i<=1;i++)
	{
		for(int j=1;j<800;j++)
		{
			if(get_(d_space+i,j)=='D')
			{
				int sum_air=0;
				for(int k=0;k<9;k++)
				{
					if(get_(d_space+i+dx[k],j+dy[k])==' ') sum_air++;
				}
				if(sum_air>=3) s[d_space+i][j].color=2;
			}
		}
	}
}
void gold_birth()
{
	int nob,pob,noc;
	for(int i=18.0/45*d_under_ground;i<=29.0/45*d_under_ground;i++)
	{
		noc=rand()%3;
		for(int j=1;j<=noc;j++)
		{
			nob=rand()%(10*length_*wide_/200/800)+3*length_*wide_/200/800;
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,'G',d_space+d_ground,d_space+d_ground+d_under_ground);
		}
	}
	for(int i=30.0*45/d_under_ground;i<d_under_ground;i++)
	{
		noc=rand()%3;
		for(int j=1;j<=noc;j++)
		{
			nob=rand()%(20*length_*wide_/200/800)+3*length_*wide_/200/800;
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,'G',d_space+d_ground,d_space+d_ground+d_under_ground);
		}
	}
}
void iron_birth()
{
	int nob,pob,noc;
	for(int i=1;i<=32.0/45*d_under_ground;i++)
	{
		noc=rand()%4;
		for(int j=1;j<=noc;j++)
		{
			nob=rand()%30+5;
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,'I',d_space+d_ground,d_space+d_ground+d_under_ground);
		}
	}
	for(int i=33.0/45*d_under_ground;i<d_under_ground;i++)
	{
		noc=rand()%4;
		for(int j=1;j<=noc;j++)
		{
			nob=rand()%(10*length_*wide_/200/800)+5*length_*wide_/200/800;
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,'I',d_space+d_ground,d_space+d_ground+d_under_ground);
		}
	}
}
void long_space_birth(int pos,int up)
{
	int nob,pob,noc;
	for(int i=5.0/45*d_under_ground;i<=40.0/45*d_under_ground;i++)
	{
		int yn=rand()%2;
		if(yn) continue;
		nob=rand()%(70*length_*wide_/200/800)+40*length_*wide_/200/800;
		int l=rand()%(60*length_*wide_/200/800)+20*length_*wide_/200/800;
		pob=rand()%(wide_-2)+1;
		int r=rand()%12+1;
		if(r==9||r==10) dfs_l(i,pob,nob,l,8,' ',pos,up);
		else if(r==11||r==12) dfs_l(i,pob,nob,l,4,' ',pos,up);
		else dfs_l(i,pob,nob,l,r,' ',pos,up);
	}
}
void space_birth(int pos,int up)
{
	int nob,pob,noc;
	for(int i=5.0/45*d_under_ground;i<=40.0/45*d_under_ground;i+=2.0/45*d_under_ground)
	{
		noc=rand()%5+3;
		for(int j=1;j<=noc;j++)
		{
			nob=rand()%(400*length_*wide_/200/800)+80*length_*wide_/200/800;
			pob=rand()%(wide_-4);
			bfs_o(nob,i,pob,' ',pos,up);
		}
	}
}
void tree_birth()
{
	int dx[13]={-1,-1,-1,-1,-1,-1,-1,0,0,0,1,1,1},dy[13]={-1,0,1,-2,2,-3,3,-1,0,1,-1,0,1};
	int dxl[23]={0,0,0,1,1,1,2,2,-1,-1,-1,-1,-1,0,0,0,0,1,1,1,1,2,2},dyl[23]={-1,0,1,-1,0,1,-1,1,-2,-1,0,1,2,-3,-2,2,3,-3,-2,2,3,-2,2};
	for(int i=2;i<wide_-1;i++)
	{
		for(int add_h=0;add_h>=-3;add_h--)
		{
			bool flag=1;
			for(int k=0;k<13;k++)
			{
				char ch=get_(d_space+add_h+dx[k],i+dy[k]);
				if(dx[k]==-1&&ch=='W')
				{
					flag=0;
					break;
				}
				if(dx[k]!=-1&&ch!='D')
				{
					flag=0;
					break;
				}
			}
			if(flag&&(!(rand()%3)))
			{
				int high_=-rand()%10-8;
				int lft=1;
				int gp=rand()%2+4;
				bool trfl=1;
				for(int p=-1;p>=high_;p--,lft++)
				{
					if(get_(d_space+add_h+p,i)!=' ')
					{
						trfl=0;
						break;
					}
					set_s(d_space+add_h+p,i,'W');
					if(lft>=gp)
					{
						lft-=gp;
						gp=rand()%2+4;
						int chz=rand()%2*2-1;
						set_s(d_space+add_h+p,i+chz,'W');
					}
				}
				if(trfl)
				{
					for(int k=0;k<23;k++)
					{
						char ch=get_(d_space+add_h+high_+dxl[k]-1,i+dyl[k]);
						if(ch!=' ')
						{
							continue;
						}
						set_s(d_space+add_h+high_+dxl[k]-1,i+dyl[k],'*');
					}
				}
			}
		}
	}
}
void ash_birth()
{
	int nob;
	for(int i=20;i<d_hel;i++)
	{
		for(int j=0;j<=wide_;j++)
		{
			if(!(rand()%(60-i)))
			{
				nob=rand()%(360*length_*wide_/200/800)+40*length_*wide_/200/800;
				bfs_o(nob,i,j,'H',d_space+d_ground+d_under_ground,length_);
			}
		}
	}
}
void hel_set()
{
	int nob;
	for(int j=0;j<=wide_;j++)
	{
		if(!(rand()%2))
		{
			nob=rand()%(100*length_*wide_/200/800)+30*length_*wide_/200/800;
			bfs_o(nob,d_space+d_ground+d_under_ground,j,'#',0,length_);
		}
	}
}
void lava_birth()
{
	int nob,pob;
	for(int j=0;j<=wide_;j++)
	{
		if(!(rand()%7))
		{
			nob=rand()%(5600*length_*wide_/200/800)+1000*length_*wide_/200/800;
			pob=rand()%15+25;
			bfs_o(nob,d_space+d_ground+d_under_ground,j,'L',pob,length_);
		}
	}
}
void hel_build_birth()
{
	int dx[3]={1,0,0},dy[3]={0,1,-1};
	int nob;
	for(int j=0;j<=wide_;j++)
	{
		if(!(rand()%50))
		{
			nob=rand()%10
		}
	}
}
void under_ground_birth()
{
	stone_birth();
	gold_birth();
	iron_birth();
	space_birth(d_space+d_ground,d_space+d_ground+d_under_ground);
	long_space_birth(d_space+d_ground,d_space+d_ground+d_under_ground);
}
void ground_birth()
{
	long_space_birth(d_space-5,d_space+d_ground);
	dirt_birth();
	tree_birth();
}
void hel_birth()
{
	hel_set();
	ash_birth();
	lava_birth();
}
void first_birth()
{
	for(int i=1;i<length_;i++)
	{
		for(int j=1;j<wide_;j++)
		{
			set_s(i,j,' ');
		}
	}
	for(int i=1;i<d_ground;i++)
	{
		for(int j=1;j<wide_;j++)
		{
			set_s(i+d_space,j,'S');
		}
	}
	for(int i=1;i<d_under_ground;i++)
	{
		for(int j=1;j<wide_;j++)
		{
			set_s(i+d_space+d_ground,j,'D');
		}
	}
	for(int i=20;i<d_hel;i++)
	{
		for(int j=1;j<wide_;j++)
		{
			set_s(i+d_space+d_ground+d_under_ground,j,'L');
		}
	}
}
void print_map()
{
	freopen("map.txt","w",stdout);
	for(int i=1;i<length_;i++)
	{
		for(int j=1;j<wide_;j++)
		{
			cout<<s[i][j].name;
		}
		cout<<'\n';
	}
}
void start_set()
{
	id[' ']=1;id['D']=2;id['S']=3;id['I']=4;id['G']=5;id['W']=6;id['*']=7;id['L']=8;id['H']=9;
	nf[0]={' ',0," ",0,0};
	nf[1]={' ',0," ",15,0};
	nf[2]={'D',0,"Dirt",6,1};
	nf[3]={'S',0,"Stone",8,1};
	nf[4]={'I',0,"Iron",7,1};
	nf[5]={'G',0,"Gold",14,100};
	nf[6]={'W',0,"Wood",6,1};
	nf[7]={'*',0,"Leaf",10,0};
	nf[8]={'L',0,"Lava",12,0};
	nf[9]={'H',0,"Ash",8,1};
}
void map_make()
{
	srand(time(0));
	start_set();
	first_birth();
	under_ground_birth();
	ground_birth();
	hel_birth();
}
int main()
{
	map_make();
	print_map();
//	system("start map.txt");
	return 0;
}
}