c++ 已知角色亚瑟arthur的初始血量为3622,物攻为164,孙悟空monkey_king的初始血量为3293,物攻为167,蓝量为430。 请在main函数中创建这两个角色并初始化,输出他们的属性。
时间: 2024-03-01 19:51:59 浏览: 20
好的,以下是 C++ 代码实现:
```cpp
#include <iostream>
#include <string>
using namespace std;
class Hero {
public:
Hero(string name, int hp, int ad, int mana=0) {
this->name = name;
this->hp = hp;
this->ad = ad;
this->mana = mana;
}
void show_status() {
cout << name << " 的属性:" << endl;
cout << " 生命值:" << hp << " 物理攻击:" << ad << " 蓝量:" << mana << endl;
}
private:
string name;
int hp;
int ad;
int mana;
};
int main() {
Hero arthur("Arthur", 3622, 164);
Hero monkey_king("Monkey King", 3293, 167, 430);
arthur.show_status();
monkey_king.show_status();
return 0;
}
```
输出结果为:
```
Arthur 的属性:
生命值:3622 物理攻击:164 蓝量:0
Monkey King 的属性:
生命值:3293 物理攻击:167 蓝量:430
```
其中,我们定义了一个 Hero 类,可以用来创建游戏中的角色。在创建角色的时候,我们可以指定他们的初始生命值、物理攻击和蓝量。同时,我们也定义了一个 show_status 方法,用来打印角色的属性。在 main 函数中,我们创建了 Arthur 和 Monkey King 两个角色,并打印了他们的属性。