0
MAC終端說傳遞兩個位置參數到take_damage方法IM ...位置參數OSX
from enemy import Enemy
random_monster = Enemy("Basic enemy", 12, 1)
print(random_monster)
random_monster.take_damage(4)
print(random_monster)
及其他文件在這裏______________________
class Enemy:
def __init__(self, name="Enemy", hit_points = 0, lives = 1):
self.name = name
self.hit_points = hit_points
self.lives = lives
def take_damage(damage):
remaining_points = self.hit_points - take_damage
if remaining_points >= 0:
self.hit_points = remaining_points
print("i took {} damage and have {} left".format(damage, self.hit_points))
else:
self.lives -= 1
def __str__(self):
return "Name: {0.name}, Lives: {0.lives}, Hitpoints: {0.hit_points}".format(self)
ahh想通了,謝謝你!我也試圖減去take_damage而不是損壞。愚蠢的學習錯誤大聲笑 – KeatonBenning