跳到正文

个人记录

地图制造机(未完善)

__LCT__约 4 分钟
原文
文章信息与版本

文章信息

发布
2024年9月25日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 4 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int dt[105][105];
void gotoxy(int x,int y)
{
    COORD pos;
    pos.X=y;
    pos.Y=x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void out(int a,int b[105][105])
{
	system("cls");
	for(int i=1;i<=a;i++){
		for(int j=1;j<=a;j++){
			if(b[i][j]==0) cout<<"  ";
			else cout<<"■"; 
		}
		cout<<endl;
	}
	cout<<endl<<'{'<<endl;
	for(int i=1;i<=a;i++){
		cout<<'{';
		for(int j=1;j<=a;j++) cout<<b[i][j]<<',';
		cout<<'}'<<endl; 
	}
	cout<<'}';
}
void dlin(int x,int y,int xx,int yy)
{
	double xie;
	if(x>xx) swap(x,xx);
	if(y>yy) swap(y,yy);
	xie=(x-xx)*1.0/(yy-y);
	for(int i=x;i<=xx;i++) dt[i][int(y+(i-x)*xie)]=1;
}
void rect(int x,int y,int xx,int yy)
{
	if(x>xx) swap(x,xx);
	if(y>yy) swap(y,yy);
	for(int i=max(1,x);i<=min(xx,100);i++){
		for(int j=max(1,y);j<=min(yy,100);j++) dt[i][j]=1;
	}
}
void circ(int x,int y,int r,int close)
{
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			if(close==1 && abs(sqrt((i-x)*(i-x)+(j-y)*(j-y))<r)) dt[i][j]=1;
			else if(abs(sqrt((i-x)*(i-x)+(j-y)*(j-y))-r)<0.5) dt[i][j]=1;
		}
	} 
} 
void mapin()
{
	startin:
	int sz;
	string s;
	system("cls");
	gotoxy(1,1);
	printf("请选择大小(1到100):");
	while(sz>100 || sz<1){
		cin>>sz;
		if(sz>100 || sz<1) goto startin;
		else break;
	}
	while(1){
		out(sz,dt);
		cin>>s;
		if(s=="LIN"){
			int x,y,xx,yy;
			linc:
			cin>>x>>y>>xx>>yy;
			if(x<=0 || y<=0 || xx<=0 || yy<=0 ||x>sz || y>sz || yy>sz || xx>sz){
			   	
			}
			dlin(x,y,xx,yy);
		} else if(s=="RET"){
			int x,y,xx,yy;
			cin>>x>>y>>xx>>yy;
			rect(x,y,xx,yy);
		} else if(s=="CIR"){
			int x,y,r,c;
			cin>>x>>y>>r>>c;
			circ(x,y,r,c);
		} 
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	gotoxy(9,25);
	printf("1.创建新的作品");
	gotoxy(11,25);
	printf("2.退出");
	char o=getch();
	if(o=='1'){
		mapin(); 
	} else {
		return 0;
	}
	return 0;
}
原文