我正在用 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