我在尝试编写游戏的过程中遇到了这个严重错误。目前,这只是骨头,我正在尝试为玩家战斗的敌人之一编码信息。
class Enemy():
def __init__(self):
super(). __init__ (
self.name = "Goblin" +
self.healthpoints = 12 + # on this line
self.damage = 3)
def isAlive(self):
return self.hp > 0
self.name = "Goblin" +
是语法错误。您没有在"Goblin"
中添加任何内容。它抱怨后面的行的原因是它试图将self.healthpoints = 12
添加到"Goblin"
,并且您无法添加赋值语句。
我认为您想做的是这样的:
def __init__(self):
self.name = "Goblin"
self.healthpoints = 12
self.damage = 3
您是要这样做吗?
class Enemy():
def __init__(self):
self.name = "Goblin"
self.healthpoints = 12
self.damage = 3
super().__init__(name=self.name, healthpoints=self.healthpoints, damage=self.damage)
enter code here
def isAlive(self):
return self.hp > 0
```