练习35
class Gamerole:
def __init__(self,nickname,ad,hp):
self.nickname = nickname
self.ad = ad
self.hp = hp
def attack(self,role):
role.hp = role.hp - self.ad
print('%s攻击%s,%s掉了%s血,还剩%s血' %\
(self.nickname, role.nickname, role.nickname, self.ad, role.hp))
def equip_weaon(self,w):
self.weapon = w
class Weapon:
def __init__(self, name, ad):
self.name = name
self.ad = ad
def fight(self,role1,role2):
role2.hp = role2.hp - self.ad
print('%s 用 %s 攻击了 %s,%s 掉了 %s 血,还剩 %s 血' %\
(role1.nickname, self.name, role2.nickname,role2.nickname,self.ad,role2.hp))
p1 = Gamerole('盖伦',20,500)
p2 = Gamerole('剑豪',100,200)
w1 = Weapon('大宝剑',30)
w2 = Weapon('武士刀',80)