c++day5(2024/1/2)

#include 

using namespace std;
#include 

using namespace std;

int monster=10000;
class Hero{
protected:
    int hp;
    int attack;
    string name;
public:
    Hero(){}
    Hero(string name,int hp,int attack):name(name),hp(hp),attack(attack){}
    virtual void Atk()
    {
        int blood=monster;
        blood-=0;
    }
};

class Master:public Hero{
    int ap_atk=50;
public:
    Master(string name,int hp,int attack):Hero(name,hp,attack){}
    void Atk(){
       int blood=monster;
       int  count=0;
       while (blood>0) {
           count++;
           blood-=(ap_atk+Hero::attack);
       }
       cout<< "法师需要攻击"<< count << "次后怪物死亡" << endl;
    }
    void show()
    {
        cout << "Master:name=" << Hero::name << endl;
        cout << "Master:hp=" << hp << endl;
        cout << "Master:attack=" << ap_atk+Hero::attack << endl;

    }
};

class Shooter:public Hero{
    int ac_atk=50;
public:
    Shooter(string name,int hp,int attack):Hero(name,hp,attack){}
    void Atk(){
       int blood=monster;
       int  count=0;
       while (blood>0) {
           count++;
           blood-=(ac_atk+Hero::attack);
       }
       cout<< "射手需要攻击"<< count << "次后怪物死亡" << endl;
    }
    void show()
    {
        cout << "Shooter:name=" << Hero::name << endl;
        cout << "Shooter:hp=" << hp << endl;
        cout << "Shooterr:attack=" << ac_atk+Hero::attack << endl;

    }
};

int main(){
    Shooter a("vn",560,150);
    Master b("虚空之眼",400,300);
    Hero *hero=&a;
    Hero *hero2=&a;

    a.show();
    hero->Atk();
    cout<<"--------------------------"<Atk();
    return 0;
}

c++day5(2024/1/2)_第1张图片
c++day5(2024/1/2)_第2张图片

你可能感兴趣的:(c++)