自制c++游戏《封神演义》(不是博主,莫关注)

· · 个人记录

c++游戏《封神演义》(纯自制) 代码随便拿!

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
string di[5]= {"孔宣","胡雷","徐芳","余化龙","通天教主"};
int num=0,money=0,attack,hp=100,your_hp=100,your_attack=17,n,b=0,a=0,c=0,d=0;
char input;
string tu[7]= {"                    *","           &^&     *","          / o |    *","          ^//  }==*","//    }","          # //\\\\","          //  \\\\"};
string tu_attack[7]= {"                      ","           &^&","          / o |","********==^//  }","//    }","          # //\\\\","          //  \\\\"};
string tu_dodge[7]= {"","","","","","",""};
string hu[7]= {"             _","            / \\/^\\","             \\\'/","            //#==","    # \\\\","              l //","           _//"};
string hu_attack[7]= {"             _","            / \\/^\\","             \\\'/","()       ===//#==","    # \\\\","              l //","           _//"};
string hu_dodge[7]= {"             _","            / \\/^\\","             \\\'/","      --0===//#==","    # \\\\","              l //","           _//"};
string tu_a="镔铁棍",tu_d="遁地术",hu_a="扔石头",hu_d="化为乌有";
string me[7],me_attack[7],me_dodge[7],me_a,me_d;
string you[7]= {"     / \\        ","     \\^/-       ","    //^\\\\      ","   //| |\\\\     ","   # | | #----->         ","    //^^\\\\     ","   //    \\\\     "};
string you_attack[7]= {"     / \\        ","     \\^/-       ","    //^\\\\      ","   //| |\\\\     ","   # | | \\\\=======#----->","    //^^\\\\     ","   //    \\\\     "};
void Ried() {
    printf("请选择角色:\n\t1.土行孙\t2.龙须虎");
    input=getch();
    if (input=='1') {
        me_a=tu_a;
        me_d=tu_d;
        for (int i=0; i<7; i++) {
            me[i]=tu[i];
            me_attack[i]=tu_attack[i];
            me_dodge[i]=tu_dodge[i];
        }
        srand(time(0));
        attack=rand()%6+15+a;
    } else if (input=='2') {
        me_a=hu_a;
        me_d=hu_d;
        for (int i=0; i<7; i++) {
            me[i]=hu[i];
            me_attack[i]=hu_attack[i];
            me_dodge[i]=hu_dodge[i];
        }
        srand(time(0));
        attack=rand()%11+15+a;
    }
    hp=100;
    your_hp=100;
    while (your_hp>0 && hp>0) {
        system("cls");
        cout<<"     "<<your_hp<<"\t\t\t  "<<hp<<endl;
        for (int i=0; i<7; i++) {
            cout<<you[i]<<me[i]<<"\n";
        }
        cout<<"____________________________________\n     "<<di[num]<<"\t\t   你\n";
        cout<<"\t\t请选择\n\t\t  1."<<me_a<<"\n\t\t  2."<<me_d<<"\n";
        if (d>0) {
            cout<<"\t\t  3.炸弹\n";
        }
        input=getch();
        system("cls");
        cout<<"     "<<your_hp<<"\t\t\t  "<<hp<<endl;
        if (input=='1') {
            for (int i=0; i<7; i++) {
                cout<<you[i]<<me_attack[i]<<"\n";
            }
            cout<<"____________________________________\n";
            Sleep(2000);
            your_hp-=attack;
            hp-=1;
        } else if(input=='3' and d>0 and num!=4) {
            d-=1;
            your_hp=0;
            printf("\t\t砰!\n");
        } else {
            for (int i=0; i<7; i++) {
                cout<<you[i]<<me_dodge[i]<<"\n";
            }
            cout<<"____________________________________\n";
            Sleep(2000);
            hp+=2+b;
            continue;
        }
        system("cls");
        cout<<"     "<<your_hp<<"\t\t\t  "<<hp<<endl;
        for (int i=0; i<7; i++) {
            cout<<you_attack[i]<<me[i]<<"\n";
        }
        cout<<"____________________________________\n";
        Sleep(2000);
        hp-=your_attack;
        your_hp-=1;
        if (c>0) {
            printf("\t我方使用道具酒杯加血!\n");
        }
        Sleep(1000);
        hp+=c;
    }
    if (your_hp>0) {
        printf("你输了!");
    } else {
        printf("你赢了!");
        num+=1;
        money+=attack;
    }
}
void Show() {
    printf("\n\t\t\t\t\t\t周武王东征路线\n");
    Sleep(1000);
    printf("西岐");
    printf("———————");
    Sleep(1000);
    for (int i=1; i<=5; i++) {
        if (i<=num) {
            printf("●");
        } else {
            printf("0");
        }
        printf("———————");
        Sleep(1000);
    }
    printf("朝歌\n");
    Sleep(1000);
    printf("你还有%i关没闯过!",(5-num));
    Sleep(2000);
}
int main() {
    printf("\n\t\t\t\t\t   封神演义之东征长途");
    Sleep(1000);
    system("cls");
    system("color F0");
    while (num<5) {
        Show();
        system("cls");
        printf("\n请选择:\n\t1.攻占关口\t2.商店\t3.查看我方人物\t4.查看敌人\n");
        input=getch();
        if (input=='1') {
            Ried();
        } else if (input=='2') {
            if (money<=10) printf("没钱,打出去!");
            else {
                printf("你要买什么?\n");
                printf("|---1---|---2---|---3---|---4---|\n");
                printf("| A  火 | 1 紫金|l##l 酒|     炸|\n");
                printf("| | 尖枪| 0 葫芦|l##l 杯| S*  弹|\n");
                printf("| | 10元|(_)10元| ||40元|() 40元|\n");
                printf("|-------|-------|-------|-------|\n");
                input=getch();
                if (input=='1') {
                    if (money<10) {
                        printf("钱不够,打出去!");
                    } else {
                        printf("购买成功,攻击增加!");
                        money-=10;
                        a+=2;

                    }
                } else if (input=='2') {
                    if (money<10) {
                        printf("钱不够,打出去!");
                    } else {
                        printf("购买成功,回血量增加!");
                        money-=10;
                        b+=2;
                    }
                } else if (input=='3') {
                    if (money<40) {
                        printf("钱不够,打出去!");
                    } else {
                        printf("购买成功,每回合可回血10滴!");
                        money-=40;
                        c=10;
                    }
                } else if (input=='4') {
                    if (money<40) {
                        printf("钱不够,打出去!");
                    } else {
                        printf("购买成功,炸弹可以毁灭对手(BOSS关无效)!");
                        money-=40;
                        d+=1;
                    }
                }
            }
        } else if (input=='3') {
            system("cls");
            printf("1.\n土行孙:玉虚宫元始天尊门下,惧留孙的弟子,其妻成汤大将邓九公之女邓蝉玉。土行孙身\n材矮小,本领高强,以遁地术称雄诸神。每到紧急时刻,他总能出人意料地遁地而行,令\n人拍案叫绝。擅长遁地术,可日行千里,捆仙绳力克天下英雄。本为商汤先锋将军,后投西\n歧。最后死于猛兽崖张奎(张奎可日行一千五百里,故提前赶到猛兽崖)之手。封神后,封为\n土府星。\n按任意键继续");
            _getch();
            system("cls");
            printf("2.\n龙须虎:玉虚宫元始天尊门下,姜子牙的弟子,是一只既有点像虎又有点像龙的灵物,体型\n硕大,出手有石。少昊时出生,修炼千载,伐纣的过程中徒建奇功与帝家。但是最后被巨人\n邬文化所杀,封神后封为九丑星。\n按任意键继续");
            _getch();
            system("cls");
            printf("2秒后回到主界面。。。");
        } else if (input=='4') {
            system("cls");
            printf("第一关:三山关——孔宣\n孔宣担任元帅时,将周军阻于三山关金鸡岭,用绝招五色神光屡胜众多阐教仙人和大将,专用此术擒敌拿人,其神光分为\n:青、黄、赤、黑、白五色,五色神光号称无物不收,一旦放出,见人就收。\n【按任意键继续】");
            _getch();
            system("cls");
            printf("第二关:佳梦关——胡雷\n胡雷是殷商佳梦关守将,胡升之弟,截教内门三代火灵圣母的弟子,有替身法,被南宫适生擒斩首之后再度重生逃脱\n【按任意键继续】");
            _getch();
            system("cls");
            printf("第三关:穿云关——徐芳\n徐芳是穿云关主将,亦是界牌关主将徐盖的弟弟,武艺高强,但不懂法术。\n【按任意键继续】");
            _getch();
            system("cls");
            printf("第四关:潼关——余化龙\n余化龙是殷商潼关兵马元帅,长子余达、次子余兆、三子余光、四子余先、五子余德。曾在周营撒下毒痘,致使周营六十\n万人马患上痘毒。\n【按任意键继续】");
            _getch();
            system("cls");
            printf("第五关:界牌关——通天教主\n通天教主偏信了弟子多宝道人和金灵圣母的一面之辞,竟发圣人之怒,决意与阐教作对,连设“诛仙阵”与“万仙\n阵”两大恶阵,令无数生灵涂炭,神仙遭殃。\n【按任意键继续】");
            _getch();
            system("cls");
            printf("2秒后回到主界面。。。");
        } else printf("不识字就直说!!");
        Sleep(2000);
        system("cls");
    }
    printf("你攻入朝歌了!");
    Sleep(1000);
    exit(0);
}