gpt4 book ai didi

python - Pygame程序在按下红叉后并不总是退出

转载 作者:太空宇宙 更新时间:2023-11-04 01:54:13 26 4
gpt4 key购买 nike

我正在尝试使用 Pygame 制作一个简单的井字游戏。在玩游戏的过程中,有时需要按1次以上的“红叉”才能退出游戏。

while playing is True:
clock.tick(30)
if round_number % 2 == 1:
current_player = 1
else:
current_player = 2

while True:
pygame.event.get()
if pygame.event.get(eventtype=pygame.QUIT):
pygame.quit()
exit()
if pygame.mouse.get_pressed()[0] == 1:
break

while True:
pygame.event.get()
if pygame.mouse.get_pressed()[0] == 0:
break

place_object(current_player, pygame.mouse.get_pos())
print(round_number)
pygame.display.update()
if 7 < pygame.mouse.get_pos()[0] < 393 and 7 < pygame.mouse.get_pos()[1] < 393:
round_number += 1

if round_number >= 3:
if check_win(board) != "No winner" and check_win(board) != "tie":
message = f"The winner is {check_win(board)}!"
message_display(message)
pygame.display.update()
playing = False
elif check_win(board) == "tie":
message_display("Game is tied...")
pygame.display.update()
playing = False

最佳答案

pygame.event.get()返回事件列表并将它们从队列中删除。
你必须循环处理列表,否则你会错过事件:

例如

for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()

关于python - Pygame程序在按下红叉后并不总是退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57265795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com