I am beginner and have a problem with my code.
(我是新手,我的代码有问题。)
Here you can see a short excerpt of my code.(在这里,您可以看到我的代码的简短摘录。)
It's a simple snake game I created but I was trying to add a pause.(这是我创建的一个简单的蛇游戏,但是我试图添加一个暂停。)
I got it but when I start the pause I am not able to close it.(我知道了,但是当我开始暂停时,我无法关闭它。)
Possibly there is a basic mistake in my code so I couldn't advance.(我的代码中可能存在一个基本错误,所以我无法前进。)
I hope you can help me.(我希望你能帮助我。)
Thank you in advance!(先感谢您!)
def checkquit(e):
running = True
pause = False
for ev in e:
if ev.type == pygame.QUIT:
exit(0)
running = True
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
quit(0)
running = True
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_p:
pause = True
while pause:
#running = False
pause = True
red = (255,0,0)
screen = pygame.display.set_mode((800,500))
screen.fill((0,0,0))
myfont=pygame.font.SysFont("monospace",50)
myfonttwo=pygame.font.SysFont("monospace",10)
text1=myfont.render("Pause!",100,red)
text2=myfont.render("Please restart the game",100,red)
screen.blit(text2,(10,200))
screen.blit(text1,(230,100))
pygame.display.update()
for ev in e:
if ev.type == pygame.QUIT:
pause = False
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
pause = False
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_p:
pause = True
ask by Rezan Yilmaz translate from so