奥特曼

#include
using namespace std;
class Monster;
class Ultraman
{
public:
Ultraman(int i) //奥特曼初始实力设置
{
rank=i;
exp=0;
hp=rank*10; //生命是等级 10 倍
damage=rank*3; //攻击是等级 3 倍
money=rank*10; //金钱是等级的 10 倍
}
void display(); //奥特曼初始实力输出
void restore(); //用于返回奥特曼回血值
void escape(); //奥特曼逃跑
void update(); //奥特曼升级
int attacked(Monster &s); //奥特曼受到伤害
void fightbacked(Monster &s);
void win(Monster &s);
int getmoney(int mmoney); //获得的金钱
int getrank();
int getexp();
int gethp();
int getdamage();
private:
int rank; //奥特曼等级
int exp; //奥特曼经验
int hp; //奥特曼当前血值
int damage; //奥特曼伤害
int money; //拥用的金钱
};
class Monster
{
public:
Monster(int i)//怪兽初始实力设置
{
mrank=i;
mhp=20*i; //生命是等级 20 倍
mdamage=2*i;//攻击是等级 2 倍
mmoney=i*10;//金钱是等级的 10 倍
mexp=i*10;//经验值是等级的 10 倍。
}
void mdisplay(); //怪兽初始实力输出
int attacked(Ultraman &s); //怪兽收到伤害
int getmmoney(); //返回怪兽身上的金钱
int getmrank();
int getmhp();
int getmdamage();
int getmexp();
private:
int mrank; //怪兽等级
int mhp; //怪兽血值
int mdamage; //怪兽伤害
int mmoney; //怪兽身上的金钱
int mexp;
};
//奥特曼输出属性
void Ultraman::display()
{
cout<<"rank="<"<<"money="<}
int Ultraman::getrank()
{
return rank;
}
int Ultraman::getexp()
{
return exp;
}
int Ultraman::gethp()
{
return hp;
}
int Ultraman::getdamage()
{
return damage;
}
//奥特曼回血
void Ultraman::restore()//如果体力不支(生命低于 50%但大于 10 点),每 10 个金钱可恢复 1 点
生命值。只要有足够的钱,可以一直恢复,直到达到生命值上限(等级的 10 倍)。
{
if(hp=10&&money>=10)
{
while(hp<=rank*10)
{
if(money>=10)
{
money=money-10;
hp=hp+1;
}
else
{
break;
}
}
}
}
//奥特曼逃跑
void Ultraman::escape()
{
money=0;
cout<<"lose"<}
//奥特曼升级
void Ultraman::update()
{
if(exp>=rank*10) //战斗结束后,达到升级条件可以升级,条件是经验值不小于等级 10 倍。
升级将扣除相应的经验值,生命满血,更新生命上限和攻击力。
{
exp-=rank*10;
rank+=1;
hp=rank*10;
damage=rank*3;
}
}
//返回奥特曼血值
int Ultraman::attacked(Monster &s)
{
hp=hp-s.getmdamage()/2;//当怪兽反击时,奥特曼受到的伤害等于怪兽攻击力的一半,即生命
损失=怪兽攻击力值/2,取整处理
return hp;
}
//奥特曼被反击
void Ultraman::fightbacked(Monster &s)
{
hp=hp-s.getmdamage(); //当怪兽被反击后,如果怪兽不死,将进行反击,反击力等于怪兽
攻击力
}
//奥特曼获得金钱
int Ult

raman::getmoney(int mmoney)
{
money+=mmoney;
return money;
}
//奥特曼胜利
void Ultraman::win(Monster &s)
{
cout<<"win"<money+=s.getmmoney();
exp+=s.getmexp();
}
//怪兽输出属性
void Monster::mdisplay()
{
cout<<"rank="<"<<"hp="<"<<"damage="<"<<"exp="<u.display();
cflag=0;
winflag=0;
}
}
else
{
u.win(m);
u.upgrade();
cout<<"win"<cflag=0;
winflag=1;
}
}
if(winflag==0)
break;
}
if(winflag==1)
{
u.display();
Bmonster b;
b.initial();
//b.display();
cflag=1;
int j=0;
while(cflag==1)
{
b.attacked(u);
j++;
//if(j==5)
// b.XP();
if(b.gethp()>0)
{
u.Attacked(b);
if(u.gethp()>10)
u.restore();
else
{
u.escape();
cout<<"lose"<u.display();
cflag=0;
winflag=0;
}
}
else
{
cout<<"win"<u.Win(b);
u.upgrade();
u.display();
cflag=0;
winflag=0;
}
}
}
}
return 0;
}

相关文档
最新文档