一直在尝试让某些精灵工作的字典。

class Player(Digimon):
def __init__(self):
    super(Player, self).__init__(0,2,0,0,0,0) # age, weight, str, def, speed, intelligence
    self.image_dict = {(0,2,0,0,0,0): itertools.cycle([pygame.image.load("images/egg_sprite_1.png"),
                                                   pygame.image.load("images/egg_sprite_2.png"),
                                                   pygame.image.load("images/egg_sprite_3.png")]),
                   (2,4,0,0,2,5): itertools.cycle([pygame.image.load("images/leaf_1.png"),
                                                    pygame.image.load("images/leaf_2.png"),
                                                    pygame.image.load("images/leaf_3.png"),
                                                    pygame.image.load("images/leaf_4.png")])}


然后在主循环中

Player.images = Player.image_dict[(Player.age, Player.weight, Player.strength, Player.defence, Player.speed, Player.intelligence)]

Player.image = next(Player.images)


我得到标题中指出的错误。我看过类似的问题,但它们似乎无济于事。据我所知,它应该工作。 Player.image_dict是在Player(digimon)子类中创建的,所以我不知道如何没有属性。

最佳答案

好了,您实际上需要创建Player类的实例,如下所示:

player = Player()

然后,您可以致电:

player.images = player.image_dict[(player.age, player.weight, player.strength, player.defence, player.speed, player.intelligence)]

player.image = next(player.images)


请注意,这些是player对象,而不是Player

关于python - AtrributeError:类型对象“玩家”没有属性“image_dict”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22578711/

10-14 17:45