存活1.5.0.4 游戏

这是我用Python打了4个半月的代码

希望能火

不求点赞和收藏

/* Copyright(c) 2021 ZiChen Zhang,JiaCheng Pan and all contributors
All right Reserved
    
    Distributed under MIT license
    See copy at https://opensource.org/licenses/MIT
*/
/*
wasd移动,不用说了吧(需要一个回车)
/move + wasd也是移动,如果你设定gamerule.standardized_command参数为1则需要这个命令移动
/set + wasd + 距离 + 方块名称 ==> 在指定方向上的指定距离放置方块
/set d 1 stone即为在右侧放一个石头
/break + wasd + 距离 ==> 在指定方向上的特定距离破坏方块
/break d 1 把刚刚那个石头破坏掉
其他的命令与Minecraft基本上相同,坐标为二维的不要搞错了
*/
/**
 *  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
 *  ┃  OOOOO    /     /   % % %     @   @   ! ! !   #   #   ~ ~ ~ ~  ┃
    ┃ O         /     /   %     %   @   @     !     #   #   ~        ┃
    ┃ O         /     /   %     %   @   @     !     #   #   ~        ┃
    ┃  OOOOO    /     /   % % %     @   @     !     #   #   ~ ~ ~ ~  ┃
    ┃       O   /     /   % %       @   @     !     #   #   ~        ┃
    ┃       O   /     /   %   %       @       !       #     ~        ┃
    ┃ OOOOOO     /    %     %     @     ! ! !     #     ~ ~ ~ ~  ┃
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
 * 这里是社区最大的C++版沙盒游戏
 * 从2020/08/26起,我们共计发布了数十个更新,到现在的1.5.0(至2021/08/26),代码超过2500行,10万字符
 * 在社区成员的帮助下,我们有了许多改进,并不断加入玩家所提议的内容。
 * 
 * 成员表:
 * 主创:ParseY Pasy(张子辰)
 * 提供帮助:
 *       Rratic(潘嘉诚)      闫雅芮
 *       李梓淇                杨墨轩
 *       尹怀杰                罗昊洋
 * 编译器支持:
 *       学而思编程社区(C站)
 * 发布平台:
 *       学而思编程社区(C站)
 * 版本历史:
 * pre0.0.1(原初版)
 * pre0.0.2
 * pre0.1.0
 * pre0.2.5(重置版本号)
 *     更新内容:初步的地形
 * pre1.1.0(保存)
 * pre1.2.1(保存)
 *     发布时间:2020/10/01 10:50:00
 *     更新内容:实体与地形分离
 * pre1.2.2
 * pre1.2.3(保存)
 *     发布时间:2020/10/01 10:50:00
 *     更新内容:模组,信息栏
 * pre1.2.4(与下面的pre1.2.5.100版本似乎重叠)
 * pre1.2.5.100(保存)
 *     发布时间:2020/11/22 20:45:00
 *     更新内容:成就,语言系统
 * pre1.2.5.200(圣诞版)
 *     发布时间:2020/12/21 21:00:00
 *     更新内容:开始界面
 * 1.1.0 
 * 
 * 1.2版本未保存
 * 
 * 1.3.1(保存)
 *     发布时间:2021/01/03 23:08:00
 *     更新内容:方块类
 * 1.3.2
 *     更新内容:gamerule指令
 * 21w1a
 *     更新内容:饥饿值,生命值,氧气值
 * 1.3.3
 *     更新内容:生存元素更新
 * 1.3.4(保存)
 *     发布时间:2021/01/28 16:30:00
 *     更新内容:命令组
 * 1.3.5(保存)
 *     发布时间:2021/02/08 21:30:00
 *     更新内容:区块
 * 1.4.1(保存)
 *     发布时间:2021/05/02 17:00:00
 *     更新内容:真正的地形
 * 1.4.2(保存)
 *     发布时间:2021/06/18
 *     更新内容:无限世界
 * 1.4.2.2(保存)
 *     发布时间:2021/07/25
 *     更新内容:bug消除+存档功能
 * 1.4.3(保存)
 *     定档时间:2021/07/31
 *     更新内容:UI,Unicode
 * 1.4.3.1--->1.4.3.3(保存)
 *     发布时间:2021/08/04--->2021/08/15
 *     更新内容:UI更多操作+维度地形算法
 > 1.5.0(保存)
 >     发布时间:2021/08/26
 >     更新内容:维度世界,更多自然元素
 *Survive一周年庆典!
 * 现代码量:2713行
 **/
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
//#include <unistd.h>
#include <stack>
#include <cstdio>
#include <locale>
#include <clocale>
#include <cwchar>
#include <typeinfo>
#include <algorithm>
#include <climits>
#include <sstream>
#include <queue>
#include <set>
#include <map>


#define DefaultUpdate Default();
#define FOR_XES true
#if FOR_XES
    const bool online_xes = true;
#else
    const bool online_xes = false;
#endif
bool CHECK_GNUC_VERSION(){
    #define GCC_VERSION (__GNUC__ * 10000 \
                       + __GNUC_MINOR__ * 100 \
                       + __GNUC_PATCHLEVEL__)
    return (GCC_VERSION > 40200);
}//对GNUC的版本号检查
#ifdef __GNUC__ 
    const bool GNUC_COMPILER_VERSION_AVAILABLE = CHECK_GNUC_VERSION();
    const bool ENVIRONMENT_GNUC_AVAILABLE = true;
