53-python-面向对象的引入

# 类:只知道它具有什么东西,但是不知道它具有的东西的具体内容
# 对象:知道具体的哪一个,具体的概念

def People(name,occ,skill,hurt,blood):
    people = {
        'name':name,
        'occ':occ,
        'skill':skill,
        'hurt':hurt,
        'blood':blood
    }
    def attack(g):
        g['blood'] -= q['hurt']
        print('%s 攻击了 %s, %s 还剩余%s的血量' % (q['name'], g['name'], g['name'], g['blood']))
    people['attack'] = attack
    return people

def Monster(name,occ,skill,hurt,blood):
    monster = {
        'name': name,
        'occ': occ,
        'skill': skill,
        'hurt': hurt,
        'blood': blood
    }
    def m_attack(q):
        q['blood'] -= g['hurt']
        print('%s 攻击了 %s, %s还剩 %s 的血量'%(g['name'],q['name'],q['name'],q['blood']))
    monster['m_attack'] = m_attack
    return monster

q = People('q','master','fire',10,100)
g = Monster('Goblin','warrior','tearing',20,200)

q['attack'](g)
g['m_attack'](q)

  



posted @ 2018-10-28 21:28  _Q  阅读(174)  评论(0)    收藏  举报