gpt4 book ai didi

python - python 上的 tic tac toe 程序出现某种错误,弹出黑屏,程序没有响应

转载 作者:太空宇宙 更新时间:2023-11-03 15:16:37 25 4
gpt4 key购买 nike

好吧,我正在尝试构建一个 pvp x o 程序,但每次我启动该程序时,都会出现黑色的 pygame 屏幕,并且程序无法运行,请有人能解释一下问题出在哪里以及我应该如何弥补吗?

import os
import pygame
from pygame.locals import*

pygame.init()

ev = pygame.event.get()
x=0
y=0


window=pygame.display.set_mode((700,700))
background=pygame.image.load('blanc.png')
grille=pygame.image.load('Tic-tac-toe.png')

window.blit(background,(0,0))
window.blit(grille,(50,50))

x=pygame.image.load("X-400.png")

o=pygame.image.load("o.png")

GRID=[0,0,0,0,0,0,0,0,0]
tour=1

a=tour/2



while tour<10:
for event in ev:
while jouer==true:
if a==int(a):
if event.type == MOUSEBUTTON and event.button==3:
pygame.mouse.get_pos(x,y)
if x<189:

if y<192:
window.blit(o,(50,50))
GRID[1]=2
elif 275<y<382:
window.blit(o,(50,275))
GRID[4]=2
elif y>468:
window.blit(o,(50,468))
GRID[7]=2
elif 275<x<377:
if y<192:
window.blit(o,(275,50))
GRID[2]=2
elif 275<y<382:
window.blit(o,(275,275))
GRID[5]=2
elif y>468:
window.blit(o,(275,468))
GRID[8]=2
elif x>461:
if y<192:
window.blit(o,(461,50))
GRID[3]=2
elif 275<y<382:
window.blit(o,(461,275))
GRID[6]=2
elif y>468:
window.blit(o,(461,468))
GRID[9]=2
tour=tour+1
elif a!=int(a):
if event.type== MOUSEBUTONDOWN and event.button== 1:
pygame.mouse.get_pos(x,y)
if x<189:

if y<192 and GRID[1]==0:
window.blit(X-400,(50,50))
GRID[1]=1
elif 275<y<382:
window.blit(X-400,(50,275))
GRID[4]=1
elif y>468:
window.blit(X-400,(50,468))
GRID[7]=1
elif 275<x<377:
if y<192:
window.blit(X-400,(275,50))
GRID[2]=1
elif 275<y<382:
window.blit(X-400,(275,275))
GRID[5]=1
elif y>468:
window.blit(X-400,(275,468))
GRID[8]=1
elif x>461:
if y<192:
window.blit(X-400,(461,50))
GRID[3]=1
elif 275<y<382:
window.blit(X-400,(461,275))
GRID[6]=1
elif y>468:
window.blit(X-400,(461,468))
GRID[9]=1
tour=tour+1

pygame.display.flip()

最佳答案

现在我只是不明白当我点击时图像如何

import os
import pygame
from pygame.locals import*

pygame.init()

ev = pygame.event.get()




window=pygame.display.set_mode((700,700))
background=pygame.image.load('blanc.png')
grille=pygame.image.load('Tic-tac-toe.png')

window.blit(background,(0,0))
window.blit(grille,(50,50))

XX=pygame.image.load("X-400.png")

o=pygame.image.load("o.png")

GRID=[0,0,0,0,0,0,0,0,0]
tour=1

a=tour/2



while tour<10:
for event in pygame.event.get():
if a==int(a):
if event.type == MOUSEBUTTONDOWN and event.button==3:
pygame.mouse.get_pos(x,y)
if x<189:

if y<192:
window.blit(o,(50,50))
GRID[1]=2
elif 275<y<382:
window.blit(o,(50,275))
GRID[4]=2
elif y>468:
window.blit(o,(50,468))
GRID[7]=2
elif 275<x<377:
if y<192:
window.blit(o,(275,50))
GRID[2]=2
elif 275<y<382:
window.blit(o,(275,275))
GRID[5]=2
elif y>468:
window.blit(o,(275,468))
GRID[8]=2
elif x>461:
if y<192:
window.blit(o,(461,50))
GRID[3]=2
elif 275<y<382:
window.blit(o,(461,275))
GRID[6]=2
elif y>468:
window.blit(o,(461,468))
GRID[9]=2
pygame.display.flip()
tour=tour+1
elif a!=int(a):
if event.type== MOUSEBUTONDOWN and event.button== 1:
pygame.mouse.get_pos(x,y)
if x<189:

if y<192 and GRID[1]==0:
window.blit(XX,(50,50))
GRID[1]=1
elif 275<y<382:
window.blit(XX,(50,275))
GRID[4]=1
elif y>468:
window.blit(XX,(50,468))
GRID[7]=1
elif 275<x<377:
if y<192:
window.blit(XX,(275,50))
GRID[2]=1
elif 275<y<382:
window.blit(XX,(275,275))
GRID[5]=1
elif y>468:
window.blit(XX,(275,468))
GRID[8]=1
elif x>461:
if y<192:
window.blit(XX,(461,50))
GRID[3]=1
elif 275<y<382:
window.blit(XX,(461,275))
GRID[6]=1
elif y>468:
window.blit(XX,(461,468))
GRID[9]=1
pygame.display.flip()
tour=tour+1


fps=15

关于python - python 上的 tic tac toe 程序出现某种错误,弹出黑屏,程序没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43832899/

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