zoukankan      html  css  js  c++  java
  • 面向对象_人狗大战

    from time import sleep
    class Person:
        role= 'people'
        def __init__(self,name,attack,blood,defense,weapon=None):
            self.name= name
            self.attack=int(attack)
            self.blood=int(blood)
            self.defense=defense
            self.weapon=weapon
        def attack_start(self,dog_name):
            if self.weapon == None:
                dog_name.blood -= self.attack
                print(self.name+'攻击了%s,'%dog_name.name)
            else:
                dog_name.blood -= self.attack
                print('%s使用%s砍了%s一刀'%(self.name,self.weapon,dog_name.name))
        def equip_weapon(self,weapon_name):
            self.blood += 1000
            self.attack+= 50
            self.weapon = weapon_name.name
            print('%s捡到了%s'%(self.name,weapon_name.name))
    class Dog:
        role='dog'
        def __init__(self,name,kind,aggresivity,defence,blood):
            self.name=name
            self.kind=kind
            self.aggresivity=aggresivity
            self.defence=defence
            self.blood=blood
        def bite(self,person):
            person.blood -= self.aggresivity
            print('%s咬了%s一口'%(self.name,person.name))
    class weapon:
        def __init__(self,name,add_attack,add_blood):
            self.name=name
            self.add_attack=add_attack
            self.add_flood=add_blood
            print('爆出了一件%s'%self.name)
    print('人狗大战即将开始')
    for i in range(10,-1,-1):
        print(i)
        sleep(0.6)
    print('开始')
    alex = Person('alex',10,500,50)
    teddy = Dog('teddy','teddy',100,50,90)
    sleep(0.6)
    alex.attack_start(teddy)
    sleep(0.6)
    print(teddy.blood)#blood血液 flood 洪水
    sleep(0.6)
    teddy.bite(alex)
    sleep(0.6)
    print(alex.blood)
    sleep(0.6)
    wujin=weapon('无尽之刃',10,100)
    sleep(0.6)
    alex.equip_weapon(wujin)
    sleep(0.6)
    alex.attack_start(teddy)
    sleep(0.6)
    print(teddy.blood)
    print('未完待续')
  • 相关阅读:
    js去重的es6做法和es5做法
    对npm的认识
    pandas_分类与聚合
    pandas_使用透视表与交叉表查看业绩汇总数据
    pandas_使用属性接口实现高级功能
    pandas_一维数组与常用操作
    pandas_DateFrame的创建
    python 连接 mysql 的三种驱动
    Django学习路6_修改数据库为 mysql ,创建mysql及进行迁徙
    Django学习路5_更新和删除数据库表中元素
  • 原文地址:https://www.cnblogs.com/accolade/p/10500044.html
Copyright © 2011-2022 走看看