我们的游戏将不会重新开始。我们希望它在用户在最终屏幕上按Y时再次启动。我们怀疑这与while循环有关。我们的错误在哪里?
我们已经尝试过在循环开始处放置KeepGoing == False,并且已经尝试了循环中每个变量的所有布尔值。
#用于选择游戏是否结束: keepGoing =真 选择=错误
clock = pygame.time.Clock()
screen.fill(GREEN)
# Set vars
font = pygame.font.SysFont("Comic Sans MS", 20)
done = False
display_end = True
end_page = 1
#Loop to keep the pages going:
while not done and display_end:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.MOUSEBUTTONDOWN:
end_page += 1
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_y:
choice = True
if event.key == pygame.K_n:
keepGoing = False
pygame.display.flip()
# Set the screen background
screen.fill(GREEN)
if end_page == 1:
text = font.render("You lose :( Score: "+str(score)+" points", True, BLACK)
text2 = font.render("Do you want to play again?", True, BLACK)
text3 = font.render("If no, click once. If yes, press Y.", True, BLACK)
screen.blit(text, [125, 150])
screen.blit(text2, [125, 250])
screen.blit(text3, [125, 350])
pygame.display.flip()
return done