day19work

1. What is the subject? What is class?

Practical features of the object is a combination of

It is the same class and object feature series combination of skills

2. What are the characteristics of binding method

The object to call a bound method object is called,
a different object calls the bound method, it will be a different object passed in the binding process
to bind methods of an object, the object is invoked,
the special of the first is to place an object as a parameter passed to the method

3. Based on object-oriented design a battle game

class Riven:
    '''放逐之刃'''
    camp = 'Noxus'

    def __init__(
        self,
        name,
        aggressivity = 56,  #初始攻击力
        life_value = 558,
        money = 1000,
        armor = 24):  #护甲
        self.name = name
        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 Garen:
    '''德玛西亚之力'''
    camp = 'Demacia'

    def __init__(
        self,
        name,
        aggressivity = 56,  #初始攻击力
        life_value = 551,
        money = 1000,
        armor = 21):  #护甲
        self.name = name
        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 Teemo:
    '''迅捷斥候'''
    camp = 'Yordels'
    def __init__(
        self,
        name,
        aggressivity = 49,  #初始攻击力
        life_value = 551,
        money = 1000,
        armor = 14):  #护甲
        self.name = name
        self.aggressivity = aggressivity
        self.life_value = life_value
        self.money = money
        self.armor = armor


class BlackCleaver:
    def __init__(
        self,
        price = 475,
        aggrev = 8,
        life_value = 80):
        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


#实例化对象
r1 = Riven('锐雯')
g1 = Garen('盖伦')
b1 = BlackCleaver()

#购买装备前属性
print(r1.aggressivity, r1.life_value, r1.money)

if r1.money > b1.price:  #如果金币大于售价
    r1.b1 = b1           #r1新增属性
    b1.update(r1)        #r1各项属性随购买b1变化

#购买装备后的属性
print(r1.aggressivity, r1.life_value, r1.money)


print('盖伦初始血量',g1.life_value)#挨打前生命值
print('锐雯初始血量',r1.life_value)#挨打前生命值

round = 1


while True:
    print(f'第{round}回合')
    round+=1
    r1.attack(g1)  # 普攻
    if g1.life_value < 0:
        print('盖伦被打死了')
        break
    else:
        print('盖伦血量',g1.life_value)

    g1.attack(r1)  # 普攻
    if r1.life_value < 0:
        print('锐雯被给打死了')
        break
    else:
        print('锐雯血量',r1.life_value)

Guess you like

Origin www.cnblogs.com/shenblog/p/11641827.html