Closed stevenjonas110 closed 3 years ago
while dead:
result()
window.blit(restart, (400, 400))
window.blit(close, (400, 460))
pygame.display.update()
buttons = pygame.mouse.get_pressed()
x1, y1 = pygame.mouse.get_pos()
if x1 >= 400 and x1 <= 600 and y1 >= 400 and y1 <= 454:
window.blit(choose, (350, 400))
if buttons[0]:
window.blit(bg, (0, 0))
return
elif x1 >= 400 and x1 <= 600 and y1 >= 460 and y1 <= 514:
window.blit(choose, (350, 460))
if buttons[0]:
pygame.quit()
sys.exit()
else:
window.blit(blank, (350, 400))
window.blit(blank, (350, 460))
这段代码里有更新 dead
的操作吗?如果不执行 return
或 exit()
就会死循环,检查一下为什么
while dead: result() window.blit(restart, (400, 400)) window.blit(close, (400, 460)) pygame.display.update() buttons = pygame.mouse.get_pressed() x1, y1 = pygame.mouse.get_pos() if x1 >= 400 and x1 <= 600 and y1 >= 400 and y1 <= 454: window.blit(choose, (350, 400)) if buttons[0]: window.blit(bg, (0, 0)) return elif x1 >= 400 and x1 <= 600 and y1 >= 460 and y1 <= 514: window.blit(choose, (350, 460)) if buttons[0]: pygame.quit() sys.exit() else: window.blit(blank, (350, 400)) window.blit(blank, (350, 460))
这段代码里有更新
dead
的操作吗?如果不执行return
或exit()
就会死循环,检查一下为什么
这段代码是游戏已经结束后的界面,让用户选择重新开始还是直接退出游戏,所以应该在用户肯定会在两个if中执行一个的,这个循环只是为了保持最后的游戏结束界面。
你说的第二个 while 循环是这个 while dead:
循环吧,按照你说的不就应该一直循环等待用户选择吗,“死循环” 指的是点按钮不管用?
你说的第二个 while 循环是这个
while dead:
循环吧,按照你说的不就应该一直循环等待用户选择吗,“死循环” 指的是点按钮不管用?
对,只要进入等待用户选择的页面就直接死机了
你说的第二个 while 循环是这个
while dead:
循环吧,按照你说的不就应该一直循环等待用户选择吗,“死循环” 指的是点按钮不管用?对,只要进入等待用户选择的页面就直接死机了
助教这是里面的result函数,还有最后运行卡死的界面
def result(): window.blit(bg, (0, 0)) font = pygame.font.SysFont('Times', 30) text1 = font.render('GAME OVER', True, (0, 0, 255), (255, 255, 255)) window.blit(text1, (300, 200)) text2 = font.render('Your score is:' +str(score), True, (0, 0, 255), (255, 255, 255)) window.blit(text2, (300, 300))