[YTU]_2635(P4 游戏中的Human角色)
来源:互联网 发布:数据库与服务器 编辑:程序博客网 时间:2024/05/28 04:54
题目描述
在一个平面打斗游戏中,任何的角色(Role)都有血量(blood)和位置loc(此处loc是Location类的实例)属性。有了Role类,可以派生出不同的角色,如人、神仙、怪兽等。如下程序中,定义了Location类和Role类,人类(Human)中新增了姓名和攻击力数据成员,请为Human类设计成员函数,并实现Role类中的moveTo和addBlood两个成员函数。
请在begin和end中间写下需要的代码。你只能编辑并提交begin和end之间的代码。
#include <iostream>
using namespace std;
class Location
{
private:
int x, y;
public:
Location(int a, int b):x(a),y(b) {}
int getX(){return x;}
int getY(){return y;}
void setXY(int a,int b) {x=a;y=b;}; //设置位置坐标
};
class Role
{
public:
Role(int rblood, int rx, int ry):blood(rblood),loc(rx,ry) {}
void moveTo(int rx, int ry); //移动到(rx, ty)处,要改变loc的值
void addBlood(int b); //增加血量,参数为负时,代表减少
protected:
int blood;
Location loc;
};
void Role::moveTo(int rx, int ry)
{
loc.setXY(rx,ry);
}
void Role::addBlood(int b)
{
blood+=b;
}
{
loc.setXY(rx,ry);
}
void Role::addBlood(int b)
{
blood+=b;
}
//************* begin *****************
class Human: public Role
{
public:
private:
string name; // 姓名
int attack; // 攻击力
};
//************* end *****************
int main()
{
string name;
int att, blood, x, y;
cin>>name>>att>>blood>>x>>y;
Human hum(name,att,blood,x,y); //人name的攻击力att,血量blood,在(x,y)处
hum.show();
int incAtt, incBlood, newx, newy ;
cin>>incAtt;
cin>>incBlood;
cin>>newx>>newy;
hum.addAttack(incAtt); //攻击力增加incAtt
hum.addBlood(incBlood); //血量增加incBlood
hum.moveTo(newx,newy); //人移到了(news,newy)处
hum.show();
return 0;
}
输入
第一行:名字 血量 攻击力 位置,其中位置处是两个整数,代表平面x、y坐标
第二行:增加的攻击力
第三行:要增加的血量
第四行:新位置,用两个整数代表
输入的各部分之间用空格隔开
输出
分别用两行显示游戏角色的初始状态和调整参数后的状态
如“Avanda has 500 attack and 1000 blood in (4,3)”表示Avanda有500攻击力1000血量,在(4,3)位置处
样例输入
Avanda 500 1000 4 3-3002002 5
样例输出
Avanda has 500 attack and 1000 blood in (4,3)Avanda has 200 attack and 1200 blood in (2,5)#include <iostream>using namespace std;class Location{private: int x, y;public: Location(int a, int b):x(a),y(b) {} int getX(){return x;} int getY(){return y;} void setXY(int a,int b) {x=a;y=b;}; //设置位置坐标}; class Role{public: Role(int rblood, int rx, int ry):blood(rblood),loc(rx,ry) {} void moveTo(int rx, int ry); //移动到(rx, ty)处,要改变loc的值 void addBlood(int b); //增加血量,参数为负时,代表减少protected: int blood; Location loc;};void Role::moveTo(int rx, int ry){ loc.setXY(rx,ry);}void Role::addBlood(int b) { blood+=b;}class Human:public Role{public:Human(string nam,int att,int b,int rx,int ry):Role(b,rx,ry),name(nam),attack(att){} void show() { cout<<name<<" has "<<attack<<" attack and "<<blood<<" blood in ("<<loc.getX()<<','<<loc.getY()<<')'<<endl; } void addAttack(int att) {attack+=att;}private: string name; int attack;};int main(){ string name; int att, blood, x, y; cin>>name>>att>>blood>>x>>y; Human hum(name,att,blood,x,y); //人name的攻击力att,血量blood,在(x,y)处 hum.show(); int incAtt, incBlood, newx, newy ; cin>>incAtt; cin>>incBlood; cin>>newx>>newy; hum.addAttack(incAtt); //攻击力增加incAtt hum.addBlood(incBlood); //血量增加incBlood hum.moveTo(newx,newy); //人移到了(news,newy)处 hum.show(); return 0;
阅读全文
0 0
- [YTU]_2635(P4 游戏中的Human角色)
- YTU-OJ-P4 游戏中的Human角色
- YTU 2635: P4 游戏中的Human角色
- P4 游戏中的Human角色
- OJ积累--P4游戏中的human角色
- OJ第三批——Problem T: P4 游戏中的Human角色
- 游戏角色中的类
- 游戏中的角色类
- 游戏中的角色类
- 游戏中的角色类
- 三维游戏中的角色动画
- 游戏中的角色类(1)
- 游戏中的角色类2
- 游戏中的角色类1
- 游戏中的角色类1
- 游戏中的角色类2
- 游戏中的角色类2
- 项目2-游戏中的角色(1)
- [YTU]_2476(E3 继承了,成员函数却不可访问)
- android文件存储的4种方式
- retrofit2.0中自定义转换器使用,通用啊
- HashMap实现原理分析
- [poj1741] Tree 点分
- [YTU]_2635(P4 游戏中的Human角色)
- idea中JSP模板{头信息}的设置方法
- bzoj 1004 Cards
- 掌握这个套路,80%的问题你都能靠自己解决
- 大数据:Spark mlib(一) KMeans聚类算法源码分析
- opencv数字图像基础,提取图像像素,遍历图像
- hadoop 打开文件输入流 源码分析
- ORACLE 查看分区表的相关信息语句
- Jenkins+SVN+AndoriodStudio自动打包(自动化持续构建)