c++打怪小游戏

c++打怪小游戏,作者(我)是个萌新,可能写的不好

#include <bits/stdc++.h>
#include <windows.h>            //Sleep()
using namespace std;
int gk=0;
struct i{
    int hp=120,mhp=120;
    string name;
    int hurt=70;
    int gold=100;
    int fy=20;
}my;
struct npc1{
    int hp=200,h=30;
    string n="小兵 武士刀:轻便,伤害80";
}n1;
struct npc2{
    int hp=350,h=40;
    string n="将军 双蝶剑:双伤害,可近可远,伤害120";
}n2;
struct npc3{
    int hp=500,h=50;
    string n="密室使者 暗影刃:可大可小,伤害370";
}n3;
struct npc4{
    int hp=1000,h=100;
    string n="风暴前线 战狙:伤害1150";
}n4;
struct npc5{
    int hp=5000,h=120;
    string n="洛格夫 激光炮:伤害4250";
}n5;
struct npc6{
    int hp=10000,h=900;
    string n="幻影魑魅A 救出公主!";
}n6;

int shop(){
    system("cls");
    cout<<"你要干什么?\n1.生命上限+200 100    2.回血加满 0    3.力量+80 200    4.肉盾+300 500    5.防御加成+100 650";
    int n;
    cin>>n;
    if(n==1&&my.gold >=100){
        my.hp+=200;
        my.mhp+=200;
        my.gold -=100;
        cout<<"完成\n生命上限,生命+200";
        Sleep(1000);
        system("cls");
    }
    if(n==2&&my.gold >=0){
        my.hp=my.mhp;
        cout<<"完成\n生命恢复";
        Sleep(1000);
        system("cls");
    }
    if(n==3&&my.gold >=200){
        my.hurt +=80;
        my.gold -=200;
        cout<<"完成\n攻击+80";
        Sleep(1000);
        system("cls");
    }
    if(n==4&&my.gold >=500){
        my.hp +=300;
        my.gold -=500;
        cout<<"完成\n血量(肉盾)+300";
        Sleep(1000);
        system("cls");
    }
    if(n==5&&my.gold >=650){
        my.fy +=100;
        my.gold -=650;
        cout<<"完成\n防御+100";
        Sleep(2000);
        system("cls");
    }
}
int out(){
    srand((int)time(0));
    int t;
    t=(rand()%400)+101;
    cout<<"保存中";
    Sleep(t);
    t=(rand()%400)+101;
    cout<<".";
    Sleep(t);
    t=(rand()%400)+101;
    cout<<".";
    Sleep(t);
    t=(rand()%400)+101;
    cout<<".";
    return 0;
}
int myhp(){
    system("cls");
    cout<<my.name <<endl;
    cout<<"--------------------------------------------\n";
    cout<<"                  hp:"<<my.hp <<endl;
    cout<<"               生命上限"<<my.mhp <<endl;
    cout<<"                 攻击:"<<my.hurt <<endl;
    cout<<"                 防御:"<<my.fy <<endl;
    cout<<"                 金钱:"<<my.gold <<endl;
    cout<<"--------------------------------------------\n";
    Sleep(10000);
}
int d1(){
    system("cls");
    int hh=1;
    int fs;
    cout<<n1.n ;
    Sleep(3500);
    while(n1.hp >0){
        system("cls");
        cout<<"                    第"<<hh<<"回合\n------------------------------------------------\n";
        cout<<"你要:\n1.攻击    2.闪\n";
        srand((int)time(0));
        cin>>fs;
        if(fs==1){
            int bj=0;
            bj=(rand()%2)+2;
            if(bj=1){
                bj=my.hurt +(rand()%(my.hurt -10))+10;
                cout<<"暴击"<<bj;
                n1.hp -=bj;
                Sleep(3000);
                if(n1.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =80;
                    my.gold +=(rand()%400)+401;
                    Sleep(3000);
                    break;
                }
            }
            else{
                cout<<"普攻"<<my.hurt ;
                n1.hp -=bj;
                Sleep(3000);
                if(n1.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =80;
                    my.gold +=(rand()%400)+401;
                    Sleep(3000);
                    break;
                }
            }
            int hd=n1.h -my.fy ;
            if(n1.h -my.fy <0) hd=0;
            cout<<endl<<"怪物攻击你"<<hd<<endl;
            my.hp -=n1.h -my.fy ;
            cout<<"你剩下"<<my.hp <<"点血";
            Sleep(3000);
        }
        else{
            if((rand()%9)+2==1){
                cout<<"逃离失败    扣"<<0.25*n1.h <<"点血"<<endl;
                my.hp -=0.25*n1.h ;
                Sleep(3000);
            }
            else{
                cout<<"逃离成功!"; 
                Sleep(3000);
            }
        }
        Sleep(3000);
        if(my.hp <=0){
            cout<<"你失败了";
            Sleep(3000);
            return 0;
        }
        hh++;
    }
}
int d2(){
    system("cls");
    int hh=1;
    int fs;
    cout<<n2.n ;
    Sleep(3500);
    while(n2.hp >0){
        system("cls");
        cout<<"                    第"<<hh<<"回合\n------------------------------------------------\n";
        cout<<"你要:\n1.攻击    2.闪\n";
        srand((int)time(0));
        cin>>fs;
        if(fs==1){
            int bj=0;
            bj=(rand()%2)+2;
            if(bj=1){
                bj=my.hurt +(rand()%(my.hurt -10))+10;
                cout<<"暴击"<<bj;
                n2.hp -=bj;
                Sleep(3000);
                if(n2.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =80;
                    my.gold +=(rand()%400)+501;
                    Sleep(3000);
                    break;
                }
            }
            else{
                cout<<"普攻"<<my.hurt ;
                n2.hp -=bj;
                Sleep(3000);
                if(n2.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =80;
                    my.gold +=(rand()%400)+501;
                    Sleep(3000);
                    break;
                }
            }
            int hd=n2.h -my.fy ;
            if(n2.h -my.fy <0) hd=0;
            cout<<endl<<"怪物攻击你"<<hd<<endl;
            my.hp -=n2.h -my.fy ;
            cout<<"你剩下"<<my.hp <<"点血";
            Sleep(3000);
        }
        else{
            if((rand()%9)+2==1){
                cout<<"逃离失败    扣"<<0.25*n2.h <<"点血"<<endl;
                my.hp -=0.25*n1.h ;
                Sleep(3000);
            }
            else{
                cout<<"逃离成功!"; 
                Sleep(3000);
            }
        }
        Sleep(3000);
        if(my.hp <=0){
            cout<<"你失败了";
            Sleep(3000);
            return 0;
        }
        hh++;
    }
}
int d3(){
    system("cls");
    int hh=1;
    int fs;
    cout<<n3.n ;
    Sleep(3500);
    while(n3.hp >0){
        system("cls");
        cout<<"                    第"<<hh<<"回合\n------------------------------------------------\n";
        cout<<"你要:\n1.攻击    2.闪\n";
        srand((int)time(0));
        cin>>fs;
        if(fs==1){
            int bj=0;
            bj=(rand()%2)+2;
            if(bj=1){
                bj=my.hurt +(rand()%(my.hurt -10))+10;
                cout<<"暴击"<<bj;
                n3.hp -=bj;
                Sleep(3000);
                if(n3.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =370;
                    my.gold +=(rand()%400)+601;
                    Sleep(3000);
                }
            }
            else{
                cout<<"普攻"<<my.hurt ;
                n3.hp -=bj;
                Sleep(3000);
                if(n3.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =370;
                    my.gold +=(rand()%400)+601;
                    Sleep(3000);
                }
            }
            int hd=n3.h -my.fy ;
            if(n3.h -my.fy <0) hd=0;
            cout<<endl<<"怪物攻击你"<<hd<<endl;
            my.hp -=n3.h -my.fy ;
            cout<<"你剩下"<<my.hp <<"点血";
            Sleep(3000);
        }
        else{
            if((rand()%9)+2==1){
                cout<<"逃离失败    扣"<<0.25*n3.h <<"点血"<<endl;
                my.hp -=0.25*n3.h ;
                Sleep(3000);
            }
            else{
                cout<<"逃离成功!"; 
                Sleep(3000);
            }
        }
        Sleep(3000);
        if(my.hp <=0){
            cout<<"你失败了";
            Sleep(3000);
            return 0;
        }
        hh++;
    }
}
int d4(){
    system("cls");
    int hh=1;
    int fs;
    cout<<n4.n ;
    Sleep(3500);
    while(n4.hp >0){
        system("cls");
        cout<<"                    第"<<hh<<"回合\n------------------------------------------------\n";
        cout<<"你要:\n1.攻击    2.闪\n";
        srand((int)time(0));
        cin>>fs;
        if(fs==1){
            int bj=0;
            bj=(rand()%2)+2;
            if(bj=1){
                bj=my.hurt +(rand()%(my.hurt -10))+10;
                cout<<"暴击"<<bj;
                n4.hp -=bj;
                Sleep(3000);
                if(n4.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =1150;
                    my.gold +=(rand()%400)+701;
                    Sleep(3000);
                }
            }
            else{
                cout<<"普攻"<<my.hurt ;
                n4.hp -=bj;
                Sleep(3000);
                if(n4.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =1150;
                    my.gold +=(rand()%400)+701;
                    Sleep(3000);
                }
            }
            int hd=n4.h -my.fy ;
            if(n4.h -my.fy <0) hd=0;
            cout<<endl<<"怪物攻击你"<<hd<<endl;
            my.hp -=n4.h -my.fy ;
            cout<<"你剩下"<<my.hp <<"点血";
            Sleep(3000);
        }
        else{
            if((rand()%9)+2==1){
                cout<<"逃离失败    扣"<<0.25*n4.h <<"点血"<<endl;
                my.hp -=0.25*n4.h ;
                Sleep(3000);
            }
            else{
                cout<<"逃离成功!"; 
                Sleep(3000);
            }
        }
        Sleep(3000);
        if(my.hp <=0){
            cout<<"你失败了";
            Sleep(3000);
            return 0;
        }
        hh++;
    }
}
int d5(){
    system("cls");
    int hh=1;
    int fs;
    cout<<n5.n ;
    Sleep(3500);
    while(n5.hp >0){
        system("cls");
        cout<<"                    第"<<hh<<"回合\n------------------------------------------------\n";
        cout<<"你要:\n1.攻击    2.闪\n";
        srand((int)time(0));
        cin>>fs;
        if(fs==1){
            int bj=0;
            bj=(rand()%2)+2;
            if(bj=1){
                bj=my.hurt +(rand()%(my.hurt -10))+10;
                cout<<"暴击"<<bj;
                n5.hp -=bj;
                Sleep(3000);
                if(n5.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =4250;
                    my.gold +=(rand()%400)+801;
                    Sleep(3000);
                }
            }
            else{
                cout<<"普攻"<<my.hurt ;
                n5.hp -=bj;
                Sleep(3000);
                if(n5.hp <=0){
                    system("cls");
                    cout<<"你赢了!";
                    my.hurt =4250;
                    my.gold +=(rand()%400)+801;
                    Sleep(3000);
                }
            }
            int hd=n5.h -my.fy ;
            if(n5.h -my.fy <0) hd=0;
            cout<<endl<<"怪物攻击你"<<hd<<endl;
            my.hp -=n5.h -my.fy ;
            cout<<"你剩下"<<my.hp <<"点血";
            Sleep(3000);
        }
        else{
            if((rand()%9)+2==1){
                cout<<"逃离失败    扣"<<0.25*n5.h <<"点血"<<endl;
                my.hp -=0.25*n5.h ;
                Sleep(3000);
            }
            else{
                cout<<"逃离成功!"; 
                Sleep(3000);
            }
        }
        Sleep(3000);
        if(my.hp <=0){
            cout<<"你失败了";
            Sleep(3000);
            return 0;
        }
        hh++;
    }
}
int d6(){
    system("cls");
    int hh=1;
    int fs;
    cout<<n6.n ;
    Sleep(3500);
    while(n6.hp >0){
        system("cls");
        cout<<"                    第"<<hh<<"回合\n------------------------------------------------\n";
        cout<<"你要:\n1.攻击    2.闪\n";
        srand((int)time(0));
        cin>>fs;
        if(fs==1){
            int bj=0;
            bj=(rand()%2)+2;
            if(bj=1){
                bj=my.hurt +(rand()%(my.hurt -10))+10;
                cout<<"暴击"<<bj;
                n6.hp -=bj;
                Sleep(3000);
                if(n6.hp <=0) break;
            }
            else{
                cout<<"普攻"<<my.hurt ;
                n6.hp -=bj;
                Sleep(3000);
                if(n6.hp <=0) break;
            }
            int hd=n6.h -my.fy ;
            if(n6.h -my.fy <0) hd=0;
            cout<<endl<<"怪物攻击你"<<hd<<endl;
            my.hp -=n6.h -my.fy ;
            cout<<"你剩下"<<my.hp <<"点血";
            Sleep(3000);
        }
        else{
            if((rand()%9)+2==1){
                cout<<"逃离失败    扣"<<0.25*n6.h <<"点血"<<endl;
                my.hp -=0.25*n6.h ;
                Sleep(3000);
            }
            else{
                cout<<"逃离成功!"; 
                Sleep(3000);
            }
        }
        Sleep(3000);
        if(my.hp <=0){
            cout<<"你失败了";
            Sleep(3000);
            return 0;
        }
        hh++;
    }
    Sleep(2000);
}
int main(){
    printf("请输入您的姓名:\n"); 
    cin>>my.name ;
    system("cls");
    system("color 03");
    printf("很久很久以前"); 
    Sleep(2000);
    system("cls");
    printf("公主被一个蒙面人挟持走"); 
    Sleep(2000);
    system("cls");
    printf("你");
    Sleep(1000);
    system("cls");
    cout<<my.name ;
    Sleep(1000);
    system("cls");
    printf("化身正义的勇士,前去营救公主!"); 
    Sleep(2000);
    system("cls");
    int n;
    while(n6.hp >0){
        system("cls");
        cout<<"你要干哈?\n1.商店    2.打怪   3.玩家状态   4.退出\n";
        cin>>n;
        if(n==1){
            shop();
        }
        if(n==2){
            gk++;
            if(gk==1) d1();
            if(gk==2) d2();
            if(gk==3) d3();
            if(gk==4) d4();
            if(gk==5) d5();
            if(gk==6) d6();
        }
        if(n==3){
            myhp();
        }
        if(n==4){
            srand((int)time(0));
            int t;
            t=(rand()%400)+101;
            cout<<"保存中";
            Sleep(t);
            t=(rand()%400)+101;
            cout<<".";
            Sleep(t);
            t=(rand()%400)+101;
            cout<<".";
            Sleep(t);
            t=(rand()%400)+101;
            cout<<".";
            exit(0);
        }
    }
    system("cls");
    cout<<"恭喜你!你就出了公主!";
    Sleep(1000);
    cout<<"伟大的"<<my.name <<"!";
    cout<<"游戏结束";
    Sleep(3000);
    system("cls");
    srand((int)time(0));
    int t;
    t=(rand()%400)+101;
    cout<<"保存中";
    Sleep(t);
    t=(rand()%400)+101;
    cout<<".";
    Sleep(t);
    t=(rand()%400)+101;
    cout<<".";
    Sleep(t);
    t=(rand()%400)+101;
    cout<<".";
    cout<<"Thank you to play!!!\n作者:任*鑫";
    exit(0);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值