移步换景 C++

移步换景:通过输入←或→,让窗外风景移动

输入:

                                    *                                           
                                       *                                        
        *                                *                                 *    
                              *                 *                  *            
  *                                           *              *  __             *
                        *            *                        _/'`\             
                                                            /'     `\           
         __                                            ___/'         `\         
       /'  `\_                                       /'                \        
__- _--       \___-_- _--_- _--______- _--__- ___- _/'                   `\__--_
               \                                   /                            
                                                 -- _--______-                  
             _- _--_ __    _ _--_                                               
    -               -        -               - _-      _ __ - _--_-             
     -__                                                -              _--_     
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                 /||\                                           
                                 ||||                                           
                                 ||||                                           
                                 |||| /|\                                       
      /|\                   /|\  |||| |||                                       
     |||||                  |||  |||| |||                                       
     |||||                  |||  |||| |||                                       
 /\  |||||                  |||  |||| |||                                       
|||| |||||                  |||  |||||||/                                       
|||| |||||  /\              |||._||||~~'                                        
|||| ||||| ||||             \||||||||                                           
 \|`-'|||| ||||              `~~~||||                    ,,,                    
  \__ |||| ||||                  ||||                   {{}}} ,,,               
     ||||`-'|||                  ||||                    \|/ {{}}}              
     |||| ___/   \|/_\|/__\/__   |||| \|/__\|/\|/________\|/__\|/______\|/______
     |||||                       ||||                                           
     |||||                                                                      

代码: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;
    }
}

可以运行一下 效果很好!!!!!

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值