3 回答
TA贡献1806条经验 获得超5个赞
我无法完全回答你的问题,因为很高兴看到整个代码,但我肯定会将其更改为:
while game_close:
self.dis.fill(colors("blue"))
self.message("You Lost! Press C-Play Again or Q-Quit", colors("red"))
self.Your_score(Length_of_snake - 1)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_close = True
game_over = True
# exit()
keys = pygame.key.get_pressed()
if keys[pygame.K_q]:
game_over = True
game_close = False
if keys[pygame.K_c]:
game_close = False
self.gameLoop()
TA贡献1827条经验 获得超4个赞
未包含整个代码,缺少一个类,并且未定义一些方法。但首先我建议将所有按键更改为:
keys = pygame.key.get_pressed()
if keys[pygame.K_yourkey]:
# do something
if keys[pygame.K_yourotherkey]:
# do something
# and so on
并且不要将其放入事件 for 循环中
TA贡献1735条经验 获得超5个赞
尝试改成这样
for event in pygame.event.get():
if event.type == pygame.KEYUP:
if event.key == pygame.K_q:
game_over = True
game_close = False
elif event.key == pygame.K_c:
game_close = False
self.gameLoop()
添加回答
举报