Błąd: niezwiązana metoda Dragon () musi zostać wywołana z instancją Enemy jako pierwszy argument (zamiast tego dostał instancję Player)
class Character:
def __init__(self):
self.name = ""
self.health = 1
self.health_max = 1
class Player(Character):
def __init__(self):
Character.__init__(self)
self.state = 'normal'
self.health = 10
self.health_max = 10
class Monster(Character):
def Dragon(self):
self.name = "Dragon"
self.health = 20
def Goblin(self):
name = "Goblin"
health = 5
p = Player()
p.name = raw_input("Please enter your name: ")
print p.name
print p.state
print p.health
print p.health_max
m = Monster()
enemy = m.Dragon
print enemy.name
print enemy.health
Przepraszam, zrobiłem to trochę prostsze, aby wyjaśnić, z czym mam problem. Mam trochę problemów z podstawami OOP i mam problem z tym fragmentem kodu. Próbuję utworzyć tutaj „smoka”, ale napotykam następujący błąd:
Śledzenie (ostatnie ostatnie wywołanie): Plik „test2.py”, wiersz 32, w print enemy.name AttributeError: obiekt „function” nie ma atrybutu „name”
Czy możesz mi powiedzieć, co tutaj robię źle? Dzięki.