Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 需要其他方法来停止我的游戏(pygame)!_Python_Crash_Pygame_Infinite Loop - Fatal编程技术网

Python 需要其他方法来停止我的游戏(pygame)!

Python 需要其他方法来停止我的游戏(pygame)!,python,crash,pygame,infinite-loop,Python,Crash,Pygame,Infinite Loop,当计时器结束时,我希望显示“游戏结束”文本,并停止执行其他所有内容。我的程序在第65行崩溃(我的游戏循环中的while循环,after time==0)。除了无限循环之外,还有什么其他方法可以做到这一点 import pygame, sys from pygame.locals import * pygame.init() FPS = 100 fpsClock = pygame.time.Clock() DISPLAYSURF = pygame.display.set_mode((500,

当计时器结束时,我希望显示“游戏结束”文本,并停止执行其他所有内容。我的程序在第65行崩溃(我的游戏循环中的while循环,after time==0)。除了无限循环之外,还有什么其他方法可以做到这一点

import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 100
fpsClock = pygame.time.Clock()

DISPLAYSURF = pygame.display.set_mode((500, 500))
pygame.display.set_caption('Cookie Clicker')

cookie = pygame.image.load('cookie.png')
cookieX = 95
cookieY = 65
bgColor = (56, 142, 142)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)

pygame.mixer.music.load('Grind.mp3')
pygame.mixer.music.play(-1, 10.2)

text = '0'
fontObj = pygame.font.Font('freesansbold.ttf', 35)
textSurfaceObj = fontObj.render(text, True, BLACK)
textRectObj = textSurfaceObj.get_rect()
textRectObj.center = (250, 420)

time = 2
seconds = ' seconds'
fontObj2 = pygame.font.Font('freesansbold.ttf', 35)
textSurfaceObj2 = fontObj2.render(str(time)+seconds, True, BLACK)
textRectObj2 = textSurfaceObj2.get_rect()
textRectObj2.center = (370, 30) 

pygame.time.set_timer(USEREVENT+1, 1000)

gameover = 'Game Over'
fontObj3 = pygame.font.Font('freesansbold.ttf', 72)
textSurfaceObj3 = fontObj3.render(gameover, True, BLACK, WHITE)
textRectObj3 = textSurfaceObj3.get_rect()
textRectObj3.center = (250, 250) 

#game-loop
while True:
    DISPLAYSURF.fill(bgColor)
    DISPLAYSURF.blit(cookie, (cookieX, cookieY))
    DISPLAYSURF.blit(textSurfaceObj, textRectObj)
    DISPLAYSURF.blit(textSurfaceObj2, textRectObj2)

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == MOUSEBUTTONDOWN:
            temp = int(text)
            temp += 1
            text = str(temp)
        if event.type == USEREVENT+1:
            time -= 1
            if time == 0:
                textSurfaceObj2 = fontObj2.render(str(time)+seconds, True, BLACK)
                DISPLAYSURF.blit(textSurfaceObj2, textRectObj2)
                DISPLAYSURF.blit(textSurfaceObj3, textRectObj3)
                pygame.display.update()
                while True:
                    pass


    textSurfaceObj = fontObj.render(text, True, BLACK)

    textSurfaceObj2 = fontObj2.render(str(time)+seconds, True, BLACK) 

    pygame.display.update()

    fpsClock.tick(FPS)

你就不能在时间>0的时候做一些类似于
的事情吗