#else
    const bool GNUC_COMPILER_VERSION_AVAILABLE = false;
    const bool ENVIRONMENT_GNUC_AVAILABLE = false;
#endif
//对于GNUC(必需环境)
#define REQUIRE_CUIL_VERSION L"CUIL v0.0.6"
extern "C" unsigned int sleep (unsigned int __seconds);
extern "C" int usleep (__useconds_t __useconds);
typedef long long ll;
typedef long double ld;
namespace stdcolor_256{
    const std::wstring red    = L"\033[48;5;1m";//红色
    const std::wstring yellow = L"\033[48;5;3m";//黄色
    const std::wstring green  = L"\033[48;5;2m";//绿色
    const std::wstring blue   = L"\033[48;5;4m";//蓝色
    const std::wstring cyan   = L"\033[48;5;5m";//青色
    const std::wstring purple = L"\033[48;5;6m";//紫色
    const std::wstring white  = L"\033[48;5;255m";//白色
    const std::wstring gray   = L"\033[48;5;8m";//灰色
    const std::wstring black  = L"\033[48;5;0m";//黑色
    const std::wstring light_red    = L"\033[48;5;9m";//亮红色
    const std::wstring light_yellow = L"\033[48;5;11m";//亮黄色
    const std::wstring light_green  = L"\033[48;5;10m";//亮绿色
    const std::wstring light_blue   = L"\033[48;5;12m";//亮蓝色
    const std::wstring light_cyan   = L"\033[48;5;13m";//亮青色
    const std::wstring light_purple = L"\033[48;5;14m";//亮紫色
    const std::wstring light_white  = L"\033[48;5;15m";//亮白色
    const std::wstring dark_black  = L"\033[48;5;16m";//纯黑色
};//标准256背景色
namespace stdcolor_RGB{
    const std::wstring pure_red =    L"\033[48;2;255;0;0m";//      颜色#FF0000
    const std::wstring pure_green =  L"\033[48;2;0;255;0m";//      颜色#00FF00
    const std::wstring pure_blue  =  L"\033[48;2;0;0;255m";//      颜色#0000FF
    const std::wstring pure_black =  L"\033[48;2;0;0;0m";//        颜色#000000
    const std::wstring pure_white =  L"\0333[48;2;255;255;255m";// 颜色#FFFFFF
    const std::wstring pure_yellow = L"\033[48;2;255;255;0m";//    颜色#FFFF00
    const std::wstring pure_violet = L"\033[48;2;255;0;255m";//    颜色#FF00FF
    const std::wstring pure_cyan   = L"\033[48;2;255;255;0m";//    颜色#00FFFF
};//RGB标准颜色库
namespace stdtext{
    const std::wstring text_red = L"\033[38;5;9m";//文字红色
    const std::wstring text_yellow = L"\033[33m";//文字黄色
    const std::wstring text_green = L"\033[32m";//文字绿色
    const std::wstring text_blue = L"\033[34m";//文字蓝色
    const std::wstring text_dark = L"\033[38;5;232m";//文字纯黑
    const std::wstring text_gray = L"\033[38;5;242m";//文字灰色
    const std::wstring text_darkblue = L"\033[38;5;27m";//文字深蓝
    const std::wstring text_lightblue = L"\033[38;5;14m";//文字亮蓝
    const std::wstring italic = L"\033[003m";//文字斜体
    const std::wstring code_background = L"\033[48;5;7m";//代码背景色
    
};//文字格式标准库

namespace CUIL_std{
    using namespace stdcolor_256;
    using namespace stdcolor_RGB;
    using namespace stdtext;
    
    #define _EN_UK_DEFAULT_WARNING L"Warning,error occured because of wrong parameter or incorrect use."//默认反馈信息——英语
    #define _ZH_CN_DEFAULT_WARNING L"警告:错误的参数或不正当使用导致了一个错误"//默认反馈信息——中文
    #ifdef __linux
	    #define CLEARSCREEN_CMDCOMMMAND "clear"
	#else
	    #define CLEARSCREEN_CMDCOMMMAND "cls"
	#endif
    int WCHAR_T_INIT(){
        try{
            std::locale lc("zh_CN.UTF-8");
    	    std::locale::global(lc);
    	    return 1;
        }catch(...){
            return 0;
        }
    }
    const int SUPPORT_WCHAR_T = WCHAR_T_INIT();//常量——系统是否支持中文宽字符(unicode字符集)
    
	//清除屏幕的system指令
    const std::wstring VOID_PARAMETER = L"NONE";//默认空参数
    const std::wstring _DEFAULT_LANGUAGE = L"zh-CN";//默认语言
    const std::wstring _NOW_DEFAULT_WARNING = _ZH_CN_DEFAULT_WARNING;//现在的默认警告(可随时更改)
    const std::wstring _CLEAREFFECT_STR = L"\033[0m";//清除效果
    const std::wstring CUIL_VERSIONINFO = L"CUIL v0.0.6";//CUIL的版本
    
    //CUIL基础结构
    
    //衍生功能库
    
