0

这是我遇到的一个非常特殊的问题。此代码(如下)不会引发错误,但不会更新并显示玩家或计算机的移动。
有什么问题??我真的很困惑。
此外,此代码中未定义的所有功能均从井字游戏和工作中导入!
游戏逻辑功能没有问题,问题在于显示(pygame)代码。
输入当前来自控制台

from TicTacToe import * # The game logic functions
import pygame
from pygame.locals import *
#-------------The problem may be here---------------#
def printb(board,surface,image): 
    surface.blit(image,(0,0))
    for x in range(3):
        for y in range(3):
            disp(board[x+(y*3)],(58*x,58*y+13),surface)  # any inputs on a better way to do this??
#-------------The problem may be here---------------#
def disp(phrase,loc,screen):
    s = font.render(phrase, True, (0,0,0))
    screen.blit(s, loc)

if __name__ == '__main__':
    # Pygame
    pygame.init()
    pygame.font.init()

    screen = pygame.display.set_mode((200,250))
    screen.fill((0,255,0))

    img = pygame.image.load('Board.png')
    img = img.convert_alpha()

    font = pygame.font.SysFont("Courier",11)
#----------The problem may even be here---------------#
    # Game
    board = [' ']*9
    playing = True
    while True:
        while True:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()

            printb(board,screen,img)

            pmove = playermove(board) # player move
            makemove(board,pmove,'O')

            if checkwinner(board,'O'):
                winner = 'P'
                break

            else:
                if boardfull(board):
                    break
                cmove = compmove(board) # comp move
                makemove(board,cmove,'X')

                if checkwinner(board,'X'):
                    winner = 'C'
                    break

            pygame.display.flip()
        printb(board,screen,img)
        if winner == 'P':
            print 'You'
        elif winner == 'C':
            print 'I'
        else:
            print'Draw'
        if playagain():
            board = [' ']*9
            print '\n\n'
        else:
            break

在其中一次运行中(在空闲时),玩家是' O ',计算机是' X '

>>> 
Enter Your Move: 1
Enter Your Move: 2
Enter Your Move: 3
Not free space!!
Enter Your Move: 4
I Win !!
Play Again? -> n
>>> board
['O', 'O', 'X', 'O', ' ', 'X', ' ', ' ', 'X']
>>> winner
'C'

这是 pygame 窗口,它始终保持不变。
窗户

4

0 回答 0