对战小程序

在这个游戏中,玩家可以创建自己的角色,选择武器,与不同类型的怪物和 Boss 进行战斗。战斗过程中,玩家和怪物的生命值、攻击力、防御力等属性会影响胜负。通过战斗,玩家可以获得经验值,提升等级并增强属性。最终目标是击败所有 Boss。

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

#pragma once
#include<iostream>
using namespace std;
class biology {
protected:
    int jingyan;//经验值
    int ad;//攻击力
    int hp, temhp;//属性生命值和对战生命值
    int hu;//防御力
public:
    biology(int i, int i1, int i2, int i3) :ad(i), hu(i1), hp(i2), jingyan(i3) { temhp = i2; }//生物构造函数
    int rhp() { return temhp; }//返回对战时的生命值
    virtual void loss() {}//
    int rjing() { return jingyan; }//用于角色胜利后获取经验值
    void hurt1(int ad) { temhp -= ad; }//直接对对战生命值造成伤害
    void hurt(int ad) { int t = ad - hu; if (t > 0)temhp -= t; }//在护甲作用下对生命值造成伤害
    virtual void attack(biology& b) { b.hurt(ad); }//攻击程序
    virtual void pr() { cout << " monster hp=" << temhp << endl; }//
    void end() { temhp = hp; }//在对战结束后将对战生命值回复满
};
class wuqi {
public:
    virtual void xiaoguo(biology& t) {}
};
class gong :public wuqi {
public:
    void xiaoguo(biology& e) {
        e.hurt1(3);
    }
};
class sword :public wuqi {
    int n = 1;
public:
    void xiaoguo(biology& e) {
        if (n % 2 == 0)
            e.hurt1(8);
        n++;
    }
};
class boss :public biology {
public:
    static int n;
    void loss() { n++; }
    boss(int i1, int i2, int i3, int i4) :biology(i1, i2, i3, i4) {}
    virtual void jineng() {}
};
int boss::n = 0;
class boss1 :public boss {
public:
    boss1(int i1, int i2, int i3, int i4) :boss(i1, i2, i3, i4) {}
    void jineng() {
        temhp += 3;
    }
    void attack(biology& t) { t.hurt(ad); jineng(); }
};
class boss2 :public boss {
public:
    boss2(int i1, int i2, int i3, int i4) :boss(i1, i2, i3, i4) {}
    void jineng() {
        ad += 2;
    }
    void attack(biology& t) { t.hurt(ad); jineng(); }
};
class boss3 :public boss {
public:
    boss3(int i1, int i2, int i3, int i4) :boss(i1, i2, i3, i4) {}
    void jineng() {
        hu += 1;
    }
    void attack(biology& t) { t.hurt(ad); jineng(); }
};
class you :public biology {
    int n;//等级;
    wuqi* q;//携带的武器
public:
    you(int i, int i1, int i2, int i3, int i5) :n(i3), biology(i, i1, i2, 0) { if (i5 == 1)q = new sword; else if (i5 == 2)q = new gong; }
    ~you() { delete q; }
    void attack(biology& b) { b.hurt(ad); q->xiaoguo(b); }
    void pr() { cout << "your hp=" << temhp << endl; }
    void win(biology& c) { cout << "you win!" << endl; jingyan += c.rjing(); shengji(); }
    void lost() { cout << "you lost." << endl; }
    void shengji() {
        if (jingyan >= 30) {
            cout << "ok,you can upgrade!" << endl;
            n++;
            int tem;
            tem = n * 2;
            ad = 10 + tem;
            tem = n * 5;
            hp = 50 + tem;
            tem = n;
            hu = 6 + tem;
            jingyan = jingyan % 30;
            cout << " hp=" << hp << " ad=" << ad << " hu=" << hu << " grade=" << n << endl;
        }
        else
            cout << "sorry,you can't upgrade now." << "now your jingyan is:" << jingyan << endl;
    }
};

#include<iostream>
#include<cstring>
#include"lei.h"
using namespace std;
void crewu(int n) {
    if (n == 1) {
        cout << "   i" << endl;
        cout << "  (-)" << endl;
        cout << " v l v" << endl;
        cout << "   U" << endl;
    }
    else if (n == 2) {
        cout << " W" << endl;
        cout << "D--)-" << endl;
        cout << " M" << endl;
    }
    else {
        cout << "please input again." << endl;
    }
}
void crecha(int n) {
    if (n == 1) {
        cout << " <o o>" << endl;
        cout << "-  l  -" << endl;
        cout << " v - v" << endl;
    }
    else if (n == 2) {
        cout << " <o o>" << endl;
        cout << "- olo -" << endl;
        cout << " v - v" << endl;
    }
    else {
        cout << "please input your sex again:" << endl;
    }
}
void pk(you& i, biology& i1) {
    for (;;) {
        i.attack(i1);
        i1.pr();
        if (i1.rhp() <= 0) {
            i.win(i1);
            i1.loss();
            i1.end();
            i.end();
            break;
        }
        i1.attack(i);
        i.pr();
        if (i.rhp() <= 0) {
            i.end();
            i1.end();
            i.lost();
            break;
        }
    }
}
int main() {
    cout << "Hello,welcome to this world!" << endl;
    cout << "Now create your character" << endl;
    cout << "input your sex " << endl << "1 means man and 2 means woman" << endl;
    int sex;
    do {
        cin >> sex;
        cout << "let's see what you look like in this world:" << endl;
        crecha(sex);
    } while (sex != 1 && sex != 2);
    int wu;
    cout << "here are two weapons to choose from." << endl;
    crewu(1);
    cout << "deals 5 damage per second attack." << endl;
    crewu(2);
    cout << "each attack deals 2 damage." << endl;
    cout << "now input the number of the weapons you want." << endl;
    do {
        cin >> wu;
        cout << "let's see what you look like in this world:" << endl;
        crewu(wu);
        crecha(sex);
    } while (wu != 1 && wu != 2);
    you u(10, 6, 50, 0, wu);
    biology xiaoguai(8, 4, 60, 20);
    boss1 t(15, 10, 150, 60);
    boss2 t1(25, 10, 100, 60);
    boss3 t2(20, 15, 100, 60);
    cout << "there are three boss in this world.please kill them." << endl;
    cout << "now start your jounary:" << endl;
    do {
        cout << "T..T" << " U-oo-U" << " Qi-iQ" << " Y~V-V~Y" << endl;
        cout << " **" << "    TT" << "     MM" << "     WW" << endl;
        cout << "  1" << "      2" << "      3" << "     4" << endl;
        int i;
        cin >> i;
        if (i == 1)
            pk(u, xiaoguai);
        else if (i == 2)
            pk(u, t);
        else if (i == 3)
            pk(u, t1);
        else if (i == 4)
            pk(u, t2);
    } while (boss::n != 3);
    cout << "you win the game!" << endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kianery

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值