    std::wstring warning_color_type[] = {stdcolor_256::yellow,stdcolor_256::light_red,stdcolor_256::red};
    //0级警告:黄,1级警告:亮红,2级(最高)警告:暗红
    //基础类
    struct warning{
        int warn_type;
        std::wstring content;
    };
    std::queue<warning> warning_queue;//警告队列
    inline int warn_if(bool statement,const std::wstring show,int type_warning = 1);//警告
    class format{
        protected:
            bool formatlock;//格式锁
        private:
            std::wstring text_color;//文字颜色 
            std::wstring background_color;//背景颜色
            bool useitalic;//是否启用斜体
        public:
            void settextcolor(std::wstring input){
                if(warn_if(formatlock,L"此类的格式锁已启用,无法通过set进行修改"))
                    return ;
                else
                    text_color = input;
            }
            void setbgcolor(std::wstring input){
                if(warn_if(formatlock,L"此类的格式锁已启用,无法通过set进行修改"))
                    return ;
                else
                    background_color = input;
            }
            void setitalic(bool input){
                if(warn_if(formatlock,L"此类的格式锁已启用,无法通过set进行修改"))
                    return ;
                else
                    useitalic = input;
            }
            void lock(){
                formatlock=true;    
            }
            void unlock(){
                formatlock=false;
            }
            void clear(){
                formatlock = false;
                useitalic=false;
                text_color=L"";
                background_color=L"";
            }//清除效果
            format(bool a,bool b,std::wstring c,std::wstring d){
                formatlock = a;
                useitalic = b;
                text_color = c;
                background_color = d;
            }
            format(){
                
            }
        friend void print(const std::wstring content,const format formatin,bool step,double wait_time,bool end);//输出函数将调用此类
        friend void printcode(const std::wstring code,const std::wstring lang);
        friend std::wostream& operator<<(std::wostream& wis,const format& c);
    }publicformat = {false,false,L"",L""},
    default_printformat = {false,false,L"",L""},
    default_codeformat = {false,false,L"",code_background};
    format printformat = default_printformat;
    format codeformat = default_codeformat;    
    std::wostream& operator<<(std::wostream& wis,const format& c){
        std::wstring s = c.text_color+c.background_color+(c.useitalic?italic:L"");
        wis<<s;
        return wis;
    
    }
    class element{
        public:
            std::wstring content;//模板化内容
            format buildin_format;//内置格式
        public:
            void show(){
                std::wcout << buildin_format << content;//内容
            }
            element(){
                content = L"";
                buildin_format = default_printformat;
            }//默认构造
            element(const std::wstring input,const format formatin = printformat){
                content = input;
                buildin_format = formatin;
            }//输入元素内容
            element(const long long input,const format formatin = printformat){
                content = std::to_wstring(input);
                buildin_format = formatin;
            }//对整型数据的重载
            element(const wchar_t input,const format formatin = printformat){
                content += input;
                buildin_format = formatin;
            }//对宽字符数据的重载
            element(const long double input,const format formatin = printformat){
                content = std::to_wstring(input);
                buildin_format = formatin;
            }
    }voidelement{L"",default_printformat};//元素类
    
