# P4 游戏中的Human角色

P4 游戏中的Human角色

#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的值
protected:
int blood;
Location loc;
};
void Role::moveTo(int rx, int ry)
{
loc.setXY(rx,ry);
}
{
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.moveTo(newx,newy);  //人移到了(news,newy)处
hum.show();
return 0;
}

``````Avanda 500 1000 4 3
-300
200
2 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);
protected:
int blood;
Location loc;
};
void Role::moveTo(int rx, int ry)
{
loc.setXY(rx,ry);
}
{
blood+=b;
}

//************* begin *****************

class Human: public Role
{
public:
Human(string hname, int att, int hblood, int hx, int hy):
Role(hblood,hx,hy),name(hname),attack(att) {}
void show()
{
cout<<name<<" has "<<attack<<" attack and "<<blood<<" blood in ("<<loc.getX()<<","<<loc.getY()<<")"<<endl;
}
{
attack+=att;
}
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.moveTo(newx,newy);  //人移到了(news,newy)处
hum.show();
return 0;
}``````

``````
#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的值
protected:
int blood;
Location loc;
};
void Role::moveTo(int rx, int ry)
{
loc.setXY(rx,ry);
}
{
blood+=b;
}class Human: public Role
{
public:
Human(string hname, int att, int hblood, int hx, int hy):
Role(hblood,hx,hy),name(hname),attack(att) {}
void show()
{
cout<<name<<" has "<<attack<<" attack and "<<blood<<" blood in ("<<loc.getX()<<","<<loc.getY()<<")"<<endl;
}
{
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;