C++小游戏

· · 个人记录

极小部分非原创
#include "heads.h"
#include "io.h"
typedef long long ll;
string weapon[10] = {"木剑" , "石剑" , "铁剑" , "钻石剑" , "下界合金剑" , "寰宇支配之剑" , "乱码剑" , "五彩斑斓剑" , "深渊剑" , "氪金萝莉"};
string skillname[6] = {"无技能","狂暴旋风","雷霆万钧","冰封千里","阴晦之气","金锋之光"};
string skilleffect[6] = {"无","无","无","无","阴晦","耀光"};
string skille[6] = {"无","无","无","无","攻击减100000","攻击减200000"};
int s1=0,s2=0,s3=0,s4=0,s5=0;
int skillnum = 0;
int skillenergy[6] = {0,5,15,10,7,8};
int skillatk[6] = {0,500,1500,1000,700,800};
int skilln = 0;
void fightmainban () {
    puts ("-----------------------------------------------");
    puts ("                    选择行动                  ");
    puts (" 1、砍击   2、刺击   3、回血   4、逃跑  5、技能");
    puts ("-----------------------------------------------");
}
void skillmianban (int num){
        if (num = 0){
            puts ("-----------------------------------------------");
            puts ("               你没有技能可选择                ");
            puts ("-----------------------------------------------");
        }
        else{
            puts ("-----------------------------------------------------------");
            puts ("                         选择技能                          ");
            puts ("1、狂暴旋风 2、雷霆万钧 3、冰封千里 4、阴晦之气 5、金锋之光");
            puts ("-----------------------------------------------------------");
        }
    }
void mianban (int page){
    if (page==1){
        print("<TCF                                                                            >",0xF8,0,0,1);
        print("<TCF  >                                                                        <TCF  >",0xF8,0,1,0);
        print("<TCF  ><TF8                             选择行动                                   ><TCF  >",0xF8,0,2,0);
        print("<TCF  ><TF8 1、战斗:NPC 2、末日机械商店 3、财富积蓄 4、最终目标:末日新生 5、更多 ><TCF  >",0xF8,0,3,1);
        print("<TCF  >                                                        ",0xF8,0,4,1);
        print("<TCF  ><TF8                  选择:                                                ><TCF  >",0xF8,0,4,0);
        print("<TCF  >                                                                        <TCF  >",0xF8,0,5,0);
        print("<TCF                                                                            >",0xF8,0,6,1);
        print("",0xF8,28,4,0);
    }
    else{
        puts("6、抽奖 7、指令 8、进入村庄");
    }

}
COORD gets_font_size()
{
    COORD font_size;
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    /* 字体信息 */
    struct CONSOLE_FONT
    {
        DWORD index;
        COORD dim;
    } cfi;
    typedef COORD (WINAPI *PROCGETCONSOLEFONTSIZE)(HANDLE, DWORD);
    typedef BOOL (WINAPI *PROCGETCURRENTCONSOLEFONT)(HANDLE, BOOL, struct CONSOLE_FONT*);

    HMODULE hKernel32 = GetModuleHandle("kernel32");
    PROCGETCONSOLEFONTSIZE GetConsoleFontSize = (PROCGETCONSOLEFONTSIZE)GetProcAddress(hKernel32,"GetConsoleFontSize");
    PROCGETCURRENTCONSOLEFONT GetCurrentConsoleFont = (PROCGETCURRENTCONSOLEFONT)GetProcAddress(hKernel32,"GetCurrentConsoleFont");

    GetCurrentConsoleFont(handle, FALSE, &cfi);             /* 获取当前字体索引信息 */
    font_size = GetConsoleFontSize(handle, cfi.index);      /* 获取当前字体宽高信息[字符宽度及高度所占像素数] */

    return font_size;
}

/*******************************************************************************
 * 最大化展示控制台窗口
 ******************************************************************************/
void full_screen()
{
    HWND hwnd = GetForegroundWindow();
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);   /* 标准输出缓冲区句柄 */
    int cx = GetSystemMetrics(SM_CXSCREEN);            /* 屏幕宽度 */
    int cy = GetSystemMetrics(SM_CYSCREEN);            /* 屏幕高度 */

    COORD size = gets_font_size();
    char cmd[32] = { 0 };
    sprintf(cmd, "MODE CON: COLS=%d LINES=%d", cx / size.X, cy / size.Y);
    system(cmd);
    SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}
