我的游戏陷入了循环,并且在self.custom_input
中的最后def __init__(self):
之后没有继续。为什么从头开始重新启动而不是调用game()
?
class game(object):
def __init__(self):
self.Continue = None
self.game = None
self.score = score()
while self.Continue == None:
self.Continue = raw_input("Question")
print "Good Luck...."
while self.game not in ("no", "quit", "leave", "n"):
self.rounds = self.custom_input("How many rounds would you like? ", self.games)
game()
def game(self):
while self.score.rounds != self.rounds:
self.score.rounds += 1
self.user_choice = custom_input("question",self.plays)
self.computer_choice = computer_choice()
result = evaluate()
if result == "win":
print "statement" %(self.user_choice.capitalize(), self.computer_choice)
self.score.wins += 1
elif result == "loss":
print "statement" %(self.computer_choice.capitalize(), self.user_choice)
self.score.losses += 1
else:
print "statement" %(self.user_choice.capitalize())
self.draws += 1
self.score.rounds += 1
finals()
答案 0 :(得分:2)
您已将game.game
函数命名为game
类,以及self.game
属性,并且解释器假设您正在尝试创建game
类的新实例。要解决此问题,请尝试将game
函数重命名为play_game
,然后执行以下操作:
self.play_game()