python 小练习('''产生了多少个对象''')('''模拟两个英雄,昵称,攻击力,生命值''')

'''小练习
计数器,产生了多少个对象'''
# class Student:
#     school = 'luffycity'
#     count = 0
#     def __init__(self, name, age, sex):
#         self.name = name
#         self.sex = sex
#         self.age = age
#         # self.count += 1
#         Student.count += 1
#     def learn(self):
#         print('%s is learing' % self.name)
#
# stu1 = Student('lihao', 55, 'boy')
# stu2 = Student('xander', 23, 'boy')
# print(Student.count)
'''模拟两个英雄,昵称,攻击力,生命值'''
class Jie:
    camp = 'dename'
    def __init__(self, nickname, life_value, aggresivity):
        self.nickname = nickname
        self.life_value = life_value
        self.aggresivity = aggresivity
    def attack(self, one):
        one.life_value -= self.aggresivity
class Mangsheng:
    camp = 'qename'
    def __init__(self, nickname, life_value, aggresivity):
        self.nickname = nickname
        self.life_value = life_value
        self.aggresivity = aggresivity
    def attack(self, one):
        one.life_value -= self.aggresivity
j1 = Jie('儿童劫', 100, 30)
m1 = Mangsheng('heshang', 120, 20)
j1 .attack(m1)
m1.attack(j1)
print(j1.__dict__, m1.__dict__)

猜你喜欢

转载自www.cnblogs.com/Xanderzyl/p/10665898.html