pygame.display.update()
如果此行已注释掉,则会在下一行引发新的语法错误;违规代码:
if isItSnap(middleDeck):
我查看了这篇文章 - 'pygame' is not defined - 但答案并不适用。
如果我要发布整个节目,请告诉我。 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
答案 0 :(得分:0)
该问题是由拼写错误引起的。
之后缺少右括号windowSurface.blit(card, (displayRect.centerx - CARDX, displayRect.centery - CARDY)
windowSurface.blit(card, (displayRect.centerx - CARDX, displayRect.centery - CARDY))