Discuss / Python / 人狗大战!!!

人狗大战!!!

Topic source
# 人狗大战class Dog(object):    def __init__(self, name, pz, gjl, ph): #属性:名字,种类,攻击力,生命值        self.name = name        self.pz = pz        self.gjl = gjl        self.ph = ph    def bite(self, p):   #狗攻击人,参数p放入实例 ren1        p.ph -= self.gjl        return '狗[%s],种类[%s],攻击力[%s],咬了[%s],被攻击者剩余生命值[%s]' % (self.name, self.pz, self.gjl, p.name, p.ph)class Pople(object):    def __init__(self, name, gjl, ph): #属性:名字,攻击力,生命值        self.name = name        self.gjl = gjl        self.ph = ph    def beat_dog(self, dog):  #人打狗  dog参数放入实例 gou1        dog.ph -= self.gjl        return '[%s]打了[%s],攻击力:[%s],被攻击者剩余生命值[%s]' % (self.name, dog.pz, self.gjl, dog.ph)ren1 = Pople('ZhangSan', 50, 100)gou1 = Dog('lala', '金毛', 40, 100)print(gou1.bite(ren1))print(ren1.beat_dog(gou1))

  • 1

Reply