Pygame-Display问题文本没有显示

时间:2013-01-15 15:02:41

标签: python pygame tic-tac-toe

这是我遇到的一个非常特殊的问题。此代码(下面)不会引发任何错误,但不会通过播放器或计算机更新并显示移动 有什么问题?我真的很困惑。
此外,此代码中未定义的所有功能都是从TicTacToe导入的,工作!
游戏逻辑功能没有问题,问题在于显示(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

在其中一个游戏中(On IDLE), 播放器为' 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窗口,它始终保持不变。
The Window

0 个答案:

没有答案