跳到正文

个人记录

RPG-Maker(Build a1w6)

bzy369258147约 24 分钟
原文
文章信息与版本

文章信息

发布
2017年12月19日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 24 分钟
获赞
9

版本

  1. v1当前

`

/*---------------------------*/

C++
        //        RPG编辑器 
        //     由bzy纯手工打造 
        //    版本号:Build a1w6 
        //    版本日期:17-12-20 
        //          c++11 
        // Copyright MICStudios 2017

/*---------------------------*/

C++
        //文件 RPG.h
        //接口: 
        //        1. Trie类 
        //        2. NPC 类 
        //        3. NPC_RunTime类(RPG编辑器的核心环境)
        //        4. NPC_RunTime.stringstream的输入输出流
        //        5. Consale类
        //        6. Consale_GDI类 \
        //          7. Label类
        //功能:
        //        1. Trie的字符串存储
        //        2. 模式匹配查询NPC属性,操作,事件 
        //        3. 改变Console窗体属性
        //        4. 窗体绘图集成 
        //        5. 整体RPG集成
        //----------------------------------------------
        #include<bits/stdc++.h>
        #include<time.h>
        #include<windows.h>
        #include<conio.h>
        #define UI unsigned int
        typedef std::string _S;
        UI Get_Hash_Code( _S __str ){
            int _len = __str.size();
            const UI _key = 127;
                  UI _ans = 0;
            for(int i = 0;i ^ _len; i++){
                _ans += __str[ i ];
                _ans *= _key ;
            }
            return _ans;
        }
        UI Get_KMP_Place( _S __str, _S __key){
            const UI str_len = __str.size();
            const UI key_len = __key.size();
            UI next[ key_len + 2 ] = {0,0};
            UI i = 1, t = 0, n = 0;
            while( i <= key_len ){
                while( t > 0 and __key[i - 1] ^ __key[t - 1]){
                    t = next[t];
                }
                t ++;
                i ++;
                if( __key[i - 1] == __key[t - 1]){
                    next[i] = next[t];
                }else{
                    next[i] = t;
                }
            }
            while( t > 0 and __key[i - 1] ^ __key[t - 1]){
                t = next[t];
            }
            t ++;
            i ++;
            next[i] = t;
            i = 0; t = 1; n = 0;
            while( key_len + 1 - t <= str_len - i){
                if( __str[i] == __key[t - 1] ){
                    i ++;
                    t ++;
                    if( t == key_len + 1){
                        return i - key_len;
                    }
                }else{
                    t = next[ t ];
                    if(t == 0){
                        i ++ ;
                        t ++ ;
                    }
                }
            }
            return 2147483647;
        }
        _S _str_int(int _input){
            std::stringstream _temp;
            _S _fin;
            _temp << _input;
            _temp >> _fin;
            return _fin;
        }
        _S _Getch_Dir(){
            int ch = getch();
            while(1){
                if( isascii(ch) )continue;
                ch = getch();
                switch( ch ){
                    case 72:
                        return "UP";
                    break;case 75:
                        return "LEFT";
                    break;case 77:
                        return "RIGHT";
                    break;case 80:
                        return "DOWN";
                }
            }
        }
        template<typename tp>
            class Trie{

private :

C++
                struct node{
                    tp _val;
                    node *_next[16] ;
                    UI _get;
                    node() { _get = 0; }
                }*_root;
                UI table[16];
                tp _wCode ;

public :

C++
                Trie(){
                    _root = new node();
                    _wCode = *new tp();
                    for(int i = 0;i <= 15;i ++){
                        table[i] = 1 << i;
                    }
                }
                tp& push( _S _sign, tp __val){
                    node **__now = & _root; 
                    const UI _way = 15;
                    const UI _que = 4 ;
                          UI _place = Get_Hash_Code( _sign );
                    while( _place ){
                        const UI __next = _place & _way;
                        if(!((*__now) -> _get &  table[ __next ])){
                             (*__now) -> _get |= table[ __next ];
                             (*__now) -> _next[__next] = new node();
                        }
                        __now = &((*__now) -> _next[ __next ] );
                        _place >>= _que;
                    }
                    (*__now) -> _val = __val ;
                    return (*__now) -> _val;
                }
                tp& get( _S _sign ){
                    node **__now = & _root;
                    const UI _way = 15;
                    const UI _que = 4 ;
                          UI _place = Get_Hash_Code( _sign );
                    while( _place ){
                        const UI __next = _place & _way;
                        if(!((*__now) -> _get &  table[ __next ])){
                            return _wCode;
                        }
                        __now = &((*__now) -> _next[ __next ] );
                        _place >>= _que;
                    }
                    return (*__now) -> _val ;        
                }
                tp& operator()(std::string A){
                    return get(A);
                }
                tp& operator()(std::string A,int B){
                    return push(A,0);
                }
            };
        enum NPC_Type{
            NPC_Player = 0,
            NPC_Friend = 1,
            NPC_Assembly = 2,
            NPC_Normal = 3
        };
        class NPC{

public:

C++
            int type;
            _S  name ;
            Trie<int>priority ;
            NPC(){}
            NPC(int _type,std::string _name){type = _type;name = _name;}
            int operator ()(std::string A){
                return priority(A);
            }
            int& operator ()(std::string A,bool B){
                return priority(A,B);
            }
        };
        class NPC_op{

public:

C++
               _S name ;
            _S style;
            _S link ;
            bool is_positive ;
            NPC_op(){}
        };
        class Console{

public:

C++
            int ForeColor;
            int BackColor;
            int width;
            int height;
            HANDLE hwnd  ; 
            void refresh(){
                SetWindowsLong(width,height);
                SetColor(ForeColor,BackColor);
            }
            void SetWindowsLong( UI _w, UI _h){
                _S  __command = 
                "mode con cols="  +  _str_int(_w * 2) + 
                " lines="           +  _str_int(_h) ;
                system( __command.c_str() );
            }
            void SetColor( UI _f, UI _b){
                ForeColor = _f;
                BackColor = _b;
                SetConsoleTextAttribute(hwnd, ForeColor + BackColor * 16);
            }
            void GoToXY( UI __x, UI __y){
                COORD _pos = { __x * 2, __y } ;
                SetConsoleCursorPosition( hwnd, _pos ) ;
            }
            Console(){
                hwnd = GetStdHandle(STD_OUTPUT_HANDLE);
                SetColor(7,0);
            }
        };
        class Console_GDI{

public:

C++
            _S BLANK;
            Console Obj ;
            void Borad( UI x1, UI y1, UI x2, UI y2){
                for(int i = x1;i <= x2; i ++){
                    Obj.GoToXY(i,y1);
                    puts( BLANK.c_str() );
                    Obj.GoToXY(i,y2);
                    puts( BLANK.c_str() ); 
                }
                for(int i = y1;i <= y2; i ++){
                    Obj.GoToXY(x1,i);
                    puts( BLANK.c_str() );
                    Obj.GoToXY(x2,i);
                    puts( BLANK.c_str() );
                }
            }
            void Fill( UI x1, UI y1, UI x2, UI y2 ){
                _S __this = "";
                for(int i = y1;i <= y2;i ++)__this += BLANK;
                for(int i = x1;i <= x2;i ++){
                    Obj.GoToXY(y1,i);
                    puts( __this.c_str() );
                } 
            }
            void point(UI x,UI y){
                Obj.GoToXY( x, y );
                puts( BLANK.c_str() ) ;
            }
            template <typename tp>
                void PutChar( UI x, UI y, tp __text ){
                    std::stringstream _str ;
                    _S _As_Return ;
                    _str << __text;
                    _str >> _As_Return;
                    Obj.GoToXY( x, y );
                    puts( _As_Return.c_str() );
                }
            Console_GDI(){ BLANK = "  " ; Obj = * new Console ;}
        };
        class label{

public :

C++
            UI x,y;
            UI width,height;
            std::vector<_S> text;
            UI ForeColor;
            UI BackColor;
            UI BordColor;
            bool IsHide ; 
            label(){}
            label(UI _x, UI _y, UI _w, UI _h){x = _x; y = _y; width = _w; height =_h;ForeColor = 7;BordColor = BackColor = 0;IsHide = false;}
        };
        class NPC_RunTime{

public:

C++
            Trie<NPC> NPCs;
            Trie<NPC_op> OPer;
            Trie<label> Labels;
            std::stringstream Back_str;
            std::stringstream _Inputs ;
            Console_GDI _Con ;
            template<typename tp>
                void write(tp _text){
                    std::stringstream __temp;
                    _S  __mid;
                    __temp << _text;
                    __temp >> __mid;
                    _Inputs << __mid << " ";
                }
            void add_NPC(NPC _from){
                NPCs.push( _from.name , _from);
            }
            void add_op(NPC_op _op){
                OPer.push( _op.name , _op ) ;
            }
            void NPC_op_run(){
            }
            void Paint(_S _label_name){
                label _clude = Labels( _label_name ) ;
                if( _clude.IsHide )return ;
                UI _BKC = _clude.BackColor;
                UI _BDC = _clude.BordColor;
                UI _FRC = _clude.ForeColor;
                UI _x   = _clude.x;
                UI _y   = _clude.y;
                UI _wid = _clude.width;
                UI _hei = _clude.height;
                _Con.Obj.SetColor( _FRC, _BDC );
                _Con.Borad(_x, _y, _x + _wid, _y + _hei);
                _Con.Obj.SetColor( _FRC, _BKC );
                _Con.Fill(_x + 1,_y + 1,_x + _wid - 1,_y + _hei -1);
                int _line = 0;
                while( _line ^ _clude.text.size() ){
                    _Con.Obj.GoToXY( _x + 1, _y + _line + 1);
                    puts( _clude.text[ _line ].c_str() );
                    _line ++; 
                }
            }
            void Hide(_S _label_name){
                label &_clude = Labels( _label_name ) ;
                if( _clude.IsHide )return ;
                UI _x   = _clude.x;
                UI _y   = _clude.y;
                UI _wid = _clude.width;
                UI _hei = _clude.height;
                _clude.IsHide = true;
                _Con.Fill( _x, _y, _x + _wid, _y + _hei ); 
            } 
            void Show(_S _label_name){
                label &_clude = Labels( _label_name ) ;
                if(! _clude.IsHide )return ;
                _clude.IsHide = false;
                Paint( _label_name );
            }
            NPC_Runtime(){
                NPCs = * new Trie<NPC>();
                OPer = * new Trie<NPC_op>();
                Labels = * new Trie<label>();
                _Con = * new Console_GDI;
            }
        };
`
原文
存档评论2 条抓取于