Self-compiled C ++ game

background

Boring weekend, then made up a cmd similar gadgets.
But it grew more and more wrong, so turning it into a game.

information

Language: DEV_C ++
source code has been released! !

Beat GG


Version: 1.0 (full version)


Version: 1.5 (special episode)


The latest version: 2.0 (Hero Edition)
source code:

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <ctime>
#define srandom srand((int)time(0))
#define random(a,b) (rand()%(b-a+1)+a)
#define cl system("cls")
using namespace std;
int x=1000,y=10,apks,doks,opinfs,bigets,comes,gos,japk;
int deapks,dedoks,deopinfs,debigets,decomes,degos;
int dokbuff;
int apklow;
int agas;
int guts;
int bag[10];
int gx=2000;
bool shopbl=0;
int wearthing[10]={0,100,170,210,190,220};
int hurtggb;
int playper;
int pero;
float pert;
int perttime;
int pere;
int peretime;
int perf;
int perftime;
int perfapk;
int perfall;
void start()
{
    char ch='0';
    while(ch!='1')
    {
        cl;
        cout<<"1.开始 2.退出 3.了解背景&操作 4.关于";
        while(!kbhit())
        {
        
        }
        ch = getch();
        if(ch == '2')
            exit(0);
        if(ch == '3')
        {
            cl;
            cout<<"你被选定为FG勇士\n打败FG怪兽——GG获得胜利!"<<endl<<endl;
            cout<<"input:a---普攻"<<endl;
            cout<<"input:d---防御"<<endl;
            cout<<"input:o---恢复"<<endl;
            cout<<"input:s---商店"<<endl;
            cout<<"input:f---状态"<<endl;
            cout<<"input:b---杀招"<<endl;
            cout<<"input:c---召唤"<<endl;
            cout<<"input:g---回避"<<endl;
            cout<<"input:r---减CD"<<endl;
            cout<<"你会在GG的攻击下血量减少,尽快干掉他!\n 'Z'键返回";
            while(!kbhit())
            {
            }
        }
        if(ch=='4')
        {
            MessageBox(NULL,"本程序最终解释权归 GG 所有\n\n              版本号1.95","关于",MB_OK);
        }
    }
    cout<<endl<<"开始";
    Sleep(500);
    system("cls");
}
int choose(int yx)
{
    cl;
    char yxc;
    if(yx == 1)
    {
        cout<<"青龙"<<endl<<endl;
        cout<<"技能:[青龙怒吼] -------- 触发暴击效果,造成原有3倍伤害。    CD:30"<<endl<<endl;
        cout<<"-------------------\nTAB 切换英雄";
    }
    if(yx == 2)
    {
        cout<<"白虎"<<endl<<endl;
        cout<<"技能:[大灵魂术] -------- 心魔防御,受到伤害将变为原有伤害的20%,提高自身攻击30(累加),持续7回合。    CD:13"<<endl<<endl;
        cout<<"-------------------\nTAB 切换英雄";
    }
    if(yx == 3)
    {
        cout<<"朱雀"<<endl<<endl;
        cout<<"技能:[朱雀圣火] -------- 灼伤GG,每回合扣除GG生命值的20%,持续3回合。    CD:12"<<endl<<endl;
        cout<<"-------------------\nTAB 切换英雄";
    }
    if(yx == 4)
    {
        cout<<"玄武"<<endl<<endl;
        cout<<"技能:[龟图大显] -------- 吸收伤害,每次释放吸收伤害的200%,单次最多吸收7回合,一共至多吸收950点伤害,再次按下C释放伤害。    CD:19"<<endl<<endl;
        cout<<"-------------------\nTAB 切换英雄";
    }
    while(!kbhit())
    {
        
    }
    yxc = getch();
    if(int(yxc)==9)
    {
        yx++;
        if(yx>4)
            yx=1;
        choose(yx);
    }
    else if(int(yxc)==13)
    {
        cl;
        return yx;
    }
    else
    {
        choose(yx);
    }
}
void rewe()
{
    if(apks!=0)apks--;
    if(doks!=0)doks--;
    if(opinfs!=0)opinfs--;
    if(bigets!=0)bigets--;
    if(comes!=0)comes--;
    if(gos!=0)gos--;
}
void help()
{
    cout<<"input:a---普攻"<<endl;
    cout<<"input:d---防御"<<endl;
    cout<<"input:o---恢复"<<endl;
    cout<<"input:s---商店"<<endl;
    cout<<"input:f---状态"<<endl;
    cout<<"input:b---杀招"<<endl;
    cout<<"input:c---召唤"<<endl;
    cout<<"input:g---回避"<<endl;
    cout<<"input:r---减CD"<<endl;
    cout<<"你会在GG的攻击下血量减少,尽快干掉他!";
    rewe();
    return;
}
void apk()
{
    if(apks>0)
    {
        cout<<"You can't do it"<<endl;
        rewe();
        return;
    }
    srandom;
    int ap = random(japk + 90 + apklow, japk + 190);
    cout<<"You hurt gg "<<ap<<" hurtnumber"<<endl;
    gx -= ap;
    hurtggb += ap;
    rewe();
    apks = 5 + deapks;
    return;
}
void self()
{
    cout<<"攻击冷却 "<<apks<<endl;
    cout<<"防御冷却 "<<doks<<endl;
    cout<<"恢复冷却 "<<opinfs<<endl;
    cout<<"大招冷却 "<<bigets<<endl;
    cout<<"召唤冷却 "<<comes<<endl;
    cout<<"躲避冷却 "<<gos<<endl;
    cout<<"武器增益 "<<japk<<endl;
    cout<<"gg的生命 "<<gx<<endl;
    cout<<"gut保命 "<<guts<<endl;
    cout<<"aga复活 "<<agas<<endl;
    rewe();
    return;
}
void biget()
{
    if(bigets > 0 || y < 100)
    {
        cout<<"You can't do it";
        rewe();
        return;
    }
    srandom;
    int ap = random(japk + 100 + apklow, japk + 200);
    ap*=2;
    cout<<"You hurt gg "<<ap<<" hurtnumber"<<endl;
    gx -= ap;
    hurtggb += ap;
    rewe();
    bigets = 10 + debigets;
    y -= 100;
}
void wear(int a)
{
    if(a==1) japk+=10;
    if(a==2) japk+=5,guts+=3;
    if(a==3) agas+=1;
    if(a==4) apklow+=20;
    if(a==5)
    {
        deapks-=2;dedoks-=2;deopinfs-=2;debigets-=2;decomes-=2;degos-=2;
    }
    
}
char shop()
{
    rewe();
    cout<<"|1.wug     |--|攻击+10                |--|100经验     |"<<endl;
    cout<<"|2.gut     |--|攻击+05,抵挡3次致命伤害|--|170经验     |"<<endl;
    cout<<"|3.aga     |--|复活(700生命)          |--|210经验     |"<<endl;
    cout<<"|4.qaq     |--|攻击伤害下限提高10     |--|190经验     |"<<endl;
    cout<<"|5.pid     |--|全体技能CD减少2        |--|220经验     |"<<endl;
    cout<<"|按编号购买                                           |"<<endl;
    shopping_again:
    while(!kbhit())
    {
    }
    char chi;
    int a;
    chi=getch();
    if(chi>='0' && chi<='9')
    {
        a=chi-'0';
        if(wearthing[a]>y)
        {
            cout<<"You can't do it"<<endl;
            rewe();
            goto shopping_again;
        }
        y-=wearthing[a];
        bag[a]+=1;wear(a);/*----穿上----*/
        goto shopping_again;
    }
    else
        return chi;
    /*----购买----*/
}
void dok()
{
    if(doks>0)
    {
        cout<<"You can't do it"<<endl;
        rewe();
        return;     
    }
    dokbuff+=3;
    rewe();
    doks=7+dedoks;
    /*----防御----*/
}
void opinf()
{
    if(opinfs>0)
    {
        cout<<"You can't do it"<<endl;
        rewe();
        return;     
    }
    x+=5;
    rewe();
    opinfs=2+deopinfs;
    /*----恢复----*/
}
bool going=false;
int gotime;
void go()
{
    if(gos>0)
    {
        cout<<"You can't do it"<<endl;
        rewe();
        return;     
    }
    going=true;
    gotime=7;
    rewe();
    gos=19+degos;
    /*----回避功能----*/
}
void come(int yx)
{
    if(yx == 1)
    {
        if(comes > 0)
        {
            cout<<"You can't do it";
            rewe();
            return;
        }
        srandom;
        int ap = random(japk + 100 + apklow, japk + 200);
        ap*=3;
        cout<<"Take it!!!"<<endl;
        cout<<"You hurt gg "<<ap<<" hurtnumber"<<endl;
        gx -= ap;
        hurtggb += ap;
        rewe();
        comes = 30 + decomes;
    }
    if(yx == 2)
    {
        if(comes > 0)
        {
            cout<<"You can't do it";
            rewe();
            return;
        }
        cout<<"My dream will come true!!!"<<endl;
        pert = 0.2;
        japk += 30;
        perttime += 7;
        comes = 13 + decomes;
    }
    if(yx == 3)
    {
        if(comes > 0)
        {
            cout<<"You can't do it";
            rewe();
            return;
        }
        cout<<"Fire!!!"<<endl;
        pere=1;
        peretime=3;
        comes = 12 + decomes;
    }
    if(yx == 4)
    {
        if(comes > 0 && perf==0)
        {
            cout<<"You can't do it";
            rewe();
            return;
        }
        if(perfall>950)
        {
            cout<<"I am old.Sorry,I can't do it..."<<endl;
            return;
        }
        if(perf==1)
        {
            cout<<"Kill it!"<<endl;
            perfapk*=2;
            gx-=perfapk;
            perfapk/=2;
            perfall+=perfapk;
            perf=0;
            perftime=0;
            perfapk=0;
            return;
        }
        else
        {
            cout<<"Let me ..."<<endl;
            perf=1;
            perftime=7;
            comes = 9 + decomes;
        }
    }
}
int main()
{
    start();
    playper=choose(1);
    char ch;
    while(1)
    {
        /*----开始----*/
        if(pere==1)
        {
            gx=floor(gx*0.8);
        }
        if(peretime>0)
            peretime--;
        if(peretime==0)
            pere=0;
        /*----判断是否在朱雀圣火效果内----*/
        if(perttime==0)
        {
            pert=1;
        }
        if(perttime>0)
        {
            perttime--;
        }
        /*----判断是否在大灵魂术效果内----*/
        main:
        int ap;
        if(gotime>0)
        {
            gotime--;
            goto goead;
        }
        else if(gotime==0)
            going=false;
        /*----判断是否回避----*/  
        srandom;
        ap = random(20,40);
        if(dokbuff>0)
        {
            dokbuff--;
            ap=floor(ap*0.5);
        }
        ap=floor(ap*pert);
        /*----判断是否防御----*/
        if(perftime>0)
        {
            perfapk+=ap;
            ap=0;
            perftime--;
        }
        /*----判断是否龟图----*/
        goead:
        cout<<"(Press 'h' to get the help)"<<endl;
        if(going==false)
            cout<<"gg hurt you "<<ap<<" hurtnumber"<<endl<<endl,x -= ap;
        else
            cout<<"gg don't hurt you because you go"<<endl<<endl;   
        cout<<"Your Blood:"<<x<<endl;
        cout<<"Your XP:"<<y<<endl;
        cout<<"GG's Blood:"<<gx<<endl;
        /*----回合基本操作----*/
        if(x<0)
        {
            if(guts>0)/*----用gut----*/
            {
                guts--;
                x+=ap;
                cout<<"You use the gut"<<endl;
                goto next1;
            }
            if(agas>0)/*----用aga----*/
            {
                agas--;
                x=700;
                cout<<"You use the aga"<<endl;
                goto next1;
            }
            cl;
            cout<<"分数:"<<hurtggb<<endl<<endl;
            cout<<"gg kill you!"<<endl;
            cout<<"Your Blood:"<<x<<endl;
            cout<<"Your XP:"<<y<<endl;
            self();
            system("pause");
            system("pause");
            system("pause");
            system("pause");
            system("pause");
            return 0;   
        }
        /*----判断是否die----*/
        next1:
        if(gx<0)
        {
            cl;
            cout<<"分数:"<<hurtggb*x<<endl<<endl;
            cout<<"you kill gg!"<<endl;
            cout<<"Your Blood:"<<x<<endl;
            cout<<"Your XP:"<<y<<endl;
            self();
            system("pause");
            system("pause");
            system("pause");
            system("pause");
            system("pause");
            return 0;
        }
        /*----判断是否kill GG---*/
        y+=10;
        if(shopbl==true)/*----判断上一次是否为shop----*/
        {
            shopbl=false;
            goto jumptocase;
        }
        ch=getch();
        jumptocase:
        cout<<"----------------------------"<<endl;
        if(ch=='h')
            help();
        if(ch=='a')
            apk();
        if(ch=='r')
            cout<<"Rewe!"<<endl, rewe();
        if(ch=='f')
            self();
        if(ch=='b')
            biget();
        if(ch=='s')
        {
            ch = shop();
            if(ch<'0' || ch>'9')
            {
                shopbl=true;
                cl;
                goto main;
            }
        }
        if(ch=='d')
        {
            dok();
        }
        if(ch=='o')
        {
            opinf();
        }
        if(ch=='g')
        {
            go();
        }
        if(ch=='c')
        {
            come(playper);
        }
        /*----读入----*/
        while(!kbhit())
        {
        }
        cl;
    }
}

Welcome demo

Guess you like

Origin www.cnblogs.com/Areds/p/12114784.html