/*
*Copyright(c) 2016, 烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:李德坤
*完成日期:2016年3月31日
*版本号:v1.0
*
*问题描述:设计游戏角色
*输入描述:无
*输出描述:角色的状态
*/
#include <iostream>
using namespace std;
class Role
{
public:
void setRole(string name,int m);
void show();
void attack();
void eat(int n);
void beAttack();
private:
string name;
int blood;
bool life();
};
void Role::setRole(string name1,int m)
{
name=name1;
blood=m;
}
void Role::show()
{
if(life())
cout<<"Mary has"<<" "<<blood<<" "<<"blood"<<","<<"it is alived."<<endl;
}
bool Role::life()
{
if(blood>0)
return true;
else
return false;
}
void Role::attack()
{
blood=blood-1;
}
void Role::eat(int n)
{
blood=blood+n;
}
void Role::beAttack()
{
blood=blood-1;
}
int main()
{
Role mary;
mary.setRole("Mary",4);
mary.show();
mary.attack();
mary.eat(2);
mary.beAttack();
mary.beAttack();
mary.show();
return 0;
}
第五周项目2.1
最新推荐文章于 2025-12-06 19:00:36 发布
464

被折叠的 条评论
为什么被折叠?



