2013-04-23 3 views
0

파이 게임으로 내 텍스트 기반 블랙 잭 게임에 열중하고 있습니다. 나는 플레이어의 손을 업데이트 할 수 없다. 때마다 그것을 그냥 이전 텍스트를 통해 추가하고 읽을 수 없게됩니다. 여기 파이 게임에서 동적으로 업데이트되는 점수를 만드는 데 도움이 필요합니다.

코드의 관련 부분이다 : 나는 중요한 뭔가를 놓친 경우

여기
def update(player, comp): 
drawText('Money: $%s' % (money), font, windowSurface, 50, 30) 
drawText('Press "H" to hit. Press S to stand', font2, windowSurface, 500, (30)) 
drawText('Player Total: %s' % (sumHand(player)), font2, windowSurface, 500, (50)) 
drawText('Dealer Total: %s' % (sumHand(comp)), font2, windowSurface, 650, (50)) 
pygame.display.update() 


     while True: 
     update(player, comp) 
     mainClock.tick(FPS) 
     if sumHand(player) < 22: 
      pygame.display.update() 
      hCount += 1 
      print('Your cards are: %s with a total value of %d' % (player,sumHand(player))) #old 
      print('The dealers visible card is %s' % (comp)) #old 
      print('Hit or Stand?') #old 
      for event in pygame.event.get(): 
       event = waitForPlayerToPressKey() 
       if event.key == ord('h') and hCount == 0: 
        player.append(getCard(cards)) 
        cardPrint3(player) 
        update(player, comp) 
       elif event.key == ord('h') and hCount == 1: 
        player.append(getCard(cards)) 
        cardPrint4(player) 
        update(player, comp) 
       elif event.key == ord('h') and hCount == 2: 
        player.append(getCard(cards)) 
        cardPrint5(player) 
        update(player, comp) 
       elif event.key == ord('h') and hCount == 3: 
        player.append(getCard(cards)) 
        cardPrint6(player) 
        update(player, comp) 
        break 
        money+=500 
       else: 
        break 
      else: 
       break 

전체 프로그램의 페이스트 빈입니다. http://pastebin.com/70EhteQ1

답변

1

다시 그리기를 시작하기 전에 화면 또는 적어도 관련 부분을 "지워야"합니다. 그렇지 않으면 기존 도면을 그려야합니다. 루프 상단에서 다음을 시도해보십시오.

while True: 
    windowSurface.fill((255, 255, 255)) # this will draw over the entire screen surface with white 
    update(player, comp) 
    ... 
+0

어떻게 그렇게하면 화면의 특정 부분에만 표시됩니까? – user2312690

+0

표면의 'blit()'함수를 호출 할 때마다 'Rect'가 반환됩니다. 그것들을 추적한다면 코드가 복잡해질 수 있지만 화면의 관련 부분 만 그릴 수 있습니다. 또한,'pygame.display.update()'는 인자로'Rects'의리스트를 받아들입니다. 그 영역을 다시 그리기 만 할 수 있습니다. (원하지 않으면 그 부분을 지우기 전에 여전히 그 부분을 지울 필요가 있습니다. "산책로"또는 뒤죽박죽 텍스트). – Haz

+0

솔직히, 알려진 성능 문제가 없으면 각 프레임 전체 화면을 지우고 모든 구성 요소를 다시 그릴 것을 제안합니다. 그것은 당신을 위해 훨씬 덜 두통이 될 것입니다. – Haz

관련 문제