windows全屏像素位移

全屏字符四向位移(为假期写2d版我的世界做准备)

***********************************made by FireHumansSkeleton

首先是主程序–(唯一的缺点是行末必须有@,结束必须有!)
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
#define sl10 Sleep(10);
int x,y;
char a[501][501];
int pmx,pmy;
int pmnx,pmny;
int lzbx=0,lzby;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);

/*
100 100 30 30 50 50
100 100 20 20 50 50
100 100 10 10 50 50
*/

void gbzb(int x,int y);
void color(int coo);
void mopm(char k);
void ra();

void ra()
{
	int co;
	char k;
	cin>>x>>y>>pmx>>pmy>>pmnx>>pmny;
	system("cls");
	for(int i=0;i<y;i++)
	{
		for(int j=0;j<x;j++)
		{
			a[i][j]=(rand()%(i+1)%(j+1))%15;
			a[i][j]<<=4;
		}
	}
	for(int i=pmny;i<=pmny+pmy;i++)
	{
		for(int j=pmnx;j<=pmnx+pmx;j++)
		{
			color(a[i][j]%15+1);
			printf("■");
		}
		printf("\n");
	}
}

void color(int coo)
{
    SetConsoleTextAttribute(hout,coo);
}
void gbzb(int x,int y)
{
	if(lzbx==x-1)
	{
		lzbx++;
		return;
	}
	else
	{
		COORD pos={x,y};
		lzbx=x;
    	SetConsoleCursorPosition(hout,pos);
	}
}
void mopm(char k)
{
	int co;
	bool flag;
	switch(k)
	{
		case 'a':
		pmnx++;
		if(pmnx>=x-pmx)
		{
			pmnx=x-pmx-1;
			return;
		}
		for(int i=pmny;i<=pmny+pmy;i++)
		{
			for(int j=pmnx;j<=pmnx+pmx;j++)
			{
				if(a[i][j]!=a[i][j-1])
				{
					gbzb(j-pmnx,i-pmny);
					putchar(a[i][j]);
					/*
					color(a[i][j]);
					putchar(' ');putchar(' ');
					*/
				}
			}
		}
		return;
		case 's':
		pmny--;
		if(pmny<=0)
		{
			pmny=1;
			return;
		}
		for(int i=pmny;i<=pmny+pmy;i++)
		{
			for(int j=pmnx;j<=pmnx+pmx;j++)
			{
				if(a[i][j]!=a[i+1][j])
				{
					gbzb(j-pmnx,i-pmny);
					putchar(a[i][j]);
					/*
					color(a[i][j]);
					putchar(' ');putchar(' ');
					*/
				}
			}
		}
		return;
		case 'd':
		pmnx--;
		if(pmnx<=0)
		{
			pmnx=1;
			return;
		}
		for(int i=pmny;i<=pmny+pmy;i++)
		{
			for(int j=pmnx;j<=pmnx+pmx;j++)
			{
				if(a[i][j]!=a[i][j+1])
				{
					gbzb(j-pmnx,i-pmny);
					putchar(a[i][j]);
					/*
					color(a[i][j]);
					putchar(' ');putchar(' ');
					*/
				}
			}
		}
		return;
		case 'w':
		pmny++;
		if(pmny>=y-pmy)
		{
			pmny=y-pmy-1;
			return;
		}
		for(int i=pmny;i<=pmny+pmy;i++)
		{
			for(int j=pmnx;j<=pmnx+pmx;j++)
			{
				if(a[i][j]!=a[i-1][j])
				{
					gbzb(j-pmnx,i-pmny);
					putchar(a[i][j]);
					/*
					color(a[i][j]);
					putchar(' ');putchar(' ');
					*/
				}
			}
		}
		return;
	}
}
int main()
{
	int i,j;char k;
	ifstream fin("0.txt");
	fin>>x>>y>>pmx>>pmy>>pmnx>>pmny;
	for(i=1;1;i++)
	{
		for(j=1;1;j++)
		{
			fin>>a[i][j];
			if(a[i][j]=='@')
			{
				break;
			}
			if(a[i][j]=='!')
			{
				break;
			}
		}
		if(a[i][j]=='!')
		{
			break;
		}
	}
	fin.close();
	fin.clear();
	system("cls");
	for(int i=pmny;i<=pmny+pmy;i++)
	{
		for(int j=pmnx;j<=pmnx+pmx;j++)
		{
			gbzb(j-pmnx,i-pmny);
			putchar(a[i][j]);
		}
		printf("\n");
	}
	while(k!=33)
	{
		k=_getch();
		mopm(k);
	}
	return 0;
}

测试数据(来自洛谷试炼场-P1000超级玛丽)

保存在0.txt

500 500 78 23 10 10
....................********......................................@
...................************...................................@
...................####....#......................................@
.................#..###.....##....................................@
.................###.......######..............###............###.@
..............................................#...#..........#...#@
...................##*#######.................#.#.#..........#.#.#@
................####*******######.............#.#.#..........#.#.#@
..................#***.****.*###..............#...#..........#...#@
...................**********##................###............###.@
...................****....*****..................................@
.................####........####.................................@
...............######........######...............................@
....##############################################################@
....#...#......#.##...#......#.##...#......#.##------------------#@
....###########################################------------------#@
....#..#....#....##..#....#....##..#....#....#####################@
....##########################################....#----------#....@
....#.....#......##.....#......##.....#......#....#----------#....@
....##########################################....#----------#....@
....#.#..#....#..##.#..#....#..##.#..#....#..#....#----------#....@
....##########################################....############....@
@
@
##############@
#...#......#.#@
##############@
#..#....#....#@
##############@
#.....#......#@
##############@
#.#..#....#..#@
##############@
@
@
####################@
#------------------#@
#------------------#@
####################@
....#----------#....@
....#----------#....@
....#----------#....@
....#----------#....@
....############....@
!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值