日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[YTU]_2635(P4 游戏中的Human角色)

發(fā)布時間:2025/4/16 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [YTU]_2635(P4 游戏中的Human角色) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目描述

在一個平面打斗游戲中,任何的角色(Role)都有血量(blood)和位置loc(此處loc是Location類的實例)屬性。有了Role類,可以派生出不同的角色,如人、神仙、怪獸等。如下程序中,定義了Location類和Role類,人類(Human)中新增了姓名和攻擊力數(shù)據(jù)成員,請為Human類設計成員函數(shù),并實現(xiàn)Role類中的moveTo和addBlood兩個成員函數(shù)。 請在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); //增加血量,參數(shù)為負時,代表減少 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; ?// 姓名 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; }

輸入

第一行:名字 血量 攻擊力 位置,其中位置處是兩個整數(shù),代表平面x、y坐標 第二行:增加的攻擊力 第三行:要增加的血量 第四行:新位置,用兩個整數(shù)代表 輸入的各部分之間用空格隔開

輸出

分別用兩行顯示游戲角色的初始狀態(tài)和調(diào)整參數(shù)后的狀態(tài) 如“Avanda has 500 attack and 1000 blood in (4,3)”表示Avanda有500攻擊力1000血量,在(4,3)位置處

樣例輸入

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); //移動到(rx, ty)處,要改變loc的值void addBlood(int b); //增加血量,參數(shù)為負時,代表減少 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); //攻擊力增加incAtthum.addBlood(incBlood); //血量增加incBloodhum.moveTo(newx,newy); //人移到了(news,newy)處hum.show();return 0;

總結(jié)

以上是生活随笔為你收集整理的[YTU]_2635(P4 游戏中的Human角色)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。