I'm intigrating my text based blackjack game with pygame. I can't seem to make the total of the player's hand update. Every time it justs adds it over the previous text, and it becomes impossible to read.
我正在将基于文本的二十一点游戏与pygame混合在一起。我似乎无法让玩家的手更新总数。每次它只是将它添加到前一个文本上,就无法阅读。
Here are the relevant sections of code:
以下是相关的代码部分:
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
Here is a pastebin of the full program if I missed something important. http://pastebin.com/70EhteQ1
如果我错过了重要的东西,这是完整程序的pastebin。 http://pastebin.com/70EhteQ1
1 个解决方案
#1
1
You need to "clear" the screen, or at least the relevant portions of it, before you start drawing again. Otherwise you are just drawing over the existing drawing. Try this at the top of your loop:
在重新开始绘图之前,您需要“清除”屏幕或至少相关部分。否则你只是绘制现有的绘图。在循环的顶部尝试这个:
while True:
windowSurface.fill((255, 255, 255)) # this will draw over the entire screen surface with white
update(player, comp)
...
#1
1
You need to "clear" the screen, or at least the relevant portions of it, before you start drawing again. Otherwise you are just drawing over the existing drawing. Try this at the top of your loop:
在重新开始绘图之前,您需要“清除”屏幕或至少相关部分。否则你只是绘制现有的绘图。在循环的顶部尝试这个:
while True:
windowSurface.fill((255, 255, 255)) # this will draw over the entire screen surface with white
update(player, comp)
...