Ejemplo n.º 1
0
        self.cd = cd
        self.atk = atk
        self.costSP = costSP


list_skills = [
    SkillData(101, "降龙十八掌", 60, 10, 5),
    SkillData(102, "如来神掌", 50, 15, 0),
    SkillData(103, "六脉神剑", 0, 20, 8),
    SkillData(104, "一阳指", 0, 50, 15),
    SkillData(105, "冷酷追击", 15, 30, 9),
]
# 作业1:
# 解决的问题1:
#    获取敌人列表中,攻击力最小的敌人.
result = ListHelper.get_min(list_skills, lambda e: e.atk)
print(result.name)

result = min(list_skills, key=lambda e: e.atk)
print(result.name)

# 解决的问题2:
#    根据cd对技能列表进行降叙排列
#    使用内置高阶函数和ListHelper实现.
# ListHelper.order_by_descending(list_skills,lambda e:e.cd)
# for item in list_skills:
#     print(item.cd)

# for item in sorted(list_skills,key = lambda e:e.cd,reverse=True):
#     print(item.cd)
Ejemplo n.º 2
0
    def __repr__(self):
        return "Enemy(%d,%s,%d,%d,%d)"%(self.id,self.name,self.atk,self.hp,self.atk_speed)

L = [
    Enemy(100,"张三",10,50,5),
    Enemy(101,"李四",15,20,7),
    Enemy(102,"王五",5,0,2),
    Enemy(103,"莉莉",20,0,13),
    Enemy(104,"芳芳",17,30,9)
]

# 解决的问题1:
#    获取敌人列表中,攻击力最小的敌人.
#    使用内置高阶函数和ListHelper实现.
result = ListHelper.get_min(L,lambda e : e.atk)
print(result)
result = min(L,key = lambda e : e.atk)
print(result)

# 解决的问题2:
#    根据血量对敌人列表进行降叙排列
#    使用内置高阶函数和ListHelper实现.
for item in sorted(L,key = lambda e : e.hp,reverse=True):
    print(item)

ListHelper.order_by_descending(L,lambda e : e.hp)
print(L)

ListHelper.sort(L,lambda e : e.hp,reverse=True)
print(L)