[英]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.