哈利波特魔法游戏(原创)

背景

最近自学动态规划和图论,真的难,所以想放松一下,用了3天的时间自己手敲,编了一个哈利波特的游戏(因为我是哈迷)。目前功能尚未完善,后续更新。

简单的介绍

后期会增加提升等级和颜色变换的功能,敬请期待。当然啦,如果您有什么好的建议,可以私信我哦!

代码部分

#include
#include
#include
#include
using namespace std;
const int N=1e6+10;
struct id
{
    bool flag;
    string name;
    string password;
    int attack;
    int defense;
    int life;
    int big_life;
    int level;
    int experience;
    string wand;
    int coin;
    string bag[N];
    int bag_len;
    int speed;
    int usual_attack[15]={10,10,20,80,30,50,15,30,10,60,60,120,50};
    int kill_attack[5]={1,1,1};
    int jinkuid;
    string jinkupass; 
};
struct gu
{
    int coin;
    int experience;
    bool flag;
    string password;
};
mapuser;
mapjinku;
int jinku_id;
string d_user;
string monster[10]={"地精","巨人","博格特","摄魂怪","巨型蜘蛛","龙","蛇怪"};
int monster_attack[10]={8,15,20,30,50,100,500};
string spell_usual[15]={"昏昏倒地","腿立僵停死","统统石化","除你武器","火焰熊熊","四分五裂","力松劲泄","粉身碎骨","障碍重重","速速禁锢","万弹齐发","神锋无影","霹雳爆炸"};
string spell_kill[5]={"阿瓦达索命","钻心剜骨","魂魄出窍"};
void init_slow_out(string s,int x)
{
    for(int i=0;i>_name>>_pass;
        freopen("CON","r",stdin);
        cin.clear();
        if(name==_name&&pass==_pass)
        {
            d_user=name;
            user[d_user].flag=true;
            string we="登入成功!欢迎,巫师"+name+"!";
            init_slow_out(we,50);
            int num;
            string cum;
            freopen("C:\\game.txt","r",stdin);
            cin>>cum;
            user[d_user].name=cum;
            cin>>cum;
            user[d_user].password=cum;
            for(int i=1;i<=8;i++)
            {
                cin>>num;
                trad(i,num);
            }
            cin>>cum;
            user[d_user].wand=cum;
            cin>>num;
            user[d_user].bag_len=num;
            for(int i=1;i<=num;i++)
            {
                cin>>cum;
                user[d_user].bag[i]=cum;
            }
            cin>>num;
            user[d_user].jinkuid=num;
            jinku[num].flag=true;
            cin>>cum;
            jinku[num].password=cum;
            freopen("CON","r",stdin);
            cin.clear();
            cout.clear();
            return true;
        }
        else
        {
            init_slow_out("用户名或密码输入错误!",50);
            return false;
        }
}
void sign_out()
{
    freopen("C:\\game.txt","w",stdout);
    cout<>cz;
        if(cz==1)
        {
            string name;
            cout<>name;
            input_password:
                string pass;
                cout<>pass;
                bool f=sign_in(name,pass);
                if(f)return;
                goto want_to_do;
        }
        else if(cz==2)
        {
            string wname,wpass;
            cout<>wname;
            cout<>wpass;
            user[wname].name=wname;
            user[wname].flag=true;
            user[wname].password=wpass;
            user[wname].attack=10;
            user[wname].defense=5;
            user[wname].life=100;
            user[wname].big_life=100;
            user[wname].level=1;
            user[wname].experience=10;
            user[wname].wand="普通魔杖";
            user[wname].coin=1000;
            user[wname].bag_len=0;
            user[wname].speed=0;
            user[wname].jinkuid=rand()%99999+1;
            user[wname].jinkupass="123";
            freopen("C:\\game.txt","w",stdout);
            cout<=0&&k-1<=2)monlife=rand()%100+50;
    else if(k-1>=3&&k-1<=4)monlife=rand()%300+100;
    else if(k-1>=5&&k-1<=6)monlife=rand()%500+300;
    else monlife=rand()%1000+500;
    cout<0&&youlife>0)
    {
        int ws=rand()%14;
        int gj=rand()%10+1;
        cout<>choose_what;
            if(choose_what==0)return;
            if(choose_what==1&&user[d_user].life>0)
            {
                cout<>choose_monster;
                    if(!(choose_monster>=1&&choose_monster<=7))
                    {
                        init_slow_out("输入错误!重新选择:",50);
                        goto choose_monster_again;
                    }
                    else
                    {
                        hit(choose_monster);
                        goto hithit;
                    }
            }
            else if(choose_what==2&&user[d_user].life>0)
            {
                hit(rand()%7+0);
                goto hithit;
            }
            else if(user[d_user].life<=0)
            {
                cout<>cheat;
        if(cheat=='y')
        {
            if(user[d_user].coin<1000&&user[d_user].experience<10)
            {
                cout<=1000)
            {
                user[d_user].life+=100;
                if(user[d_user].life>user[d_user].big_life)
                    user[d_user].life=user[d_user].big_life;
                user[d_user].coin-=1000;
                cout<user[d_user].big_life)
                    user[d_user].life=user[d_user].big_life;
                user[d_user].experience-=10;
                cout<>chwa;
        if(chwa==1)
        {
            if(user[d_user].coin>chbuwa;
        if(chbuwa==0)return;
        else if(chbuwa>=1&&chbuwa<=8){buy_wand_YES(chbuwa);return;}
        else cout<>chpabo;
        if(chpabo!=1&&chpabo!=2)
        {
            cout<>chbubo;
            if(chbubo==0)return;
            if(!(chbubo>=1&&chbubo<=6))
            {
                init_slow_out("输入错误!请重新输入:",50);
                goto choose_buy_book;
            }
            else buy_sthbook(chbubo);return;
}
void jinku_do(int id)
{
    system("cls");
    cout<>td;
        if(td==0)return;
        if(!(td>=1&&td<=4))
        {
            cout<>a;
                if(user[d_user].coin>a;
                if(jinku[id].coin>a;
                if(user[d_user].experience>a;
                if(jinku[id].experience>j;
            if(user[d_user].experience>j;
            if(user[d_user].coin>id;
            cout<>mima;
                if(jinku[id].flag==false)
                {
                    cout<>a;
            if(a!=1&&a!=2)
            {
                cout<>idd;
            cout<>mimaa;
                if(jinku[idd].flag==false)
                {
                    cout<>iid;
            cout<>mmima;
                if(jinku[iid].flag==false)
                {
                    cout<>iD;
            init_slow_out("请输入您的金库密码:",50);
            string Mima;
            cin>>Mima;
            if(iD==user[d_user].jinkuid&&Mima==jinku[iD].password)
            {
                cout<>nMima;
                jinku[iD].password=nMima;
                cout<>chgudo;
        if(chgudo==0)return;
        if(!(chgudo>=1&&chgudo<=5))
        {
            cout<>choose_buy;
            if(choose_buy==0)return;
            if(choose_buy==1)
            {
                buy_wand();
                goto buybuy;
            }
            else if(choose_buy==2)
            {
                buy_book();
                goto buybuy;
            }
            else if(choose_buy==3)
            {
                buy_gulingge();
                goto buybuy;
            }
            else cout<=1&&k<=13)lesp+=spell_usual[k-1],pull=1;
    else lesp+=spell_kill[k-14],pull=2;
    lesp+="魔咒,请稍后......";
    init_slow_out(lesp,50);
    Sleep(5500);
    cout<user[d_user].big_life)
            user[d_user].life=user[d_user].big_life;
        system("pause");
    }
    else
    {
        cout<>chse;
            if(chse==0)return;
            if(!(chse>=1&&chse<=16))
            {
                init_slow_out("输入错误!请重新输入:",50);
                goto choose_spell;
            }
            learn_spell(chse);
            return;
    }
    else if(k==2)
    {
        system("cls");
        cout<>chme;
            if(chme==0)return;
            if(!(chme>=1&&chme<=2))
            {
                cout<>chqu;
            if(chqu==0)return;
            if(!(chqu>=1&&chqu<=4))
            {
                cout<>chst;
            if(chst==0)return;
            if(!(chst>=1&&chst<=3))
            {
                cout<>wtd;
            if(wtd==-1)
            {
                system("cls");
                for(int i=1;i<=10;i++)
                {
                    init_slow_out("正在存档,请稍后..........",50);
                    system("cls");
                }
                sign_out();
                MessageBox(NULL,("已经安全的存档并退出。"),("退出游戏"),MB_OK);
                exit(0);
            }
            else if(wtd==0)
            {
                if(MessageBox(NULL,("你确定吗?"),("注销用户"),MB_YESNO|MB_ICONINFORMATION)==IDYES)
                {
                    user[d_user].flag=false;
                    cout<

后记

存档功能特别鸣谢两位帮助我的大佬:lyc和xht。

后期会更新哦!关注我吧球球了!

最后,点个赞吧!

你可能感兴趣的:(原创小游戏,c++,游戏程序)