10.9 作业
什么是对象?什么是类?
对象是特征和技能的结合体
类是有相同特征和技能的对象的结合体
绑定方法有什么特点
把对象当作第一个参数传入
对战游戏
class Irelia:
camp='Noxus'
def __init__(self,name,aggressivity=55,life_value=514,armor=30):
self.name=name
self.aggressivity=aggressivity
self.life_value=life_value
self.armor=armor
def attack(self,enemy):
damage_value=self.aggressivity-enemy.armor
enemy.life_value-=damage_value
class Teemo:
camp='Yordels'
def __init__(self,name,aggressivity=52,life_value=455,armor=25):
self.name=name
self.aggressivity=aggressivity
self.life_value=life_value
self.armor=armor
def attack(self,enemy):
damage_value=self.aggressivity-enemy.armor
enemy.life_value-=damage_value
r1=Irelia('刀妹')
g1=Teemo('提百万')
print(f'{r1.name},攻击力:{r1.aggressivity},生命值:{r1.life_value},护甲:{r1.armor}')
while True:
if g1.life_value <= 0:
print('英雄已阵亡!!!')
break