I have this code that gives me weird errors. Below you should see that code. First of i have my CombatEngine that basically just simulates a shoot out between me the player and the list of enemies. In the class TheBridge i make a instance of the combatengine and give it a list of enemies in the constructor(i code mostly in c#) but when i run the the combat method on the engine an error will be returned
AttributeError: type object 'GothonTrooper' has no attribute 'health'
I really dont understand how that is possible when its clear that health is defined for the GothonTrooper class. I suppose the error occurs in the combat method itself some point around when the individual enemy is found from the randint function.
class TheBridge(Scene):
def __init__(self):
enemies = [GothonTrooper(), GothonTrooper(), GothonTrooper(), GothonTrooper, GothonTrooper()]
self.the_bridge_combat = CombatEngine(enemies)
...
class CombatEngine(object):
def __init__(self, enemies):
self.enemies = enemies
while len(self.enemies) != 0:
enemy = self.enemies[randint(0, len(self.enemies)-1)]
print "You shoot at the Gothon."
hit_or_miss = PLAYER.attack()
if hit_or_miss >= 5:
print "The shot hits the Gothon!"
enemy.health -= 10
print "The Gothon is down to %s health" % enemy.health
...
class GothonTrooper(Humanoid):
def __init__(self):
self.health = 100
def attack(self):
return randint(1,10)
GothonTrooperin yourenemieslist?