c++打怪小游戏(求大神指点)

这是一个使用C++编写的战斗小游戏,包括多个不同等级的敌人,玩家可以选择攻击或闪避,战斗中可以购买道具提升属性。游戏结束后会进行保存并显示恭喜信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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个

红包金额最低5元

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

抵扣说明:

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

余额充值