移步换景:通过输入←或→,让窗外风景移动
输入:
*
*
* * *
* * *
* * * __ *
* * _/'`\
/' `\
__ ___/' `\
/' `\_ /' \
__- _-- \___-_- _--_- _--______- _--__- ___- _/' `\__--_
\ /
-- _--______-
_- _--_ __ _ _--_
- - - - _- _ __ - _--_-
-__ - _--_
/||\
||||
||||
|||| /|\
/|\ /|\ |||| |||
||||| ||| |||| |||
||||| ||| |||| |||
/\ ||||| ||| |||| |||
|||| ||||| ||| |||||||/
|||| ||||| /\ |||._||||~~'
|||| ||||| |||| \||||||||
\|`-'|||| |||| `~~~|||| ,,,
\__ |||| |||| |||| {{}}} ,,,
||||`-'||| |||| \|/ {{}}}
|||| ___/ \|/_\|/__\/__ |||| \|/__\|/\|/________\|/__\|/______\|/______
||||| ||||
|||||
代码:111
#include <bits/stdc++.h>
#include "util.h"
using namespace std;
string background[] =
{
R"L( * )L",
R"L( * )L",
R"L( * * * )L",
R"L( * * * )L",
R"L( * * * __ *)L",
R"L( * * _/'`\ )L",
R"L( /' `\ )L",
R"L( __ ___/' `\ )L",
R"L( /' `\_ /' \ )L",
R"L(__- _-- \___-_- _--_- _--______- _--__- ___- _/' `\__--_)L",
R"L( \ / )L",
R"L( -- _--______- )L",
R"L( _- _--_ __ _ _--_ )L",
R"L( - - - - _- _ __ - _--_- )L",
R"L( -__ - _--_ )L",
R"L( )L",
R"L( )L",
R"L( )L",
R"L( )L",
};
const auto WIDTH = background[0].size();
const auto HEIGHT = sizeof(background)/sizeof(background[0]);
string foreground[] =
{
R"L( )L",
R"L( )L",
R"L( )L",
R"L( /||\ )L",
R"L( |||| )L",
R"L( |||| )L",
R"L( |||| /|\ )L",
R"L( /|\ /|\ |||| ||| )L",
R"L( ||||| ||| |||| ||| )L",
R"L( ||||| ||| |||| ||| )L",
R"L( /\ ||||| ||| |||| ||| )L",
R"L(|||| ||||| ||| |||||||/ )L",
R"L(|||| ||||| /\ |||._||||~~' )L",
R"L(|||| ||||| |||| \|||||||| )L",
R"L( \|`-'|||| |||| `~~~|||| ,,, )L",
R"L( \__ |||| |||| |||| {{}}} ,,, )L",
R"L( ||||`-'||| |||| \|/ {{}}} )L",
R"L( |||| ___/ \|/_\|/__\/__ |||| \|/__\|/\|/________\|/__\|/______\|/______)L",
R"L( ||||| |||| )L",
R"L( ||||| )L",
};
string ground[HEIGHT];
int main()
{
clear();
for (auto y=0; y<HEIGHT; y++) ground[y] = string(WIDTH, ' ');
int direction = 0;
int offset = 0;
while (true) {
if (offset%8==0) {
if (direction==KEY_RIGHT) {
for (auto y=0; y<HEIGHT; y++) {
auto t = background[y][0];
for (auto x=0; x<WIDTH-1; x++) {
background[y][x] = background[y][x+1];
}
background[y][WIDTH-1] = t;
}
} else if (direction==KEY_LEFT) {
for (auto y=0; y<HEIGHT; y++) {
auto t = background[y][WIDTH-1];
for (auto x=WIDTH-1; x>0; x--) {
background[y][x] = background[y][x-1];
}
background[y][0] = t;
}
}
}
if (direction==KEY_RIGHT) {
for (auto y=0; y<HEIGHT; y++) {
auto t = foreground[y][0];
for (auto x=0; x<WIDTH-1; x++) {
foreground[y][x] = foreground[y][x+1];
}
foreground[y][WIDTH-1] = t;
}
} else if (direction==KEY_LEFT) {
for (auto y=0; y<HEIGHT; y++) {
auto t = foreground[y][WIDTH-1];
for (auto x=WIDTH-1; x>0; x--) {
foreground[y][x] = foreground[y][x-1];
}
foreground[y][0] = t;
}
}
for (auto y=0; y<HEIGHT; y++) {
for (auto x=0; x<WIDTH; x++) {
ground[y][x] = foreground[y][x];
if (ground[y][x]==' ') ground[y][x] = background[y][x];
}
}
recursor();
for (auto y=0; y<HEIGHT; y++) {
for (auto x=0; x<WIDTH; x++) {
cout << ground[y][x];
}
cout << '\n';
}
auto key = getkey();
if (key==KEY_RIGHT) offset++;
else if (key==KEY_LEFT) offset--;
direction = key;
}
}
可以运行一下 效果很好!!!!!