[英]Need help creating a dynamically updating score in pygame
我正在用pygame來啟動基於文本的二十一點游戲。 我似乎無法全部更新玩家的手牌。 每次它只是將其添加到以前的文本中,就變得不可能閱讀。
以下是相關代碼部分:
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
在再次開始繪制之前,您需要“清除”屏幕或至少屏幕的相關部分。 否則,您只是在現有圖形上繪制。 在循環的頂部嘗試一下:
while True:
windowSurface.fill((255, 255, 255)) # this will draw over the entire screen surface with white
update(player, comp)
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.