[英]Why doesn't my program go to game()?
My game gets caught in a loop and doesn't continue after the last self.custom_input
in def __init__(self):
. 我的游戏陷入了一个循环,并且在def __init__(self):
的最后一次self.custom_input
之后无法继续进行。 Why does it restart from the beginning instead of calling game()
? 为什么它从头开始而不是调用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()
You've named the game.game
function with the same name as the game
class, as well as the self.game
attribute, and the interpreter is assuming that you're trying to create a new instance of the game
class. 您已经使用与game
类相同的名称以及self.game
属性来命名game.game
函数,并且解释器假定您正在尝试创建game
类的新实例。 To fix this, try renaming the game
function to play_game
, and then do this: 要解决此问题,请尝试将game
功能重命名为play_game
,然后执行以下操作:
self.play_game()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.