1
我一直在爲RPG遊戲做一個戰鬥測試。無論出於何種原因,我都會收到class has no attribute
錯誤。職業沒有屬性X
任何想法如何解決這個問題?
class Enemy:
def __init__(self, name, H, STR):
self.name = name
self.H = H
self.STR = STR
def is_alive(self):
return self.H > 0
enemyturn = ["1", "2"]
class Goblin(Enemy):
def __init__(self, name, H, STR):
name = "Goblin"
H = 50
STR = 5
這些類是在下面的代碼中使用:
if command == "1":
Goblin.H -= Player.STR
print("You strike the Goblin for {0} damage.".format(Player.STR))
random.choice(enemyturn)
if random.choice == "1":
Player.H -= Goblin.STR
print("The Goblin strikes you for {0} damage.".format(Player.STR))
if random.choice == "2":
pass
Combat()
哪條線返回此錯誤? – Marcin
@Marcin這一個:'Goblin.H - = Player.STR' – Jivan