0
我intigrating我的文字为基础的二十一点游戏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
如何做到这一点,所以它只能做到屏幕的某个部分? – user2312690 2013-04-23 21:02:27
每次调用一个表面的'的blit()'函数时,会返回一个'Rect'。如果您跟踪这些,你可以笼络只有屏幕的相关部分,虽然该代码可以变得复杂。另外'pygame.display.update()'接受作为一个参数,它允许你只重绘这些领域(虽然你仍然需要对他们的画任何东西,如果你不想先清除这些板块Rects'的'名单“痕迹”或混乱的文字)。 – Haz 2013-04-23 21:17:55
老实说,如果你没有一个已知的性能问题来处理,我建议你只是清除整个屏幕每一帧并重新绘制所有的组件。这对你来说会少得多头痛。 – Haz 2013-04-23 21:18:46