什么是对象
对象是具有特征和技能的实体
什么是类
类是具有一系列对象相同特征和技能的结合体
绑定方法有什么特点
把对象当作第一个参数传入该方法中
理解敲出来的
class Riven:
camp = 'Noxus'
def __init__(self,nickname,aggressivuty=54,life_value=414,money=1001,armor=3):
self.nickname = nickname
self.aggressivity = aggressivuty
self.life_value = life_value
self.money = money
self.armor = armor
def attack(self,enemy):
damage_value = self.aggressivity - enemy.armor
enemy.life_value -= damage_value
class Garen:
camp = 'Demacia'
def __init__(self,nickname,aggressivity=58,life_value=455,money=100,armor=10):
self.nickname = nickname
self.aggressivity = aggressivity
self.life_value = life_value
self.money = money
self.armor = armor
def attack(self,enemy):
damage_value = self.aggressivity - enemy.armor
enemy.life_value -= damage_value
class BlackCleaver:
def __init__(self,price=475,aggrev=9,life_value =100):
self.price =price
self.aggrev = aggrev
self.life_value = life_value
def update(self,obj):
obj.money -= self.price
obj.aggressivity += self.aggrev
obj.life_value += self.life_value
def fire(self,obj):
obj.life_value -= 1000
r1 = Riven('草丛伦')
g1 = Garen('盖文')
b1 = BlackCleaver()
print(r1.aggressivity,r1.life_value,r1.money)
if r1.money > b1.price:
r1.skill = b1
b1.update(r1)
print(r1.aggressivity,r1.money,r1.life_value)
print(g1.life_value)
r1.attack(g1)
print(g1.life_value)
r1.b1.fire(g1)# 特殊攻击
print(g1.life_value)