I am quite new programming and have been learning Python, i decided to try and create a text-based adventure through OOP, so far I've managed to overcome issues on my own but I'm stuck on this one problem i just cannot solve, here's the code:
class player:
def __init__(self, name, health):
self.name = name
self.health = health
Player_1 = player ('Bob', 80)
class enemies:
def __init__ (self, description, health, damage):
self.description = description
self.health = health
self.damage = damage
def __str__ (self):
return '{} , {} , {}'.format (self.description, self.health, self.damage)
def enemy_damage (self):
Player_1.health - random_enemy1
return Player_1.health
random_enemy1 = enemies ('Goon', 40, 5)
At the moment I'm just testing this code before applying it fully in the game, when calling the enemy_damage method (random_enemy1.enemy_damage) i can successfully lower the players health by 5, but the issue is that the players health isn't updated, so the next time the enemy_damage method is run, the players health is back to 80.
Can someone please help? How would i get the players health to update here? I have looked at numerous videos and whatnot about class methods etc but cannot wrap my head around this, i know the code is probably terrible for what i'm trying to do, but i'm just looking to get the thing to work at the moment, after which i will use other means to reduce the amount of code and improve on it.
Many thanks
Player_1) toenemy_damageas an argument.Player_1.health - random_enemy1doesn't updatePlayer_1.health(and actually it should even raise a TypeError).