This is a very peculiar problem I am having. This code (below) raises no error, but doesn't update and show the move, by player or computer.
What is the the problem?? I am really confused.
Also, All functions that are not defined in this code are imported from TicTacToe and Work!
There is no problem with the game logic functions, the problem is with the display(pygame) code.
Inputs are currently from console
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
In one of the runs(On IDLE),
player is ' O ', computer is ' 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'
Here's the pygame window, It stays the same at all times.