全屏字符四向位移(为假期写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
....................********......................................@
...................************...................................@
...................####....#......................................@
.................#..###.....##....................................@
.................###.......######..............###............###.@
..............................................#...#..........#...#@
...................##*#######.................#.#.#..........#.#.#@
................####*******######.............#.#.#..........#.#.#@
..................#***.****.*###..............#...#..........#...#@
...................**********##................###............###.@
...................****....*****..................................@
.................####........####.................................@
...............######........######...............................@
....##############################################################@
....#...#......#.##...#......#.##...#......#.##------------------#@
....###########################################------------------#@
....#..#....#....##..#....#....##..#....#....#####################@
....##########################################....#----------#....@
....#.....#......##.....#......##.....#......#....#----------#....@
....##########################################....#----------#....@
....#.#..#....#..##.#..#....#..##.#..#....#..#....#----------#....@
....##########################################....############....@
@
@
##############@
#...#......#.#@
##############@
#..#....#....#@
##############@
#.....#......#@
##############@
#.#..#....#..#@
##############@
@
@
####################@
#------------------#@
#------------------#@
####################@
....#----------#....@
....#----------#....@
....#----------#....@
....#----------#....@
....############....@
!!!