def startgame():
start.state = False
print start.state
def restart():
end.state = False
start.state = True
print game.state, end.state
s.listen()
s.onkey(startgame, "Return")
s.onkey(restart, 'r')
# This Loop stops when you hit Enter
while start.state:
start.enter()
s.reset()
# I tried repeating it here but it doesn't work
while end.state:
end.enter()
s.reset()
game.state = 'playing'
两个循环都嵌套在一个主while循环中,但第二个循环嵌套在另一个while循环中(如果有帮助的话)所以它看起来像这样
while True:
while start.state:
start.flash()
s.reset()
while True:
# main game code here
while end.state:
end.flash()
s.reset()
game.state = 'playing'
break
我只是希望它显示结束屏幕并让“按 r 再次播放”在屏幕上闪烁,直到玩家点击 r,然后它应该重新启动游戏并返回开始屏幕。该end.state
变量不会在 while 循环期间更新,但start.state
会在其 while 循环期间更新。