Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sprite.Group()中的对象的行为不像它们应该的那样具有唯一性_Python_For Loop_Pygame_Sprite - Fatal编程技术网

Python sprite.Group()中的对象的行为不像它们应该的那样具有唯一性

Python sprite.Group()中的对象的行为不像它们应该的那样具有唯一性,python,for-loop,pygame,sprite,Python,For Loop,Pygame,Sprite,下面是令人不安的代码,有一个快速分解 if player.attacked == True and delay >= 60: #if it's monster's turn plus a built in delay so everything isn't instant for enemy in enemies_list: #iterating the all the enemies in the sprite group if enemy.attack_rdy

下面是令人不安的代码,有一个快速分解

if player.attacked == True and delay >= 60: #if it's monster's turn plus a built in delay so everything isn't instant
    for enemy in enemies_list: #iterating the all the enemies in the sprite group
        if enemy.attack_rdy == True and enemy.health >0 and delay ==60: #if THAT particular monster hasn't attacked, isn't dead, and the delay has been long enough.
            player.hit.play() #play the player's damaged sound
            damage = random.randrange(each.attack[0],each.attack[1]+1)-player.armor #random attack roll of a tuple assigned to the enemy class
            player.health -= damage 
            enemy.attack_rdy = False #Sets THIS particular enemy so that he may not attack until it's his turn again
            player.damaged = True #Just triggers an animation on the player
            each.attack_anim = 1 #triggers an animation on the enemy
            break #stops the for loop so that everything doesn't happen at once and relies on the delay int.
问题:
这个迭代工作正常,因为玩家根据攻击他的敌人的数量准确地被攻击了正确的次数。然而,出于某种奇怪的原因,同样的敌人会一直在进攻。当进攻的敌人死亡时,另一个敌人简单地接管了他作为进攻者的任务。我完全搞不懂这一点。

以一种真正愚蠢的方式,在盯着我的代码编辑了几个小时后,我发现我的错误仅仅是发布后的瞬间。这真的只是一个愚蠢的错误

each.attack_anim = 1
应该读

enemy.attack_anim = 1
纠正错误后,代码按设计运行