作业:
#include <iostream>
using namespace std;
int blood=10000;
class hero
{
protected:
string name;
int hp;
int attack;
public:
hero():name("马哥"),hp(500),attack(50){}
hero(string name,int hp,int attack):name(name),hp(hp),attack(attack){}
virtual void Atk()
{
blood-=0;
}
};
class AP:public hero
{
int ap_atk=50;
public:
AP():hero(){}
AP(string name,int hp,int attack):hero(name,hp,attack){}
void Atk()
{
blood-=(attack+ap_atk);
}
};
class AD:public hero
{
int ad_atk=100;
public:
AD():hero(){}
AD(string name,int hp,int attack):hero(name,hp,attack){}
void Atk()
{
blood-=(attack+ad_atk);
}
};
int main()
{
AD a;
AP b("hs",550,50);
while (1)
{
a.Atk();
cout<<"AD a了一下,blood="<<blood<<endl;
if(blood<=0)
{
cout<<"暨了"<<endl;
break;
}
b.Atk();
cout<<"AP a了一下,blood="<<blood<<endl;
if(blood<=0)
{
cout<<"暨了"<<endl;
break;
}
}
return 0;
}