import random
class Player:
def __init__(self, name, weapon, strength, health, attack, hero, creature):
self.name = name
self.weapon = weapon
self.strength = 100
self.health = 100
self.attack = 0
self.hero = hero
self.creature = creature
def entername_player(self):
self.name = input("Enter your name: ")
print("Welcome " + self.name + " !")
return self.name
def main():
hero = select_hero()
if __name__ == "__main__":
main()
我试图剖析问题所在,并在添加其他功能之前测试我的一个功能,但我仍然对我的问题是什么感到困惑。
从问题中尚不清楚最终结果需要是什么,但这将修复代码的当前结构:
select_hero()
import random
class Player:
def __init__(self, name, weapon, strength, health, attack, hero, creature):
self.name = name
self.weapon = weapon
self.strength = 100
self.health = 100
self.attack = 0
self.hero = hero
self.creature = creature
def entername_player(self):
self.name = input("Enter your name: ")
print("Welcome " + self.name + " !")
return self.name
def select_hero(self):
...
def main():
p = Player('darren', 'axe', 100, 100, 100, 'the moon', 'dragon')
hero = p.select_hero()
if __name__ == "__main__":
main()