    int count_showlen(const element input){
        int count_t = input.content.length();
        for(auto&& i:input.content){
            if(int(i)>127)
                count_t++;
        }
        return count_t;
    }
    std::wstring wstrcpy(std::wstring cpystr,int cpynum);
    class label_line{
        public:
            element left;//左元素
            element mid;//中元素
            element right;//右元素
            int line_len;//当前对齐长度
        public:
            int minshowlen(){
                int show_len_left = count_showlen(left),
                    show_len_mid  = count_showlen(mid),
                    show_len_right = count_showlen(right);
                int line_len = show_len_left + show_len_mid + show_len_right + 2;
                return line_len;
            }
            void editleft(const element in){
                left = in;
            }
            void editright(const element in){
                right = in;
            }
            void editmid(const element in){
                mid = in;
            }
            void show(int line_len_min = 20){
                int now_len = minshowlen();
                if(now_len > line_len_min){
                    left.show();
                    std::wcout << L" ";
                    mid.show();
                    std::wcout << L" ";
                    right.show();
                    line_len = now_len;
                }//拓展长度
                else{
                    int space_left = (line_len_min - now_len + 2)/2,
                        space_right = line_len_min - now_len + 2 - space_left;
                    left.show();
                    std::wcout << wstrcpy(L" ",space_left);
                    mid.show();
                    std::wcout << wstrcpy(L" ",space_right);
                    right.show();
                    line_len = line_len_min;
                }
            }//展示标签行
            label_line(){
                left = element();
                mid = element();
                right = element();
            }
            label_line(const element l,const element m = voidelement,const element r = voidelement){
                left = l;
                mid = m;
                right = r;
                
            }
    };//标签行类
    class label{
        public:
            std::vector<label_line>content;
        public:
            void add_line(const label_line in){
                content.push_back(in);
            }
            void delete_line(){
                content.pop_back();
            }
            void show(int show_len = 20){
                int max_len = -1;
                for(auto&&i:content){
                    int tmp_len = i.minshowlen();
                    max_len = tmp_len>max_len?tmp_len:max_len;
                }//检索最大长度
                show_len = max_len>=show_len?max_len:show_len;//如果最大长度超过定义,则换为最大长度
                std::wcout << L"┌"<<wstrcpy(L"─",show_len-1)<<L"┐"<<std::endl;
                for(auto&&i:content){
                    std::wcout << L"│";
                    i.show(show_len);
                    std::wcout << L"│"<<std::endl;
                }
                std::wcout << L"└"<<wstrcpy(L"─",show_len-1)<<L"┘"<<std::endl;
            }
    };//标签总类
    double half_precision(double a){
        return fabs(a - floor(a))<fabs(ceil(a)-a)?floor(a):ceil(a);
    }
    template<class T>class martix{
        private:
            std::vector<std::vector<T>>content;
        public:
            void edit(int x,int y,T v){
                if(warn_if(!(0<=x&&x<content[0].size()&&0<=y&&y<content.size()),L"尝试访问不存在的矩阵元素["+std::to_wstring(x)+L","+std::to_wstring(y)+L"]"))
                    return ;
                else
                    content[y][x]=v;
            }
            T get(int x,int y){
                if(warn_if(!(0<=x&&x<content[0].size()&&0<=y&&y<content.size()),L"尝试访问不存在的矩阵元素["+std::to_wstring(x)+L","+std::to_wstring(y)+L"]"))
                    return T();
                else
                    return content[y][x];
            }
            martix<T>(int h = 16,int w = 16){
                std::vector<T>tmp;
                for(int i = 0;i<w;i++)
                    tmp.push_back(T());
                for(int i = 0;i<h;i++)
                    content.push_back(tmp);
            }
            int geth(){
                return content.size();
            }
            int getw(){
                return content[0].size();
            }
            void seth(int newh,const T set_as = T()){
                if(newh<content.size()){
                    while(content.size()>newh&&(!content.empty()))
                        content.pop_back();
                }else{
                    std::vector<T>tmp;
                    while(tmp.size()<content[0].size())
                        tmp.push_back(set_as);
                    while(content.size()<newh)
                        content.push_back(tmp);
                }
            }
            void setw(int neww,const T set_as = T()){
                if(neww<content[0].size()){
                    for(auto&&i:content){
                        while(i.size()>neww)
                            i.pop_back();
                    }
                }else{
                    for(auto&&i:content){
                        while(i.size()<neww)
                            i.push_back(set_as);
                    }
                }
            }
            void recover(T input){
                for(int i = 0;i<content.size();i++){
                    for(int j = 0;j<content[i].size();j++)
                        content[i][j] = input;
                }
            }
            void cover(int sx,int sy,int ex,int ey,T input){
                if(0<=sx&&sx<content[0].size()){
                    if(0<=sy&&sy<content.size()){
                        
                    }else
                        sy = sy<0?0:content.size()-1;
                        warn_if(true,L"开始的y坐标超出范围,已自动调整",0);    
                }//开始坐标在范围内
                else{
                    sx = sx<0?0:content[0].size()-1;
                    warn_if(true,L"开始的x坐标超出范围,已自动调整",0);
                }
                if(0<=ex&&ex<content[0].size()){
                    if(0<=ey&&ey<content.size()){
                        
                    }else
                        ey = ey<0?0:content.size()-1;
                        warn_if(true,L"结束的y坐标超出范围,已自动调整",0);    
                }//开始坐标在范围内
                else{
                    ex = ex<0?0:content[0].size()-1;
                    warn_if(true,L"结束的x坐标超出范围,已自动调整",0);
                }
                int tmp = sx;
                sx = std::min(tmp,ex);
                ex = std::max(tmp,ex);
                tmp=sy;
                sy = std::min(tmp,ey);
                ey = std::max(tmp,ey);
                for(int i = sx;i<=ex;i++){
                    for(int j = sy;j<=ey;j++)
                        content[j][i] = input;
                }
            }
            void print(){
                for(int i = 0;i<content.size();i++){
                    for(int j = 0;j<content[i].size();j++)
                        std::wcout << content[i][j]<<L",";
                    std::wcout << std::endl;
                }
            }
            void line(int sx,int sy,int ex,int ey,T input){
                long double k = (sx!=ex)?(ey-sy-0.0)/(ex-sx-0.0):(1e+308);
                long double b = sy - sx*k;
                if(sx>ex){
                    for(long double i = ex;i<=sx;i+=0.1){
                        long double nx = i,ny = k*i+b;
                        if(0<=nx&&nx<=content[0].size()&&0<=ny&&ny<=content.size())
                            content[int(ny)][nx] = input;
                    }
                }else if(sx<ex){
                    for(long double i = sx;i<=ex;i+=0.1){
                        long double nx = i,ny = k*i+b;
                        if(0<=nx&&nx<=content[0].size()&&0<=ny&&ny<=content.size())
                            content[int(ny)][nx] = input;
                    }
                }else{
                    int nsy = std::min(sy,ey),ney = std::max(sy,ey);
                    for(int i = nsy;i<=ney;i++){
                        if((0<=i&i<=content.size()&&0<=sx&&sx<=content[0].size()))
                            content[i][sx] = input;
                    }
                }
            }
            void circle(int x,int y,int r,T input){
                for(int i = x-r;i<=x+r;i++){
                    for(int j = y-r;j<=y+r;j++){
                        if(0<=i&i<=content[0].size()&&0<=j&&j<=content.size()){
                            if((i-x)*(i-x)+(j-y)*(j-y)<r*r)
                                content[j][i] = input;
                        }
                    }
                }
            }
    };
    std::wstring img_type[] = {L"rgb",L"256",L"grey"};
    const int type_num = 3;
    bool intype(std::wstring typein){
        for(int i = 0;i<type_num;i++){
            if(typein == img_type[i])
                return true;
        }
        return false;
    }
    class pixel{
        public:
            unsigned char red;//红
            unsigned char green;//绿
            unsigned char blue;//蓝
        public:
            std::wstring make_show_RGB(){
                return L"\033[48;2;"+std::to_wstring(red)+L";"+
                                     std::to_wstring(green)+L";"+
                                     std::to_wstring(blue)+L"m";
            }
            pixel(int r = 255,int g = 255,int b = 255){
                red = r;
                green = g;
                blue = b;
            }
    }
    pixel_red(255,0,0),//纯红像素
    pixel_green(0,255,0),//纯绿像素
    pixel_blue(0,0,255),//纯蓝像素
    pixel_white(255,255,255),//纯白像素
    pixel_cyan(0,255,255),//纯靛像素
    pixel_violet(255,0,255),//纯紫像素
    pixel_yellow(255,255,0),//纯黄像素
    pixel_black(0,0,0);//纯黑像素
    class grey{
        public:unsigned char vgrey;
        public:
            std::wstring make_show_grey(){
                return L"\033[48;2;"+std::to_wstring(vgrey)+L";"+
                                     std::to_wstring(vgrey)+L";"+
                                     std::to_wstring(vgrey)+L"m";
            }
            void edit(unsigned char a){
                vgrey = a;
            }
            grey(int a = 255){
                vgrey = a>255?255:(a<0?0:a);
            }
    }grey_white(255),grey_black(0);
    std::wostream& operator<<(std::wostream& wis,const pixel& c){
        std::wstring s = L"["+std::to_wstring(c.red)+L":"+std::to_wstring(c.green)+L":"+std::to_wstring(c.blue)+L"]";
        wis<<s;
        return wis;
    }
    class image{
        public:
            int height;//图像高
            int width;//图像宽
            martix<pixel>pmap;//像素矩阵
            double speed;//速度
        public:
            image(const int h = 16,const int w = 16,martix<pixel> mapin = martix<pixel>(16,16)){
                height = h;
                width = w;
                mapin = martix<pixel>(h,w);
                pmap = mapin;
                speed = 100;
            }
            void setspeed(double a){
                speed = a;
            }
            void show(){
                for(int i = 0;i<pmap.geth();i++){
                    for(int j = 0;j<pmap.getw();j++){
                        pixel tmp = pmap.get(j,i);
                        std::wcout << tmp.make_show_RGB() << L"  ";
                        usleep(500000/speed);
                    }
                    std::wcout << _CLEAREFFECT_STR;
                    std::wcout << std::endl;
                }
                std::wcout << _CLEAREFFECT_STR;
            }
            void recover(pixel input){
                pmap.recover(input);
            }
            void cover(int sx,int sy,int ex,int ey,pixel input){
                pmap.cover(sx,sy,ex,ey,input);
            }
            void edit(int x,int y,pixel input){
                pmap.edit(x,y,input);
            }
            void line(int sx,int sy,int ex,int ey,pixel input){
                pmap.line(sx,sy,ex,ey,input);
            }
            void circle(int x,int y,int r,pixel input){
                pmap.circle(x,y,r,input);
            }
            void seth(int newh,const pixel set_as = pixel_white){
                if(warn_if(newh<0,L"设置的图像高无法小于0",1))
                    return ;
                else
                    pmap.seth(newh,set_as);
                height = newh;
            }
            void setw(int neww,const pixel set_as = pixel_white){
                if(warn_if(neww<0,L"设置的图像宽无法小于0",1))
                    return ;
                else
                    pmap.setw(neww,set_as);
                width = neww;
            }
    };
    class image_grey{
        public:
            int height;//图像高
            int width;//图像宽
            martix<grey>pmap;//像素矩阵
            double speed;//输出速度
        public:
            image_grey(const int h = 16,const int w = 16,martix<grey> mapin = martix<grey>(16,16)){
                height = h;
                width = w;
                mapin = martix<grey>(h,w);
                pmap = mapin;
                speed = 100;
            }
            void setspeed(double a){
                speed = a;
            }
            void show(){
                for(int i = 0;i<pmap.geth();i++){
                    for(int j = 0;j<pmap.getw();j++){
                        grey tmp = pmap.get(j,i);
                        std::wcout << tmp.make_show_grey() << L"  ";
                        if(speed!=0)
                            usleep(500000/speed);
                    }
                    std::wcout << _CLEAREFFECT_STR;
                    std::wcout << std::endl;
                }
                std::wcout << _CLEAREFFECT_STR;
            }
            void recover(grey input){
                pmap.recover(input);
            }
            void cover(int sx,int sy,int ex,int ey,grey input){
                pmap.cover(sx,sy,ex,ey,input);
            }
            void edit(int x,int y,grey input){
                pmap.edit(x,y,input);
            }
            void line(int sx,int sy,int ex,int ey,grey input){
                pmap.line(sx,sy,ex,ey,input);
            }
            void circle(int x,int y,int r,grey input){
                pmap.circle(x,y,r,input);
            }
            void seth(int newh,const grey set_as = grey_white){
                if(warn_if(newh<0,L"设置的图像高无法小于0",1))
                    return ;
                else
                    pmap.seth(newh,set_as);
                height = newh;
            }
            void setw(int neww,const grey set_as = grey_white){
                if(warn_if(neww<0,L"设置的图像宽无法小于0",1))
                    return ;
                else
                    pmap.setw(neww,set_as);
                width = neww;
            }
    };
    int doclear(){
        try{
            system(CLEARSCREEN_CMDCOMMMAND);
            return 1;
        }catch(...){
            return 0;
        }//或许永远不会发生?
    }//调用系统cmd清屏
    
