My game gets caught in a loop and doesn't continue after the last self.custom_input
in def __init__(self):
. Why does it restart from the beginning instead of calling 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. To fix this, try renaming the game
function to play_game
, and then do this:
self.play_game()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.