对称

#include<iostream>			//□■□□  □□■□   □□□□
#include<windows.h>			//■■□□  □□■■   □■□□
#define w 12		  		//□■□□  □□■□   ■■□□
#define h 10		  		//□□□□  □□□□   □■□□
#include<conio.h>
int map[w*h]={};
char* S[]={"□","■","※"};
int px = 1 ;
int py = 1 ;
bool want = false;
void draw()
{	
	int Tmap[w*h]={};
	memcpy(Tmap,map,w*h*4);
	Tmap[px+py*w] = 2 ;
	for(int y = 0 ;y < h ;++y)
	{
		for(int x = 0; x < w ;++x)
		{
			std::cout<<S[Tmap[x+y*w]];
		}
		std::cout<<std::endl;
	}
}
void run()
{
	int g = _getch();
	if((g == 'W' || g == 'w')&& py>0)py--;
	if((g == 'S' || g == 's')&& py<h-1)py++;
	if((g == 'A' || g == 'a')&& px>0)px--;
	if((g == 'D' || g == 'd')&& px<w-1)px++;
	if(g == ' ')
	{
		map[px+py*w] = 1;
	}
	if(g == 'H' || g == 'h')
	{
		want = true;
	}
}
void drawX(int a)
{
	int D_map[w*h]={};
	if(a == 1)
	{
		memcpy(D_map,map,w*h*4);
	}
	else if(a == 2)
	{
		for(int y = 0 ;y < h ;++y)
		{
			for(int x = 0; x < w ;++x)
			{
				D_map[x + y*w] = map[w-1-x + y*w];
			}
		}
	}
	else if(a == 3)
	{
		for(int y = 0 ;y < h ;++y)
		{
			for(int x = 0; x < w ;++x)
			{
				D_map[x + y*w] = map[x + (h-1-y)*w];
			}
		}
	}
	else if(a == 4)
	{
		for(int y = 0 ;y < h ;++y)
		{
			for(int x = 0; x < w ;++x)
			{
				D_map[x + y*w] = map[w-1-x + (h-1-y)*w];
			}
		}
	}
	else if(a == 5)
	{
		return ;
	}
	for(int y = 0 ;y < h ;++y)
	{
		for(int x = 0; x < w ;++x)
		{
			std::cout<<S[D_map[x+y*w]];
		}
		std::cout<<std::endl;
	}
}
								
void main()
{	
	
	while(1)
	{
		system("cls");
		std::cout<<"请用空格设置地图,w、s、a、d方向\n";
		draw();
		run();
		if(want)
		{
			system("cls");
			std::cout<<"1:正常显示\n";
			std::cout<<"2:左右镜像\n";
			std::cout<<"3:上下镜像\n";
			std::cout<<"4:左右上下镜像\n";
			std::cout<<"5:退出\n";
			std::cout<<"请选择:";
			int hh;
			std::cin>>hh;
			drawX(hh);
			system("pause");

		}
	}

	system("pause");
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值