I am trying to build a turn based battle game but I am encountering a problem with damage infliction.
roomMonsters is a list like: [['A Zombie' , 2 , 2 , 3],['A Zombie , 2 , 2, 3]]
def heroAttack(roomMonsters , heroes):
target = int(input('Which monster shall you attack? ')) #Which monster to attack
attacker = int(input('Which hero shall you attack with? ')) #Which hero to attack with
damage = int(random.randint(int(heroes[attacker][2]) , heroes[attacker][2])*2) #Calculates damage
for number in range(0,damage):
while roomMonsters[target][1] > 0:
roomMonsters[target][1] = roomMonsters[target][1]-1
#print('Debug, inflicting pain')
print('Your' , heroes[attacker][0] , 'attacked' , roomMonsters[target][0] , 'for' , damage , 'damage.') #Prints the result
checkForMonsterDeath(heroes,roomMonsters,attacker,target)
return roomMonsters
I expect the result to inflict damage to one list entry and then stop, so it inflicts damage to the zombie which is attacked.
However, it inflicts the damage to all zombies.I think it may be because the checkForMonsterDeath removes a monster from the list but I cannot see how that leads to the damage being inflicted to all the monsters of the same type.
Gameplay looks like this accordingly:
You enter the room and monsters lie ahead of you...
You can see:
0 A Zombie with 2 HP.
1 A Spider with 5 HP.
2 A Zombie with 2 HP.
Which monster shall you attack? 0
Which hero shall you attack with? 1
Your Wielder of Zzzzap attacked A Zombie for 14 damage.
A Zombie exploded in a fiery ball of gloop.
You enter the room and monsters lie ahead of you...
You can see:
0 A Spider with 5 HP.
1 A Zombie with 0 HP.
As you can see the damage is inflicted to all the zombies, not just the one who was attacked.
Apologies for any bad formatting, this is my first time here and thanks for your help.