pygame не определен, теперь просто синтаксическая ошибка

Надеюсь, вы, ребята, можете помочь. Первоначально ошибка, вызванная оболочкой, была «nameError:« pygame »не определена», что казалось странным, поскольку без слишком больших изменений мой код ранее работал нормально. Теперь, после возни с кодом — комментирования строк, ничего особенного — выполнение его из режима ожидания Python вызывает основную синтаксическую ошибку. код нарушения:

pygame.display.update()

Если эта строка закомментирована, то в следующей строке возникает новая синтаксическая ошибка; код нарушения:

if isItSnap(middleDeck):

Я просмотрел этот пост - 'pygame' не определен - но ответ не применим.

Пожалуйста, дайте мне знать, если я должен опубликовать всю программу. pygame, конечно же, был импортирован и инициализирован.

#loop for actual gameplay
while True:
    for event in pygame.event.get():
        #event.type, check identifier the 'type' of event it is
        #pygame.QUIT, all 'type's that an event can be are stored as constants
        #in pygame.locals module in fact the 'pygame' preceeding QUIT is unnecessary
        #QUIT is contant variable in pygame.locals module. now in our global namespace
        #finally to generate an event with type 'QUIT' user clicks red boxed cross on window
        if event.type == pygame.QUIT:
            terminate()
        if event.type == pygame.KEYDOWN and event.key == K_ESCAPE:
            terminate()
        if event.type == pygame.KEYDOWN:#check
            if event.key == pygame.turnCardButton:#anyone can turn card over
                #lets us know user wants to flip card
                turnCard = True

    #turn card, only for computer atm
    if turnCard:
        turnCard(currentPlayer, middleDeck)
        turnCard = False

    #draw everything to screen, only need to blit latest card, no need whole screen
    #or draw everything end prog just draw the latest card here???
    windowSurface.fill(GREEN)#clear screen
    displayRect = windowSurface.get_rect()
    for cards in middleDeck:
        card = pygame.image.load(imageLocator[cards])
        #atm there is no rotation, all cards aligned perfectly
        windowSurface.blit(card, (displayRect.centerx - CARDX, displayRect.centery - CARDY)

    #update screen for user, this when they will try call snap
    pygame.display.update()

    if isItSnap(middleDeck):
        #need users to see card before we enter into loop
        #check rules snap, maybe need to timer if noone called can continue turning cards
        #clear event list as we want to find player with the QUICK DRAW YEEHAA
        pygame.event.clear()
        while True:
            #CURRENTLY NO SCORE CALLING SLOW IN PLAY
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    #who has one this round!?
                    if event.key == playerOneSnapButton:
                        #player one takes all the cards
                        player1 = middleDeck + player1
                        middleDeck = []
                        #just for now UNTIL ALL DRAWING HAS BEEN OPTIMIZED
                        windowSurface.fill(GREEN)
                        pygame.display.update()
                        break

                    elif event.key == playerTwoSnapButton:
                        player2 = middleDeck + player2
                        middleDeck = []
                        windowSurface.fill(GREEN)
                        pygame.display.update()
                        break                               
    else:
        time.sleep(playSpeed)#to slow game a little

person Daniel Kidd    schedule 12.12.2014    source источник
comment
Похоже, вы пропустили ) в предыдущей строке, windowSurface.blit(card, (displayRect.centerx - CARDX, displayRect.centery - CARDY)   -  person KSab    schedule 12.12.2014
comment
О ДА, спасибо добрый незнакомец.   -  person Daniel Kidd    schedule 12.12.2014


Ответы (1)


Проблема вызвана опечаткой. Закрывающая скобка отсутствует после

windowSurface.blit(card, (displayRect.centerx - CARDX, displayRect.centery - CARDY)

windowSurface.blit(card, (displayRect.centerx - CARDX, displayRect.centery - CARDY))
person Community    schedule 31.01.2021