跳到正文

休闲·娱乐

小游戏

yaoyg约 24 分钟
原文

这是 2025年12月26日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本
C++
#include <bits/stdc++.h>
using namespace std;

class enemy
{
public:

    struct enemykind
    {
        string name;
        int bl_v;
        int enemy_at_powwer;
    };
    
    enemykind kind[1000]={{"natural",500,100},
                          {},
                        };

    int Enemy_Unit_Combination[10][10000]={{1,1,1,1,1}};

    int e[100];
    void emy(int en_co)//敌方初始化
    {
        for(int i=0;i<5;i++)
        {
            e[i]=kind[Enemy_Unit_Combination[i][en_co-1]].bl_v;
        }
    }
    void print()//显示敌方状态
    {
        for(int i=0;i<5;i++)
        {
            cout<<"|";
            if(e[i]==0)
            {
                cout<<" 消亡";
                continue;
            }
            printf("%5d",e[i]);
        }
        cout<<"|"<<endl;
        cout<<"|     |     |     |     |     |"<<endl;
        cout<<"-------------------------------"<<endl;
        cout<<"|     |     |     |     |     |"<<endl;
        for(int i=5;i<10;i++)
        {
            cout<<"|";
            if(e[i]==0)
            {
                cout<<" 消亡";
                continue;
            }
            printf("%5d",e[i]);
        }
        cout<<"|"<<endl;
    }
    int ifkia()//全灭判断
    {
        for(int i=0;i<10;i++)
        {
            if(e[i])
            {
                return 0;
            }
        }
        return 1;
    }
private:
};

enemy en_o;//敌人对象
class The_lost
{
public:

    int att_power=100;
    int lostnl=0,life=1500;
    string name="the lost";
    bool recovery_state = false; // 「回复」状态标记
    int recovery_turn = 0;       // 「回复」状态剩余回合
    int damage_record = 0;       // 「回复」状态下记录的伤害值
    int rationality=0;//理性点,普攻后增加,消耗以发动e技能,理智点属于各个角色独有,不与其他角色共享
    The_lost()
    {
        att_power=100;
        lostnl=0;
    }
    void lostaskill(int d,int *lostnl,int *e,int *rationality)//普攻
    {
        *lostnl=*lostnl+20;
        int damage = 0.8 * att_power;
        e[d]-=damage;
        if(recovery_state) {
            damage_record += damage;
            cout<<"【回复状态】记录普攻伤害:"<<damage<<" 累计:"<<damage_record<<endl;
        }
        *rationality+=1;
        if(e[d] <= 0) 
        {
            e[d] = 0;
        }
    }
    void losteskill(int d,int *lostnl,int *e,int *rationality)//e技能
    {
        if(*rationality>0)
        {
            *rationality-=1;
        }
        else
        {
            cout<<"理性不足"<<endl;
            return;
        }
        int damage = 2 * att_power;
        e[d]-=damage;
        if(recovery_state) {
            damage_record += damage;
            cout<<"【回复状态】记录E技能伤害:"<<damage<<" 累计:"<<damage_record<<endl;
        }
        *lostnl+=30;
        if(e[d] <= 0)
        {
            e[d] = 0;
        }
    }
    void lostqskill(int *lostnl,int *e)//大招
    {
        if(*lostnl>=qenergy)
        {
            *lostnl-=qenergy;
        }
        else
        {
            cout<<"能量不足"<<endl;
            return;
        }

        // 大招核心逻辑:回复2个理性点,进入回复状态(持续2回合),重置伤害记录
        rationality += 2;
        recovery_state = true;
        recovery_turn = 3+1;
        damage_record = 0;
        cout<<"【Q技能生效】回复2个理性点(当前:"<<rationality<<"),进入「回复」状态,持续3回合!"<<endl;

        // 回复状态结束处理(如果是状态到期)- 此处由回合逻辑触发,这里仅初始化状态
        *lostnl+=30;
    }

    //每回合结束时调用,更新回复状态
    void update_recovery_state() {
        if(recovery_state) 
        {
            int damage_record_per=0.5;
            recovery_turn--;
            cout<<"【回复状态】剩余回合:"<<recovery_turn<<endl;
            int heal = damage_record * damage_record_per;
            damage_record*=damage_record_per;
            life += heal;
            // 生命值不超过上限
            if(life > 1500) life = 1500;
            cout<<"【回复状态】累计造成伤害:"<<damage_record<<",转化"<<heal<<"点记录值(当前:"<<life<<")"<<endl;
	     if(recovery_turn==0)
            {
                recovery_state = false;
                damage_record = 0;
            } 
        }
    }
private:
    int qenergy=180;//e技能能量、q技能能量
};

