为什么我的程序没有进入游戏()?

时间:2015-11-03 23:23:25

标签: python

我的游戏陷入了循环,并且在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()

1 个答案:

答案 0 :(得分:2)

您已将game.game函数命名为game类,以及self.game属性,并且解释器假设您正在尝试创建game类的新实例。要解决此问题,请尝试将game函数重命名为play_game,然后执行以下操作:

self.play_game()