当我在 Zombie 类中调用 render() 方法时,我想将 Zombie 对象的一个实例添加到 ZombieList.list 中。当我尝试这样做时,它说
Unresolved attribute reference
list
for classZombieList
.
我应该尝试另一种方式吗?
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 Objects到 Zombie
类:
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/