    wchar_t datain(){
        wchar_t tmpin;
        system("stty raw");
        wscanf(L"%c",&tmpin);
        system("stty -raw");
        std::wcout<<std::endl;
        return tmpin;
    }//获取单个字符
    
    int digitin(){
        wchar_t tmpin = datain();
        std::wcout<<std::endl;
        return iswdigit(tmpin)?(tmpin-L'0'):1;
    }
    const std::wstring key_word[] = {
    L"alignas",L"alignof",L"and",L"and_eq",L"asm",L"auto",
    L"bitand",L"bitor",L"bool",L"break",L"_Bool",
    L"case",L"catch",L"char",L"char16_t",L"char32_t",L"class",L"const",L"compl",L"const_cast",L"constexpr",
    L"decltype",L"default",L"delete",L"do",L"double",L"dynamic_cast",
    L"else",L"enum",L"explicit",L"export",L"extern",
    L"false",L"FALSE",L"float",L"for",L"friend",
    L"global",L"goto",
    L"if",L"include",L"inline",L"int",L"iostream",L"iterator",L"_Imaginary",
    L"long",
    L"map",L"mutable",
    L"new",L"namespace",L"noexcept",L"not",L"not_eq",L"NULL",L"nullptr",
    L"operator",L"or",L"or_eq",
    L"private",L"protected",L"public",L"_Pragma",
    L"queue",
    L"register",L"reinterpret_cast",L"restrict",L"return",
    L"set",L"short",L"signed",L"size",L"sizeof",L"stack",L"static",L"static_cast",L"struct",L"switch",
    L"template",L"this",L"thread_local",L"throw",L"true",L"TRUE",L"try",L"typedef",L"typeid",L"typename",
    L"union",L"unsigned",L"using",
    L"virtual",L"void",L"volatile",
    L"wchar_t",L"while",
    L"xor",L"xor_eq",
    };//关键字表
    const wchar_t key_char[] = {
    L'!',L'%',L'^',L'&',L'-',L'=',L'+',L'|',L'<',L'>',L'/',L'~'         
    };
    const std::wstring key_macro[] = {
    L"#include",L"#define",L"#if",L"#else",L"#endif",L"#ifdef",L"#ifndef",L"#pragma"
    };
    const int key_macro_num = 8;//宏语句数量
    const int key_char_num = 12;//关键字符数量
    const std::wstring key_word_color[] = {
    text_darkblue,text_darkblue,text_gray,text_gray,text_darkblue,text_darkblue,
    text_gray,text_gray,text_darkblue,text_darkblue,text_darkblue,
    text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_gray,text_gray,text_darkblue,
    text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_gray,
    text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,
    text_blue,text_blue,text_darkblue,text_darkblue,text_darkblue,
    text_darkblue,
    text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_darkblue,
    text_darkblue,
    text_darkblue,text_darkblue,
    text_darkblue,text_gray,text_darkblue,text_gray,text_gray,text_blue,text_blue,
    text_darkblue,text_gray,text_gray,
    text_darkblue,text_darkblue,text_darkblue,text_darkblue,
    text_darkblue,
    text_darkblue,text_gray,text_darkblue,text_darkblue,
    text_darkblue,text_darkblue,text_darkblue,text_darkblue,text_gray,text_darkblue,text_darkblue,text_gray,text_darkblue,text_darkblue,
    text_darkblue,text_green,text_darkblue,text_darkblue,text_blue,text_blue,text_darkblue,text_darkblue,text_gray,text_darkblue,
    text_darkblue,text_darkblue,text_darkblue,
    text_darkblue,text_darkblue,text_darkblue,
    text_darkblue,text_darkblue,
    text_gray,text_gray,   
    };//关键词标色
    const int key_word_num = 98;
    inline int find_keyword(std::wstring input){
        for(int i = 0;i< key_word_num;i++){
            if(input == key_word[i])
                return i;
        }
        return -1;
    }
    inline int find_macro(std::wstring input){
        for(int i = 0;i< key_word_num;i++){
            if(input == key_macro[i])
                return i;
        }
        return -1;
    }
    inline int find_keychar(wchar_t input){
        for(int i = 0;i<key_char_num;i++){
            if(input == key_char[i])
                return i;
        }
        return -1;
    }
    inline bool isnoncoloredchar(wchar_t input){
        if(iswalpha(input)||iswdigit(input)||input==L'_'||input==L'#'||input==L'\"'||input==L'\'')
            return true;
        else
            return false;
    }
    bool issimulatechar(wchar_t front,wchar_t input){
        if( (iswalpha(front)&&iswalpha(input))||
            (iswalpha(front)&&iswdigit(input))||
            (iswdigit(front)&&iswalpha(input))||
            (iswdigit(front)&&iswdigit(input))||
            (front==L'_'&&(iswdigit(input)||iswalpha(input)||input==L'_'))||
            (input==L'_'&&(iswdigit(front)||iswalpha(front)||front==L'_'))||
            (front==L'#'&&(iswdigit(input)||iswalpha(input)||input==L'#'))||
            (input==L'#'&&(iswdigit(front)||iswalpha(front)||front==L'#'))||
            (find_keychar(front)!=-1 && find_keychar(input)!=-1)||
            (front==input&&front!=L'\"'&&front!=L'\''&&input!=L'\"'&&input!=L'\'')
        )
            return true;
        else
            return false;
    }
    std::vector<std::wstring> sep_bykeychar(std::wstring input){
        std::vector<std::wstring> out;
        for(int a = 0;a<input.length();a++){
            if(a == 0){
                std::wstring put_newstr;
                put_newstr+=input[a];
                a++;
                while(issimulatechar(input[a-1],input[a])&&a<input.length())
                    put_newstr+=input[a++];
                a--;
                out.push_back(put_newstr);
            }
            else{
                std::wstring put_newstr;
                put_newstr+=input[a];
                a++;
                while(issimulatechar(input[a-1],input[a])&&a<input.length())
                    put_newstr+=input[a++];
                a--;
                out.push_back(put_newstr);
            }
        }
        return out;
    }
    bool contain_onlydigit(std::wstring input){
        for(auto&&i:input){
            if(!iswdigit(i))
                return false;
        }
        return true;
    }
    bool is_hex_num(std::wstring input){
        if(input.size()<=1)
            return false;
        if(input[0]==L'0'&&(input[1]==L'x'||input[1]==L'X')){
            for(int i = 2;i<input.length();i++){
                if(!iswdigit(input[i]))
                    return false;
            }    
            return true;
        }else
            return false;
    }
    bool is_long_num(std::wstring input){
        if(input.size()<=1)
            return false;
        if(input[input.size()-1]==L'l'||input[input.size()-1]==L'L'){
            for(int i = 0;i<input.size()-1;i++){
                if(!iswdigit(input[i]))
                    return false;
            }    
            return true;
        }else
            return false;
    }
    bool is_longhex_num(std::wstring input){
        if(input.size()<=1)
            return false;
        if(input[input.size()-1]==L'l'||input[input.size()-1]==L'L'){
            if(input[0]==L'0'&&(input[1]==L'x'||input[1]==L'X')){
                for(int i = 2;i<input.length()-1;i++){
                    if(!iswdigit(input[i]))
                        return false;
                }    
                return true;
            }else
                return false;
        }else
            return false;
    }
    bool is_float_num(std::wstring input){
        if(input.size()<=1)
            return false;
        if(input[input.size()-1]==L'f'||input[input.size()-1]==L'F'){
            for(int i = 0;i<input.size()-1;i++){
                if(!iswdigit(input[i]))
                    return false;
            }    
            return true;
        }else
            return false;
    }
    