class operate
{
public:
    int generate()//生成敌方
    {
        cout<<"战斗开始"<<endl;
        en_o.emy(1);
        en_o.print();
        return 0;
    }
    The_lost lost;
    queue <string>actionqueue;//行动队列
    //行动队列中的单位会轮换行动
    int select(int rs)//选择角色
    {
        for(int i=0;i<5;i++)
        {
            actionqueue.push("monster");
        }
        for(int i=0;i<rs;i++)
        {
            string rolename; 
            cout<<"踏上前来,你是:(me)"<<endl;
            cin>>rolename;
            actionqueue.push(rolename);
        }
        while (!en_o.ifkia())//回合轮换
        {
            string ppp=actionqueue.front();
            move(ppp);
            actionqueue.pop();
            actionqueue.push(ppp);
        }
        cout<<"战斗胜利"<<endl;
        return 0;
    }
    int move(string role)
    {
        if(role=="me")//迷途之人便是你    你的操作
        {
            //cout<<"迷途之人"<<endl;
            cout<<" 选择操作  当前能量:"<<lost.lostnl<<"       理性点:"<<lost.rationality<<endl;
            cout<<"a   e   q"<<endl;
            char operationoptions;
            cin>>operationoptions;
            if(operationoptions=='a')
            {
                int d;
                en_o.print();
                cout<<"请选择目标(1~5):"<<endl;
                cin>>d;
                d-=1;
                lost.lostaskill(d,&lost.lostnl,en_o.e,&lost.rationality);
                en_o.print();
                cout<<endl;
            }
            if(operationoptions=='e')
            {
                int d;
                en_o.print();
                cout<<"请选择目标(1~5):"<<endl;
                cin>>d;
                d-=1;
                en_o.print();
                lost.losteskill(d,&lost.lostnl,en_o.e,&lost.rationality);
                en_o.print();
                cout<<endl;
            }
            if(operationoptions=='q')
            {
                en_o.print();
                lost.lostqskill(&lost.lostnl,en_o.e);
                en_o.print();
                cout<<endl;
            }
            lost.update_recovery_state();
        }
        else if(role=="monster")
        {
            cout<<"pass"<<endl;
        }
        return 0;
    }
};

class display
{
public:
    string screen_stirp[20]={"==============================================================",//0     //界面显示条,长最长60+2字符
                             "|                                                            |",//1
                             "|                          wating.                           |",//2
                             "|                          wating..                          |",//3
                             "|                          wating...                         |",//4
                             "|          ","          |",//小型区(10+1)
                              //     5            6
                             "     "};//mini款
                             // 7
//------------------------------------------------------------------------游戏开始显示
    struct AnimationFrame {
        string text;
        string progress_bar;
    };
    // 预定义动画帧
    vector<AnimationFrame> loading_frames = {
        {screen_stirp[2], "□□□□□□□□□□□□□□□□□□□□"},
        {screen_stirp[3], "■□□□□□□□□□□□□□□□□□□□"}, 
        {screen_stirp[4], "■■□□□□□□□□□□□□□□□□□□"}, 
        {screen_stirp[2], "■■■□□□□□□□□□□□□□□□□□"}, 
        {screen_stirp[3], "■■■■□□□□□□□□□□□□□□□□"}, 
        {screen_stirp[4], "■■■■■□□□□□□□□□□□□□□□"}, 
        {screen_stirp[2], "■■■■■■□□□□□□□□□□□□□□"}, 
        {screen_stirp[3], "■■■■■■■□□□□□□□□□□□□□"}, 
        {screen_stirp[4], "■■■■■■■■□□□□□□□□□□□□"}, 
        {screen_stirp[2], "■■■■■■■■■□□□□□□□□□□□"}, 
        {screen_stirp[3], "■■■■■■■■■■□□□□□□□□□□"}, 
        {screen_stirp[4], "■■■■■■■■■■■□□□□□□□□□"}, 
        {screen_stirp[2], "■■■■■■■■■■■■□□□□□□□□"}, 
        {screen_stirp[3], "■■■■■■■■■■■■■□□□□□□□"}, 
        {screen_stirp[4], "■■■■■■■■■■■■■■□□□□□□"}, 
        {screen_stirp[2], "■■■■■■■■■■■■■■■□□□□□"}, 
        {screen_stirp[3], "■■■■■■■■■■■■■■■■□□□□"}, 
        {screen_stirp[4], "■■■■■■■■■■■■■■■■■□□□"}, 
        {screen_stirp[2], "■■■■■■■■■■■■■■■■■■□□"}, 
        {screen_stirp[3], "■■■■■■■■■■■■■■■■■■■□"}, 
        {screen_stirp[4], "■■■■■■■■■■■■■■■■■■■■"}


    };
    // 渲染单个帧的通用方法
    void render_frame(const AnimationFrame& frame) {
        cout << screen_stirp[0] << endl << screen_stirp[1] << endl;
        cout << screen_stirp[1] << endl << screen_stirp[1] << endl;
        cout << screen_stirp[1] << endl << screen_stirp[1] << endl;
        cout <<frame.text << endl;
        cout << screen_stirp[5] + screen_stirp[7] + screen_stirp[7];
        cout << frame.progress_bar;
        cout << screen_stirp[7] + screen_stirp[7] + screen_stirp[6] << endl;
        cout << screen_stirp[1] << endl << screen_stirp[0] << endl;
    }
    