int main () {
    system("color f0");
    full_screen();
    SetConsoleTitle("GAR 3:末日新生");
    srand ((unsigned)time (NULL));
    int chance = 2 , bloodchance = 2 , pricechange = 2 , hotal = 500 , tmpblood;
    string s;
    ll blood1 = 300000 , atk1 = 300000 , wep = 0;
    ll atk , blood , equipment , money = 0 , experience = 0;
    print("<TFC----------GAR 3:末日新生  <TF5末日机械工作室:GARS> 出品------------------>",0xF8,0,0,10);
    print("<TFC请输入您的名字:>",0xF8,0,1,10);
    print("<TFC--------------------------------------------------------------------->",0xF8,0,2,10);
    print("",0xF8,15,1,0);
    HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(handle, &csbi);
    SetConsoleTextAttribute(handle, 0xF9);
    WORD colorOld = csbi.wAttributes;
    s=getstr(16);
    SetConsoleTextAttribute(handle, colorOld);
    if (s == "GARS" || s == "机械贾瑞斯"|| s == "xxz") {
        atk = 99999999;
        blood = 99999999;
        equipment = 99999999;
        money = 99999999999;
        experience = 999999999;
    }
    else if (s == "GARK" || s == "机械贾卡斯"||s=="zxy") {
        atk = 9999999;
        blood = 99999999;
        equipment = 99999999;
        money = 999999999;
        experience = 999999999;
    }
    else {
        atk = rand () % 10 + 99900;
        blood = rand () % 9 + 50000;
        equipment = rand (); 
        tmpblood = blood;
    }
    int bl = 2;
    bool killed = false;
    blood += equipment;
    char buff[150];
    sprintf(buff,"<TF9%s> <TFCatk:>%lld <TFCblood:>%lld <TFCequipment:>%d \n",s.c_str(),atk,blood,equipment,experience);
    print(buff,0xF8,0,3,10);
    char opt;
    while (1) {
i:      Sleep(2000);
        system("cls");
        if (killed) blood = tmpblood;
        int i = 1,page = 1;
        mianban (page);
        HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        GetConsoleScreenBufferInfo(handle, &csbi);
        SetConsoleTextAttribute(handle, 0xF9);
        WORD colorOld = csbi.wAttributes;
        opt=getch();
        putch(opt);
        SetConsoleTextAttribute(handle, colorOld);
        print("",0xF8,0,7,0);
        if (opt == '1') {
            int energy=0;
            while (1) {
                int blood1 = rand () % 10 + 50000;
                int atk1 = rand () % 9 + 2000;
                cout << "NPC血量=" << blood1 << ". 攻击力=" << atk1 << endl;
                cout << "第" << i << "回合" << endl;
                cout << "请问" << s << "要干什么?" << endl;
                fightmainban ();
                int k;
                cin >> k;
                if (k == 1) {
                    int tmp = rand () % 10;
                    if (tmp < 4) {
                        blood1 -= (atk * 2);
                        cout << s << "使用附魔钻石剑砍击" << endl;
                        cout << "NPC" << "还剩" << blood1 << "血" << endl;
                        energy+=4;
                    }
                    else {
                        blood1 -= atk;
                        cout << s << "使用" << weapon[wep] << "砍击" << "NPC" << endl;
                        cout << "NPC" << "还剩" << blood1 << "血" << endl;
                        energy+=2;
                    }
                }
                if (k == 2) {
                    if (energy<=5){
                        cout << "能量不足!"<<endl;
                    }
                    else{
                        blood-=atk*3;
                        cout<<s<<"使用"<<weapon[wep]<<"刺击"<<"NPC"<<endl;
                        cout<<"NPC还剩"<<blood1<<"血"<<endl; 
                    }
                }
                if (k == 3 && bl <= 0) puts ("你没吃的了......");
                if (k == 3 && bl > 0) {
                    blood += 10;
                    bl -- ;
                    cout << s << "加10滴血" << endl;
                }
                if (k == 4) {
                    int tmp = rand () % 10;
                    if (tmp <= 4) {
                        cout << s << "逃跑了" << endl;
                        cout << "NPC" << "胜利" << endl;
                        money -= 10;
                        break;
                    }
                    else{
                        cout<<s<<"没能跑掉......"<<endl;
                    }
                }
                if (k == 5){
                    int miss = rand()%10;
                    int ex = rand()%10;
                    skillmianban(skilln);
                    if(skillnum==0){
                        puts(" ");
                    }
                    else{
                        int sf;
                        cin>>sf;
                        if(sf = 1){
                            if (s1=1){
                                if(energy<5){
                                    cout<<"能量不足!"<<endl; 
                                }
                                else{
                                    if(miss<=3){
                                    cout<<"NPC闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                    miss=rand()%10;
                                    }   
                                    else{
                                        if(ex<=3){ 
                                            blood1-=skillatk[skillnum]*2;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            blood1-=skillatk[skillnum];
                                            ex=rand()%10;
                                        }
                                        energy-=skillenergy[skillnum];
                                    }   
                                }
                            }
                            else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf=2){
                            if(s2=1){
                                if(energy<15){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                    cout<<"NPC闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                    miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){ 
                                            blood1-=skillatk[skillnum]*2;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            blood1-=skillatk[skillnum];
                                            ex=rand()%10;
                                        }
                                        energy-=skillenergy[skillnum];
                                    }   
                                }
                            }
                            else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf = 3){
                            if(s3=1){
                                if(energy<10){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                        cout<<"NPC闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                        miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){ 
                                            blood1-=skillatk[skillnum]*2;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            blood1-=skillatk[skillnum];
                                            ex=rand()%10;
                                        }
                                    energy-=skillenergy[skillnum];
                                    }   
                                }
                            }
                            else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf = 4){
                            if(s4=1){
                                if(energy<7){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                        cout<<"NPC闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                        miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){ 
                                            blood1-=skillatk[skillnum]*2;
                                            cout<<"NPC"<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<"NPC"<<skille[skillnum]<<endl;
                                            cout<<"因暴击增益,多减10000"<<endl;
                                            atk-=110000; 
                                            ex=rand()%10; 
                                        }
                                        else{
                                            cout<<"NPC"<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<"NPC"<<skille[skillnum]<<endl;
                                            atk1-=100000;
                                            ex=rand()%10;
                                        }
                                    energy-=skillenergy[skillnum];
                                    }   
                                }
                            }
                            else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf = 5){
                            if(s5=1){
                                if(energy<10){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                        cout<<"NPC闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                        miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){
                                            cout<<"NPC"<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<"NPC"<<skille[skillnum]<<endl;
                                            cout<<"因暴击增益,多减20000"; 
                                            atk1-=220000;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            cout<<"NPC"<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<"NPC"<<skille[skillnum]<<endl;
                                            atk1-=200000;
                                            ex=rand()%10;
                                        }
                                    energy-=skillenergy[skillnum];
                                    }   
                                }
                            }
                            else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                    }
                }
                if (blood1 <= 0) {
                    cout << s << "干掉了" << "NPC" << endl;
                    cout << s << "胜利" << endl;
                    money += rand () % 10;
                    experience +=rand()%10;
                    break;
                }
                int tmp2 = rand () % 10;
                if (tmp2 <= 4) {
                    blood -= (atk1 * 4);
                    cout << "NPC" << "使用攻击" << s << endl;
                    cout << s << "还剩" << blood << "血" << endl;
                }
                else {
                    blood -= atk1*2;
                    cout << "NPC使用破土攻击" << s << endl;
                    cout << s << "还剩" << blood << "血" << endl;
                }
                if (blood <= 0) {
                    cout << "NPC" << "干掉了" << s << endl;
                    cout << "NPC" << "胜利" << endl;
                    money -= 10;
                    killed = true;
                    break;
                }
                i ++ ;
            }
        }
        if (opt == '2') {
            puts ("欢迎来到末日机械商店!");
            puts ("攻击武器 : 1、石剑:100钻石 2、铁剑:500钻石 3、钻石剑:2000钻石 4、下界合金剑:5000钻石");
            puts ("防御装备 : 5、皮革套:300钻石 6、锁链套:5500钻石 7、铁套:8000钻石 8、钻石套:50000钻石 9、下界合金套:100000钻石"); 
            puts ("究极装备 : 9、无尽套 2000000 10、乱码套 3000000 11、五彩斑斓套 4000000 12、深渊套 5000000 13、氪金萝莉 50000000000000000欧元"); 
            puts ("技能 : 14、阴晦之气 500000 15、金锋之光 600000");
            puts ("输入0,离开商店");
            int op;
            cin >> op;
            if (op == 0) goto i;
            if (op == 1 && money >= 10) atk += 30 , money -= 10 , wep = 1;
            else if (money < 10) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 2 && money >= 50) atk += 500 , money -= 50 , wep = 2;
            else if (money < 50) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 3 && money >= 200) atk += 1000 , money -= 200 , wep = 3;
            else if (money < 200) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 4 && money >= 500) atk += 2000 , money -= 500 , wep = 4;
            else if (money < 500) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 5 && money >= 30) blood += 200 , money -= 30;
            else if (money < 30) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 6 && money >= 100) blood += 7000 , money -= 100;
            else if (money < 100) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 7 && money >= 500) blood += 10000 , money -= 500;
            else if (money < 500) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 8 && money >= 1000) blood += 30000 , money -= 1000;
            else if (money < 1000) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 9 && money >= 200000) atk += 20000 , money -= 200000 , wep = 6;
            else if (money < 200000) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 10 && money >= 300000) atk += 30000 , money -= 300000 , wep = 7;
            else if (money < 300000) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 11 && money >= 400000) atk += 40000 , money -= 400000 , wep = 8;
            else if (money < 400000) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 12 && money >= 500000) atk += 50000 , money -= 500000 , wep = 9;
            else if (money < 500000) {
                puts ("没钱!!!");
                goto i;
            }
            if (op == 13){
                puts("你氪不起......");
            }
            if (op == 14 && money >=50000) s4 = 1 , skillnum = 4 , money -= 50000;
            else if (money < 50000){
                puts ("没钱!!!");
                goto i;
            }

            if (op == 15 && money >= 60000) s5 = 1 , skillnum = 4 , money -= 60000;
            else if (money < 60000){
                puts ("没钱!!!");
                goto i;
            }
            puts ("已穿上装备");
        }
        if (opt == '3') {
            puts ("选择工作");
            puts ("1、清理 2分钟5钻石");
            puts ("2、撸树 2分钟20钻石");
            puts ("3、挖矿 2分钟50钻石");
            puts ("4、保卫村庄 2分钟70钻石");
            int y;
            cin >> y;
            if (y == 1 && experience >= 10) {
                puts ("输入工作时间");
                int times;
                cin >> times;
                cout << "工作中......" << endl;
                Sleep (times * 60000);
                money += (times / 2) * 20;
                experience+=(times/2)*2;
                cout << "你现在有:" << money << "钻石" << endl;
                cout<<"你的经验为:"<<experience<<endl;
                goto i;
            }
            else if (y == 1 && experience < 10) {
                puts ("资格不足");
                goto i;
            }
            if (y == 2 && money >= 20) {
                puts ("输入工作时间");
                int times;
                cin >> times;
                cout << "工作中......" << endl;
                Sleep (times * 60000);
                money += (times / 2) * 50;
                experience+=(times/2)*4;
                cout << "你现在有:" << money << "钻石" << endl;
                cout<<"你的经验为:"<<experience<<endl;
                goto i;
            }
            else if (y == 2 && experience < 20) {
                puts ("资格不足");
                goto i;
            }
            if (y == 3 && experience>= 50) {
                puts ("输入工作时间");
                int times;
                cin >> times;
                cout << "工作中......" << endl;
                Sleep (times * 60000);
                experience+=(times / 2)*6;
                money += (times / 2) * 5;
                cout << "你现在有:" << money << "钻石" << endl;
                cout << "你的经验为:"<<experience<<endl;
                goto i;
            }
            else if (y == 3 && experience < 50) {
                puts ("资格不足");
                goto i;
            }
            if (y == 4 && money >= 100) {
                puts ("输入工作时间");
                int times;
                cin >> times;
                cout << "工作中......" << endl;
                Sleep (times * 60000);
                experience+=(times / 2) * 8;
                money += (times / 2) * 70;
                cout << "你现在有:" << money << "钻石" << endl;
                cout << "你的经验为:" << experience << endl;
                goto i;
            }
            else if (y == 4 && experience < 100) {
                puts ("资格不足");
                goto i;
            }
        }
        if (opt == '4') {
            blood1*=20;
            atk1*=20;
            int miss = rand()%10;
            int energy = 0; 
            string boss = "凋零风暴"; 
            while (1) {
                cout << boss << "血量=" << blood1 << ". 攻击力=" << atk1 << endl;
                cout << "第" << i << "回合" << endl;
                cout<<"能量:"<<energy<<endl;
                cout << "请问" << s << "要干什么?" << endl;
                fightmainban ();
                int k;
                cin >> k;
                if (k == 1) {
                    int tmp = rand () % 10;
                    if (tmp < 4) {
                        blood1 -= (atk * 2);
                        cout << s << "使用附魔钻石剑刺击" << endl;
                        cout << boss << "还剩" << blood1 << "血" << endl;
                        energy += 6;
                    }
                    else{
                        blood1 -= atk;
                        cout << s << "使用" << weapon[wep] << "刺击" << boss << endl;
                        cout << boss << "还剩" << blood1 << "血" << endl;
                        energy += 4;
                    }
                }
                if(k == 2){
                    if(energy>=5){
                        if(miss>3){
                            blood1-=atk*3;
                            energy-=5;
                            cout<<s<<"使用"<<weapon[wep]<<"劈击"<<boss<<endl;
                            cout<<boss<<"还剩"<<blood1<<"血"<<endl;
                            cout<<s<<"的能量"<<"还剩"<<energy<<endl;
                            miss=rand()%10;
                        }else{
                            energy-=5;
                            cout<< boss << "闪避了"<<s<<"的攻击!!!"<<endl; 
                            cout<<s<<"的能量"<<"还剩"<<energy<<endl;
                            miss = rand()%10; 
                        }
                    }else{
                        cout<<"能量不足!"<<endl;
                    }
                }
                if (k == 3 && bl <= 0) puts ("你没吃的了......");
                if (k == 3 && bl > 0) {
                    blood += 10;
                    bl -- ;
                    cout << s << "加10滴血" << endl;
                }
                if (k == 4) {
                    int tmp = rand () % 10;
                    if (tmp <= 4) {
                        cout << s << "逃跑了" << endl;
                        cout << boss << "胜利" << endl;
                        money -= 10;
                        energy = 0;
                        break;
                    }else{
                        cout << s << "没能逃掉"<<endl;
                    }
                }
                if (k == 5){
                    int ex = rand()%10;
                    skillmianban(skilln);
                    if(skillnum==0){
                        puts(" ");
                    }
                    else{
                        int sf;
                        cin>>sf;
                        if(sf == 1){
                            if (s1==1){
                                if(sf==1&&energy<5){
                                    cout<<"能量不足!"<<endl; 
                                }
                                else{
                                    if(miss<=3){
                                    cout<<boss<<"闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                    miss=rand()%10;
                                    }   
                                    else{
                                        if(ex<=3){ 
                                            blood1-=skillatk[skillnum]*2;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            blood1-=skillatk[skillnum];
                                            ex=rand()%10;
                                        }
                                        energy-=skillenergy[skillnum];
                                    }   
                                }
                            }else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf==2){
                            if(s2==1){
                                if(sf==2&&energy<15){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                    cout<<boss<<"闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                    miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){ 
                                            blood1-=skillatk[skillnum]*2;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            blood1-=skillatk[skillnum];
                                            ex=rand()%10;
                                        }
                                        energy-=skillenergy[skillnum];
                                    }   
                                }
                            }else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf == 3){
                            if(s3==1){
                                if(sf==3&&energy<10){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                        cout<<boss<<"闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                        miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){ 
                                            blood1-=skillatk[skillnum]*2;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            blood1-=skillatk[skillnum];
                                            ex=rand()%10;
                                        }
                                    energy-=skillenergy[skillnum];
                                    }   
                                }
                            }else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf == 4){
                            if(s4==1){
                                if(sf==4&&energy<7){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                        cout<<boss<<"闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                        miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){
                                            cout<<boss<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<boss<<skille[skillnum]<<endl; 
                                            cout<<"因暴击增益,多减10000"<<endl;
                                            atk1-=110000;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            cout<<boss<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<boss<<skille[skillnum]<<endl;
                                            atk1-=100000;
                                            ex=rand()%10;
                                        }
                                    energy-=skillenergy[skillnum];
                                    }   
                                }
                            }else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                        if(sf == 5){
                            if(s5==1){
                                if(sf==5&&energy<8){
                                        cout<<"能量不足!"<<endl;
                                }
                                else{
                                    if(miss<=3){
                                        cout<<boss<<"闪避了"<<s<<"的"<<skillname[skillnum]<<"攻击"<<endl; 
                                        miss=rand()%10;
                                    }
                                    else{
                                        if(ex<=3){
                                            cout<<boss<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<boss<<skille[skillnum]<<endl;
                                            cout<<"因暴击增益,多减20000"<<endl;
                                            atk1 -= 220000;
                                            ex=rand()%10; 
                                        }
                                        else{
                                            cout<<boss<<"受到"<<s<<"的"<<skilleffect[skillnum]<<"效果"<<endl;
                                            cout<<boss<<skille[skillnum]<<endl; 
                                            atk1-=200000;
                                            ex=rand()%10;
                                        }
                                    energy-=skillenergy[skillnum];
                                    }   
                                }
                            }else{
                                cout<<"你没有这个技能!"<<endl;
                            }
                        }
                    }
                }
                if (blood1 <= 0) {
                    cout << s << "干掉了" << boss << endl;
                    cout << s << "胜利" << endl;
                    cout << "挑战已达成!"<<endl;
                    cout << "末日新生" <<endl;
                    return 0;
                }
                int tmp2 = rand () % 10;
                if (tmp2 <= 4) {
                    blood -= (atk1 * 12);
                    cout << boss << "使用显卡飘香攻击" << s << endl;
                    cout << s << "还剩" << blood << "血" << endl;
                }
                else if(tmp2 <= 6){
                    blood -= (atk1 * 6);
                    cout << boss << "使用卡死5分钟攻击" << s <<endl;
                    cout << s << "还剩" << blood << "血" << endl; 
                } 
                else {
                    blood -= atk1*3;
                    cout << boss<<"使用延迟1000000ms攻击" << s << endl;
                    cout << s << "还剩" << blood << "血" << endl;
                }
                if (blood <= 0) {
                    cout << boss << "干掉了" << s << endl;
                    cout << boss << "胜利" << endl;
                    money -= 100;
                    experience+=rand()%5;
                    killed = true;
                    break;
                }
                i ++ ;
            }
        }
        if (opt == '5'){
            page+=1;
            mianban(page);
        }
        if(opt=='6'){
            int g = rand()%50;
            puts ("奖项:1、技能:狂暴旋风 2、电光一闪 3、冰封千里");
            puts ("      5、钻石500 6、钻石1000 7、氪金萝莉 8、血量+10000 9、隐藏大奖");
            puts ("抽奖一次500钻石 按1抽奖");
            string yn;
            cin>>yn;
            if(yn == "1"){
                if(money<50){
                    cout<<"钻石不足!";
                }else{
                    money -= 50;
                    if(g<=5){
                        cout<<"获得技能:狂暴旋风!"<<endl;
                        skillnum = 1;
                        s1 = 1;
                    }
                    if(g>5&&g<=7){
                        cout<<"获得:氪金萝莉!运气爆棚!"<<endl;
                        wep = 10;
                        atk+=10000000; 
                    }
                    if(g>7&&g<=10){
                        cout<<"获得技能:雷霆万钧!运气可以!"<<endl;
                        skillnum = 2;
                        s2 = 1;
                    }
                    if(g>10&&g<=20){
                        cout<<"获得500钻石!"<<endl;
                        money+=500; 
                    }
                    if(g>20&&g<=24){
                        cout<<"获得技能:冰封千里!"<<endl;
                        skillnum = 3;
                        s3 = 1;
                    }
                    if(g>24&&g<=30){
                        cout<<"获得1000钻石!"<<endl;
                        money+=1000;
                    }
                    if(g>30&&g<=33){
                        cout<<"血量+10000!运气可以啊!"<<endl;
                        blood += 100000;
                    }
                    if(g>33&&g<=40||g>45&&g<=50){
                        cout<<"运气不佳......什么也没抽到......"<<endl;
                    }
                    if(g>40&&g<=45){
                        cout<<"隐藏大奖!!!炸弹!!!血量-5000!!!"<<endl;
                        blood-=5000;
                    }
                    goto i;
                }
            } 
        }
        if (opt == '7') {
            puts ("指令:1、coi_money (看自己有多少钱)");
            puts ("1(1)、coi_atk_and_blood (看boss血量、攻击力)");
            puts ("1(2)、coi_me (看自己目前攻击力、血量)");
            puts ("2、cut_blood (削弱boss3%血量,有20%的几率)");
            puts ("3、atk++ (加强攻击力,作者专用)");
            puts ("4、blood++ (加强血量)");
            puts ("5、cut_price (降价旅馆钱数,两次机会,有20%几率)");
            puts ("请输入指令:");
            string zl;
            cin >> zl;
            if (zl == "GAR:末日机械万岁!!!"){
                cout<<"指令输入成功!已开启内部指令模式!"<<endl;
                string GARzl,GARpassword;
                puts("1、money+++(自定义增加钻石)");
                puts("2、atk+++(自定义增加攻击力)");
                puts("3、blood+++(自定义增加血量)") ;
                puts("4、leave(离开游戏)");
                puts("5、top-ups(充值获得氪金萝莉(Tips:直接加攻击不就好了......))");
                puts("请输入内部指令:");
                cin>>GARzl;
                if(GARzl=="money+++"){
                    cout << "输入密码:"<<endl;
                    cin >> GARpassword;
                    if(GARpassword == "xuxinzhe666"){
                        cout<<"认证成功!!!"<<endl;
                        cout << "输入数目:"<<endl;
                        int GARm;
                        cin>>GARm;
                        money+=GARm;
                        puts("添加成功!!!");
                    }else{
                        puts("呵,不知道密码还想用");
                    }
                }
                if(GARzl=="leave"){
                    return 0;
                }
                if(GARzl=="blood+++"){
                    cout << "输入密码:"<<endl;
                    cin >> GARpassword;
                    if(GARpassword == "xuxinzhe666"){
                        cout<<"认证成功!!!"<<endl;
                        cout << "输入数目:"<<endl;
                        int GARm;
                        cin>>GARm;
                        blood+=GARm;
                        puts("添加成功!!!");
                    }else{
                        puts("呵,不知道密码还想用");
                    }
                }
                if(GARzl=="atk+++"){
                    cout << "输入密码:"<<endl;
                    cin >> GARpassword;
                    if(GARpassword == "xuxinzhe666"){
                        cout<<"认证成功!!!"<<endl;
                        cout << "输入数目:"<<endl;
                        int GARm;
                        cin>>GARm;
                        atk+=GARm;
                        puts("添加成功!!!");
                    }else{
                        puts("呵,不知道密码还想用");
                    }
                }
                if(GARzl=="top-ups"){
                    cout << "输入密码:"<<endl;
                    cin >> GARpassword;
                    if(GARpassword == "xuxinzhe666"){
                        cout<<"认证成功!!!"<<endl;
                        wep = 10;
                        atk+=100000000;
                        money = 0; 
                        cout<<"已获得氪金萝莉"<<endl; 
                    }else{
                        puts("呵,不知道密码还想用");
                    }
                }
            }
            if (zl == "coi_money") {
                cout << "money:" << money << endl;
                goto i;
            }
            if (zl == "coi_atk_and_blood") {
                cout << "攻击力:" << atk1 << " 防御力:" << blood1 << endl;
                goto i;
            }
            if (zl == "coi_me") {
                cout << "攻击力:" << atk << " 防御力:" << blood << endl;
                goto i;
            }
            if (zl == "cut_blood" && chance <= 0) {
                puts ("你是不是以为这是无限次数的?");
                goto i;
            }
            if (zl == "cut_blood" && chance > 0) {
                int ran = rand ();
                if (ran % 5 == 0) {
                    atk1 *= 0.97; 
                    blood1 *= 0.97;
                    cout << "目前boss攻击力:" << atk1 << "血量:" << blood1 << endl;
                    chance -- ;
                    goto i;
                }
                else {
                    puts ("真不走运......");
                    goto i;
                }
            }
            if (zl == "atk++" && s == "GARS" || zl == "atk++" && s == "xxz") {
                string password;
                puts("请输入密码:");
                cin>>password;
                if(password=="xuxinzhe666"){
                    puts("认证成功!");
                    atk += 1000;
                    blood += 10000;
                }else{
                    puts("你不是作者!!!!!!"); 
                } 

                cout << "现在血量:" << atk << " 防御力:" << blood << endl;
                goto i;
            }
            else if (zl == "atk++" && s != "GARS" || zl == "atk++" && s != "GARS") {
                puts ("你不是作者!!!!!!");
                goto i;
            }
            if (zl == "blood++" && bloodchance <= 0) {
                puts ("你是不是以为这是无限次数的?");
                goto i;
            }
            if (zl == "blood++" && bloodchance > 0) {
                blood += 900;
                cout << "现在血量:" << blood;
                bloodchance -- ;
                goto i;
            }
            if (zl == "cut_price" && pricechange <= 0) {
                puts ("你是不是以为这是无限次数的?");
                goto i;
            }
            if (zl == "cut_price" && pricechange > 0) {
                int price = rand () % 10;
                if (price <= 4) {
                    hotal *= 0.8;
                    cout << "现在钱数:" << hotal << endl;
                    pricechange -- ;
                    goto i;
                }
                else {
                    puts ("真不走运......");
                    goto i;
                }
            }
        }
        if (opt == '8') {
            puts ("欢迎来到村庄!");
            puts ("住宿一次500钻石,血量+5000");
            puts ("修炼一次500钻石,攻击力+5000");
            puts ("住店输入1,修炼输入2");
            int o;
            cin >> o;
            if (o == 1 && money >= 500) {
                puts ("好好睡吧......");
                blood += 5000;
                money -= 500;
                Sleep (3000);
                puts ("第二天了");
                goto i;
            }
            else if (o == 1 && money < 500) {
                puts ("你似乎没钱呢?");
                goto i;
            }
            else {
                puts ("下次再来!!!!");
                goto i;
            }
            if (o == 2 && money >= 500) {
                puts ("嘿!呼!呀!");
                atk += 5000;
                money -= 500;
                Sleep (3000);
                puts ("一天过去了......");
                goto i;
            }
            else if (o == 2 && money < 500) {
                puts ("你似乎没钱呢?");
                goto i;
            }
            else {
                puts ("下次再来!!!!");
                goto i;
            } 
        }
    }
    return 0;
} 