    inline int warn_if(bool statement,const std::wstring show,int type_warning){
        if(statement){
            if(show != VOID_PARAMETER)//非空串
                CUIL_std::warning_queue.push({type_warning,show+CUIL_std::_CLEAREFFECT_STR});
            else
                CUIL_std::warning_queue.push({type_warning,_NOW_DEFAULT_WARNING+CUIL_std::_CLEAREFFECT_STR});
        }
        return statement;
    }//如果表达式为真,进行警告
    
    std::vector<std::wstring> split(std::wstring input,wchar_t sep = L','){
        std::vector<std::wstring>input_units;
        for(long long spliti=0;spliti<input.length();spliti++){
            if(input[spliti]!=sep){
                input_units.push_back(L"");
                while(input[spliti]!=sep&&spliti<input.length())
                    input_units[input_units.size()-1]+=input[spliti++];
            }
        }
        return input_units;
    }//分割字符串
    
    std::wstring wstrcpy(std::wstring cpystr,int cpynum){
        std::wstring out_wstrcpy;
        for(int i = 1;i<cpynum;i++)
            out_wstrcpy+=cpystr;
        return out_wstrcpy;
    }//复写字符串
    
    std::wstring wstrcpy(wchar_t cpystr,int cpynum){
        std::wstring out_wstrcpy;
        for(int i = 1;i<=cpynum;i++)
            out_wstrcpy+=cpystr;
        return out_wstrcpy;
    }//对wchar_t的重载
    void clear_warning(){
        while(!warning_queue.empty())
            CUIL_std::warning_queue.pop();
        return ;
    }//清除警告
    void updwarning(){
        while(!CUIL_std::warning_queue.empty()){
            std::wcout  << L"|"<<warning_color_type[CUIL_std::warning_queue.front().warn_type]<<L"  "<<_CLEAREFFECT_STR<<L"|"
                        <<CUIL_std::warning_queue.front().content<<L"\n";
            CUIL_std::warning_queue.pop();
        }
        std::wcout<<std::endl;
    }//清空并输出警告队列
    void PAUSE(){
        wchar_t tmp;
        std::wcout<<L"输入任意键以继续>>>";
        system("stty raw");
        wscanf(L"%c",&tmp);
        system("stty -raw");
        std::wcout<<std::endl;
    }
    std::wstring make_shapebool(bool input){
        return input?(L"是|"+green+L"  "+_CLEAREFFECT_STR):(L"否|"+red+L"  "+_CLEAREFFECT_STR);
    }
    std::wstring formin(const std::wstring show = L"输入:",int line_len = 10){
        std::wcout << show;
        std::wstring line = wstrcpy(L"_",line_len);
        std::wstring back = wstrcpy(L"\b",line_len);
        std::wcout << line<<back;
        std::wstring input;
        getline(std::wcin,input);
        return input;
    }
    
