the human characters in 2635:P4 gamesTime limit: 1 Sec memory limit: MB
Submissions: 524 Resolution: 328
Title DescriptionIn a plane fight game, any character (role) has a blood volume (blood) and a positional loc (where Loc is an instance of the location Class) attribute. With a role class, you can derive different roles, such as people, Immortals, monsters, and so on. In the following procedure, you define the location class and the role class, a new name and attack data member is added to Human (Human), design member functions for the Human class, and implement the MoveTo and Addblood two member functions in the role class. Write down the required code in the middle of begin and end. You can only edit and submit the code between begin and 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;}; Set position coordinates}; Class Role {public:role (int rblood, int rx, int ry): Blood (Rblood), loc (rx,ry) {} void MoveTo (int rx, int ry); Move to (Rx, Ty), to change the value of loc to void Addblood (int b); Increase the blood volume, the parameter is negative, the representative reduces protected:int blood; Location Loc; }; void Role::moveto (int rx, int ry)
{
Loc.setxy (Rx,ry);
}
void Role::addblood (int b)
{
Blood+=b;
}//************* begin ***************** class Human:public Role {public:private:string name; name int attack; Damage}; End ***************** int main () {string name; int att, blood, x, y; cin>>name>>att>>blood>>x>>y; Human hum (name,att,blood,x,y); The attack att of person name, the amount of blood blood, at (x, y) at Hum.show (); int Incatt, Incblood, newx, Newy; cin>>incatt; cin>>incblood; cin>>newx>>newy; Hum.addattack (Incatt); Damage increased Incatt hum.addblood (Incblood); Blood volume increased Incblood hum.moveto (newx,newy); The man moved to the (news,newy) place Hum.show (); return 0; }
Enter The first line: the name of the blood attack position, where the position is two integers, representing the plane x, y coordinate the second row: Increased damage third line: The amount of blood to increase the fourth line: the new position, with two integers to represent the input parts separated by a space
The output shows the initial state of the game characters in two lines, and the state after adjusting the parameters such as "Avanda have attack and blood in (4,3)" means Avanda has 500 attack and 1000 blood, at (4,3) position
Sample Input
Avanda 4 3
-300
2 5
Sample Output
Avanda have attack and blood in (4,3) Avanda have-attack and blood in
(2,5)
lost in the valley of the birds, flying alone in the vast world, but do not know where they should fly ...
#include <iostream> using namespace std; Class Location {Private:int x, y; public:location (int a, int b): X (a), Y (b) {} int GetX () {retur
n x;
} int GetY () {return y;
} void SetXY (int a,int b) {x=a;
Y=b; };
Set position coordinates}; Class Role {public:role (int rblood, int rx, int ry): Blood (Rblood), loc (rx,ry) {} void MoveTo (int rx, int ry); Move to (Rx, Ty), to change the value of loc to void Addblood (int b);
Increase the blood volume, the parameter is negative, the representative reduces 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:publi C Role,public Location {Public:human (string na,int att,int rblood,int rx,int ry): Location (Rx,ry), Role (Rblood,rx,ry), Name (NA), Attack (ATT) {} void Show () {cout<<name<< "has" <<attack<< "Attack and" & lt;<blood<< "Blood In (" <<getx () << "," <<gety () << ")" <<endL
} void Addattack (int a) {attack+=a;
} void Addblood (int b) {Role::addblood (b);
} void MoveTo (int rx,int ry) {location::setxy (rx,ry); } private:string name; name int attack;
Damage};
int main () {string name;
int att, blood, x, y;
cin>>name>>att>>blood>>x>>y; Human hum (name,att,blood,x,y);
The attack att of person name, the amount of blood blood, at (x, y) at Hum.show ();
int Incatt, Incblood, newx, Newy;
cin>>incatt;
cin>>incblood;
cin>>newx>>newy; Hum.addattack (Incatt); Damage increased Incatt hum.addblood (Incblood); Blood volume increased Incblood hum.moveto (newx,newy);
The man moved to the (news,newy) place Hum.show ();
return 0;
}