heads.h头文件:

#pragma once
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
using namespace std;

io.h头文件:

#include "heads.h"
int toint(char ch)
{
    if(ch>='0'&&ch<='9')
        return ch-'0';
    return ch-'A'+10;
}
int stoint(string str)
{
    int ans=0;
    for(int i=0;i<str.size();i++)
        ans=ans*16+toint(str[i]);
    return ans;
}
void print(string a,WORD color,int x,int y,int wait)
{   
    WORD colorOld;
    HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(handle, &csbi);
    colorOld = csbi.wAttributes;
    if(x>=0&&y>=0)
    {
        COORD pos={x,y};
        SetConsoleCursorPosition(handle,pos);
    }
    SetConsoleTextAttribute(handle, color);
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='<')
        {
            i++;
            char model=a[i];
            i++;
            if(model=='T')
            {
                char ch1=a[i];
                i++;
                char ch2=a[i];
                string b="";
                int c=1; 
                do{
                    i++;
                    if(a[i]=='<')
                        c++;
                    if(a[i]=='>')
                        c--;
                    if(a[i]=='&')
                    {
                        b+=a[i];
                        i++;
                    }
                    b+=a[i];
                }while(c!=0);
                b.erase(b.size()-1,1);
                WORD adder;
                adder=toint(ch1)*16+toint(ch2);
                print(b,adder,-1,-1,wait);
                continue;   
            }
        }
        else
        {
            if(a[i]=='&')
                i++;
            printf("%c",a[i]);
        }
        Sleep(wait);
    }
    SetConsoleTextAttribute(handle, colorOld);
}
string getstr(int lenth)
{
    char ch;
    string input="";
    while(ch=getchar(),ch!='\n'&&input.size()<lenth)
        input+=ch;
    return input;
}