在《王者荣耀》游戏中,定义Assassin类的子类为法师( Master )。子类法师( Master)继承父类的攻击、防御和技能冷却属性,对名字、等级和血量属性进行重载。 (1)根据实训1中的需求说明,创建和刺客角色相同属性的父类Asasi (2)创建子类Master (法师)的角色,继承并重载父类的名字、等级和血量属性。 (3)调用子类Master创建对象并命名为master, 访问对象属性,调用oupu ntb区
时间: 2024-02-16 17:05:04 浏览: 249
(1) 根据实训1中的需求,创建和刺客角色相同属性的父类Asasi:
```
class Asasi:
def __init__(self, name, level, hp, attack, defense, skillCD):
self.name = name
self.level = level
self.hp = hp
self.attack = attack
self.defense = defense
self.skillCD = skillCD
```
(2) 创建子类Master (法师)的角色,继承并重载父类的名字、等级和血量属性:
```
class Master(Asasi):
def __init__(self, name, level, hp, attack, defense, skillCD, magicPower):
super().__init__(name, level, hp, attack, defense, skillCD)
self.magicPower = magicPower
def setName(self, name):
self.name = "Master " + name
def setLevel(self, level):
self.level = level + 10
def setHP(self, hp):
self.hp = hp * 2
```
(3) 调用子类Master创建对象并命名为master,访问对象属性,调用oupu ntb区:
```
master = Master("Li Bai", 20, 2000, 100, 50, 10, 200)
master.setName("Wang Zhaojun")
master.setLevel(30)
master.setHP(3000)
print("Name:", master.name)
print("Level:", master.level)
print("HP:", master.hp)
print("Attack:", master.attack)
print("Defense:", master.defense)
print("Skill CD:", master.skillCD)
print("Magic Power:", master.magicPower)
```
输出结果为:
```
Name: Master Wang Zhaojun
Level: 40
HP: 6000
Attack: 100
Defense: 50
Skill CD: 10
Magic Power: 200
```
阅读全文