python - 类 '...' 的未解析属性引用 '...'

标签 python pygame pycharm

当我在 Zombie 类中调用 render() 方法时,我想将 Zombie 对象的一个​​实例添加到 ZombieList.list 中。当我尝试这样做时,它说

Unresolved attribute reference list for class ZombieList.

我应该尝试另一种方式吗?

class ZombieList:
    def __init__(self):
        self.list = []
        for zombie in self.list:
            ds.blit(zombie.image, (1000, random.randint(10, 790)))

class Zombie(object):
    def __init__(self):
        self.attack = 3
        self.speed = 5
        self.health = 30
        self.image = pygame.image.load("Assets/green zombie.png")

        self.zombieList = []

    def render(self):
        ZombieList.list.append(self)

最佳答案

您必须创建一个ZombieList 对象,您可以将Zombie 对象附加到其中。
您可以添加 Class ObjectsZombie 类:

class Zombie(object):

    zombies = ZombieList()

    def __init__(self):
        self.attack = 3
        self.speed = 5
        self.health = 30
        self.image = pygame.image.load("Assets/green zombie.png")

    def render(self):
        Zombie.zombies.list.append(self)

关于python - 类 '...' 的未解析属性引用 '...',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55406904/

相关文章:

python - 如何修复 Python 变音字典值

python - 在 Pygame 中移动 Gif?

python - 向spyder添加文档(python IDE)

python - 怎样才能让蛇继续移动呢?

pycharm - 如何阻止pycharm在虚拟环境文件夹中搜索?

python - 调用 Flask app.run 后,我可以让 Python 代码继续执行吗?

Python:Pandas 数据帧总和

python - typing.NamedTuple 和 PyCharm

python - 将 pandas 数据帧转换为元组列表 - ('Row' 、 'Column' 、值)

python - PyCharm远程调试双SSH