我已經使用了這個錯誤,並且不明白它是什麼。我正在嘗試做一個簡單的遊戲,並且我不允許我稱之爲攻擊方法。Python class'int'object not callable
這是該行它說的錯誤是:
enemy.attack(player1)
if player1.dead == True:
print "You have lost"
這是方法:
def attack(self, player):
#defend = randint(0,10)
damage = randint(0, self.strength)
if damage == 0:
print "You missed"
elif damage < self.strength:
print "Hit for", damage,"damage."
player.health = player.health - damage
elif damage == self.strength:
print "Critical hit!"
player.health = player.health - (damage + 2)
player.check_dead(player)
如果您需要了解代碼請詢問更多的信息。我不確定我打算給你什麼信息,因爲我不明白錯誤。
錯誤控制檯:
Your health: 100
Attack or Heal attack
Hit for 3 damage.
97
Traceback (most recent call last):
File "E:\Computing\player.py", line 119, in <module>
enemy.attack()
TypeError: 'int' object is not callable
請發佈完整回溯(控制檯中的錯誤) –
請將類別敵人和播放器發佈到源.. –