每次都是Pygame Black Window

时间:2017-05-25 17:29:57

标签: python pygame visualization

每次尝试跑步时都会出现黑屏。有人能指出这个问题吗?我完全不确定可能是什么问题。另外,我在Stack上检查了相同问题的其他解决方案 我的代码:

import sys, os, random, pygame
sys.path.append(os.path.join("objects"))
import SudokuSquare
from GameResources import *

digits = '123456789'
rows = 'ABCDEFGHI'


def play(values_list):
    pygame.init()


    size = width, height = 700, 700
    screen = pygame.display.set_mode(size)

    background_image = pygame.image.load("./images/sudoku-board-bare.jpg").convert()

    clock = pygame.time.Clock()

    # The puzzleNumber sets a seed so either generate
    # a random number to fill in here or accept user
    # input for a duplicatable puzzle.

    for values in values_list:
        pygame.event.pump()
        theSquares = []
        initXLoc = 0
        initYLoc = 0
        startX, startY, editable, number = 0, 0, "N", 0
        for y in range(9):
            for x in range(9):
                if x in (0, 1, 2):  startX = (x * 57) + 38
                if x in (3, 4, 5):  startX = (x * 57) + 99
                if x in (6, 7, 8):  startX = (x * 57) + 159

                if y in (0, 1, 2):  startY = (y * 57) + 35
                if y in (3, 4, 5):  startY = (y * 57) + 100
                if y in (6, 7, 8):  startY = (y * 57) + 165
                col = digits[x]
                row = rows[y]
                string_number = values[row + col]
                if len(string_number) > 1 or string_number == '' or string_number == '.':
                    number = None
                else:
                    number = int(string_number)
                theSquares.append(SudokuSquare.SudokuSquare(number, startX, startY, editable, x, y))

        screen.blit(background_image, (0, 0))
        for num in theSquares:
            num.draw()

        pygame.display.flip()
        pygame.display.update()
        clock.tick(5)

    # leave game showing until closed by user
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

if __name__ == "__main__":
    main()
    sys.exit()

以下代码调用:

from PySudoku import play

def visualize_assignments(assignments):
    """ Visualizes the set of assignments created by the Sudoku AI"""
    last_assignment = None
    filtered_assignments = []

    for i in range(len(assignments)):
        if last_assignment:
            last_assignment_items = [item for item in last_assignment.items() if len(item[1]) == 1]
            current_assignment_items = [item for item in assignments[i].items() if len(item[1]) == 1]
            shared_items = set(last_assignment_items) & set(current_assignment_items)
            if len(shared_items) < len(current_assignment_items):
                filtered_assignments.append(assignments[i])
        last_assignment = assignments[i]

    play(filtered_assignments)

如果需要,我的完整代码可以here

0 个答案:

没有答案