    //复合组件原型
    template<class T>int uniselect(const std::vector<T>choice_list,std::wstring title=L"",wchar_t last_sign=L'w',wchar_t next_sign=L's',wchar_t end_sign=L'y',int choice_first=1);//一元选择器
    void dot_linerary_load(double wait_time,int width = 10,int height = 1,bool has_boarder = true,bool has_progress = true,wchar_t show_char = L'O',wchar_t blank_char = L' ');//点型加载
    void shape_linerary_load(double wait_time,int width = 10,int height = 1,bool has_border = true,bool has_progress = true,std::wstring format_pass = _CLEAREFFECT_STR,std::wstring format_border = _CLEAREFFECT_STR,wchar_t pass_char = L'■',wchar_t show_char = L'■',wchar_t blank_char = L' ');//线性加载 
    void ring_linerary_load();//环形加载动效
    void print(const std::wstring content,const format formatin = printformat,bool step = true,double wait_time = 5.0,bool end = true);//打印
    void printcode(const std::wstring code,const std::wstring lang = L"cpp");
    //复合组件实现

    
    
    template<class T>
    int uniselect(const std::vector<T> choice_list,std::wstring title,wchar_t last_sign,wchar_t next_sign,wchar_t end_sign,int choice_first){
        wchar_t tmp_listchoice=L' ';
        int choice_now = choice_first;
        while(tmp_listchoice!=end_sign){
            std::wcout<<L"("<<last_sign<<L","<<next_sign<<L"上下切换选项,"<<end_sign<<L"确定)"<<std::endl<<title<<std::endl<<L"选择:"<<std::endl;
            
            for(int choice_i = 1;choice_i<=choice_list.size();++choice_i)
                std::wcout<<(choice_now==choice_i?L">  ":L"   ")<<choice_i<<L"." << choice_list.at(choice_i-1) << std::endl;
            std::wcout<<">>>";
            tmp_listchoice=datain();
            if(tmp_listchoice==last_sign)
                choice_now-=(choice_now>1?1:0);
            if(tmp_listchoice==next_sign)
                choice_now+=(choice_now<choice_list.size()?1:0);
            doclear();
        }
        return choice_now;
    }
    void dot_linerary_load(double wait_time,int width,int height,bool has_border,bool has_progress,wchar_t show_char,wchar_t blank_char){
        if(warn_if(wait_time<0.0,L"dot_linerary_load组件参数错误:时间参数不得小于0",1))
            return ;
        if(warn_if(width<0,L"dot_linerary_load组件参数错误:长度参数不得小于0",1))
            return ;
        if(warn_if(height<0,L"dot_linerary_load组件参数错误:高度参数不得小于0",1))
            return ;
        doclear();
        std::wstring up_border_str = L"┌" + wstrcpy(L"─",width+1) + L"┐\n",
                     down_border_str = L"└" + wstrcpy(L"─",width+1) + L"┘\n";
        for(int i = 1;i<=width;i++){
            doclear();
            if(height == 1){
                std::wcout << (has_border?L"[":L"");
                for(int j = 0;j<width;j++){
                    if(j==i-1)
                        std::wcout << show_char;
                    else
                        std::wcout << blank_char;
                }
                std::wcout << (has_border?L"]":L"") << _CLEAREFFECT_STR;
                if(has_progress)
                    std::wcout << int(100*i/width) <<L"%"<<_CLEAREFFECT_STR;//文字颜色自行添加
                std::wcout << std::endl;
            }
            else{
                std::wstring mid_content_str = (has_border?L"│":L"") + wstrcpy(blank_char,i-1) + show_char + wstrcpy(blank_char,width-i) + (has_border?L"│":L""); 
                if(has_border)
                    std::wcout << up_border_str;
                for(int k = 0;k<height;k++){
                    std::wcout << mid_content_str;
                    if(k==(height+1)/2){
                        if(has_progress)
                        std::wcout << int(100*i/width) <<L"%"<<_CLEAREFFECT_STR;//文字颜色自行添加
                    }
                    std::wcout << L"\n"; 
                }
                if(has_border)
                    std::wcout << down_border_str;
            }
            usleep(int(wait_time*1000000)/width);
        }//线性加载动效
    }
    void shape_linerary_load(double wait_time,int width,int height,bool has_border,bool has_progress,std::wstring format_pass,std::wstring format_border,wchar_t pass_char,wchar_t show_char,wchar_t blank_char){
        if(warn_if(wait_time<0.0,L"shape_linerary_load组件参数错误:时间参数不得小于0",1))
            return ;
        if(warn_if(width<0,L"shape_linerary_load组件参数错误:长度参数不得小于0",1))
            return ;
        if(warn_if(height<0,L"shape_linerary_load组件参数错误:高度参数不得小于0",1))
            return ;
        std::wstring up_border_str = format_border + L"┌" + wstrcpy(L"─",width+1) + L"┐\n"+_CLEAREFFECT_STR,
                     down_border_str = format_border + L"└" + wstrcpy(L"─",width+1) + L"┘\n"+_CLEAREFFECT_STR;
        for(int i = 1;i<=width;i++){
            doclear();
            if(height == 1){
                std::wcout << format_border << (has_border?L"[":L"") << _CLEAREFFECT_STR;
                std::wcout << format_pass;
                for(int j = 0;j<width;j++){
                    if(j<i-1)
                        std::wcout << pass_char;
                    else if(j==i-1)
                        std::wcout <<show_char<
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值