当我在 Zombie 类中调用 render() 方法时,我想将 Zombie 对象的一个实例添加到 ZombieList.list 中。当我尝试这样做时,它说
Unresolved attribute reference
listfor 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)