    int start_screen()//开始屏幕显示
    {
        int a;
        cout<<screen_stirp[0]<<endl<<screen_stirp[1]<<endl;
        cout<<screen_stirp[5]<<"--                                    --"<<screen_stirp[6]<<endl;
        cout<<screen_stirp[5]<<"(            名为数学的游戏            )"<<screen_stirp[6]<<endl;
        cout<<screen_stirp[5]<<"--                                    --"<<screen_stirp[6]<<endl<<screen_stirp[1]<<endl;
        cout<<screen_stirp[5]<<"        (输入任意内容以开始游戏)        "<<screen_stirp[6]<<endl<<screen_stirp[1]<<endl<<screen_stirp[1]<<endl<<screen_stirp[0]<<endl;
        cout<<"输入任意内容以开始游戏:";
        cin>>a;
        cout<<endl;
        cout<<"欢迎来到“名为数学的游戏”游戏马上开始"<<endl;
        
        // 播放加载动画
        for (const auto& frame : loading_frames) {
            render_frame(frame);
            std::this_thread::sleep_for(std::chrono::milliseconds(300));
        }
        
        return 0;
    }
//------------------------------------------------------------------------游戏开始显示
//------------------------------------------------------------------------角色 or 战斗

    int display_role()
    {
        // 显示角色
        string name;
        cout<<"请输入名称(me):";
        cin>>name;
        if(name=="me")
        {
            cout<<"角色名称:"<<name<<endl;
            cout<<"角色技能:"<<endl;
            cout << screen_stirp[7] + "天赋:探索者    羁绊:独行者" << endl;
            cout << screen_stirp[7] + screen_stirp[7] + "天赋:    作为独行于此的你,步步为艰,你将探索此地,学习便是你最好的武器,(经过学习你将会获得新的一套技能)" << endl;
            cout << screen_stirp[7] + "形态:无知    初来乍到,你一无所知" << endl;
            cout << screen_stirp[7] + screen_stirp[7] + "普攻a:   回复一个理性点,对指定敌方单体造成80%攻击力的伤害,回复20能量" << endl;
            cout << screen_stirp[7] + screen_stirp[7] + "E技能e:  消耗一个理性点,对指定敌方单体造成200%攻击力的伤害,回复30能量" << endl;
            cout << screen_stirp[7] + screen_stirp[7] + "Q技能q:  消耗180能量,回复两个理性点,进入「回复」状态,持续三回合,此状态下记录角色造成的伤害,在状态中,每回合结束后将记录的伤害的50%转化为血量回复量" << endl;

        }
        else
        {
            cout<<"(请勿重复进行无效输入,否则电脑堆栈将爆炸)木有欧"<<endl;
            display_role();
        }
        return 0;
    }

    int choose_look_or_fight()
    {
        cout<<screen_stirp[0]<<endl;
        cout<<screen_stirp[1]<<endl;
        cout<<screen_stirp[1]<<endl;
        cout<<screen_stirp[1]<<endl;
        cout<<"|                      输入“c”查看角色                       |"<<endl;
        cout<<"|                      输入“f”开始战斗                       |"<<endl;
        cout<<screen_stirp[1]<<endl;
        cout<<screen_stirp[1]<<endl;
        cout<<screen_stirp[1]<<endl;
        cout<<screen_stirp[0]<<endl;
        string a;
                    // 清除输入缓冲区
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
        cout<<"请输入:";
        cin>>a;
        // 清除输入缓冲区
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
        
        if(a=="c")
        {
            display_role();
        }
        else if(a=="f")
        {
            operate fight;
            fight.generate();
            fight.select(1);//只有一个角色
        }   
        else
        {
            cout<<"(请勿重复进行无效输入,否则电脑堆栈将爆炸)无效输入,请重新输入:"<<endl;
            choose_look_or_fight();
        }
        return 0;
    }
    

};

int main()
{
    display screen;
    //screen.start_screen();
    screen.choose_look_or_fight();
    // operate fight;
    // fight.generate();
    // fight.select(1);//只有一个角色
    return 0;
}