?
#include <iostream>
using namespace std;
int blood=10000;
class Hero
{
protected:
string name;
int hp;
int attck;
public:
Hero(){cout<<"hero的无参构造函数"<<endl;}
Hero(string name,int hp,int attck):name(name),hp(hp),attck(attck){cout<<"hero的有参构造函数"<<endl;}
virtual ~Hero(){cout<<"hero的析构函数"<<endl;}
virtual void Atk()
{
blood-=0;
}
};
class Master:public Hero
{
int ap_atk=50;
public:
Master(){}
Master(string name,int hp,int attck):Hero(name,hp,attck){}
void Atk() override
{
blood-=(attck+ap_atk);
}
};
class Shooter:public Hero
{
int ac_atk=100;
public:
Shooter(){}
Shooter(string name,int hp,int attck):Hero(name,hp,attck){}
void Atk()override
{
blood-=(attck+ac_atk);
}
~Shooter(){cout<<"shoot的析构函数"<<endl;}
};
int main()
{
Master m1("剑姬",100,2400);
Shooter s1("刀妹",100,2500);
int count=0;
while(blood>0)
{
m1.Atk();
if(blood>0)
{
s1.Atk();
}
count++;
}
Hero *p=new Shooter("万豪",2000,100);
p->Atk();
delete p;
return 0;
}