如何创建一个需要大量参数的基类

2024-06-28 15:44:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我的班级是:

class Champion:

    def __init__(self, secondary_bar, secondary_attributes, health, health_reg, mana, mana_reg, c_range, att_damage, att_speed, armor, magic_res, move_speed):
        self.secondary_bar = secondary_bar 
        self.secondary_attributes = secondary_attributes
        self.health = health
        self.health_reg = health_reg
        self.mana = mana
        self.mana_reg = mana_reg
        self.c_range = c_range
        self.att_damage = att_damage
        self.att_speed = att_speed
        self.armor = armor
        self.magic_res = magic_res
        self.move_speed = move_speed

    ...


class SpecificChampion(Champion):

    ...


my_champ = SpecificChampion("mana", "melee", 500, 20, 250, 20, 125, 50, 0.8, 65, 65, 320)

我想要一个更短的方法来创建第一个类,因为在我看来它占用了太多的空间。我尝试使用kwargs将它们存储在一个列表中,但是访问它们并将它们作为参数传递给其他函数有点混乱。有什么建议吗?你知道吗


Tags: selfmovemagicbarrangeresregatt