class SkillDeployer:
"""
技能释放器
"""
def __init__(self, name):
"""
技能名称
:param name:
"""
self.name = name
self.dict_skill_config = self.__load_config_file()
self.__effect_objects = self.__create_effect_objects()
def __load_config_file(self):
"""
读取技能文件
:return:
"""
return {
'鬼波功': ['LowerDeffenseEffect(30)', 'DamageEffect(50)'],
'汽博': ['LowerDeffenseEffect(30)'],
}
def __create_effect_objects(self):
"""
创建技能
:return:
"""
list_effect_name = self.dict_skill_config[self.name]
list_effect_object = []
for item in list_effect_name:
list_effect_object.append(eval(item))
return list_effect_object
def generate_skill(self):
print(self.name, '技能释放了')
for item in self.__effect_objects:
item.impact()
class SkillImpactEffect:
def impact(self):
"""
技能影响效果
:return:
"""
raise NotImplementedError()
class DamageEffect(SkillImpactEffect):
"""
伤害生命效果
"""
def __init__(self, value):
self.value = value
def impact(self):
print('修改生命值%d' % self.value)
class LowerDeffenseEffect(SkillImpactEffect):
"""
修改防御力
"""
def __init__(self, value):
self.value = value
def impact(self):
print('修改防御力%d' % self.value)
list01 = SkillDeployer('汽博')
list01.generate_skill()
list02 = SkillDeployer('鬼波功')
list02.generate_skill()
|