我正在学习Python并从内存中重新创建我在Visual Basic中创建的旧程序。
大多数事情都运作正常,但我知道必须有一个更好的方式来宣布胜利者。目标是让2-4支队伍嗡嗡作响并获得问题分数。得分最高的球队获胜。
现在这就是胜利的代码看起来像,但我觉得它非常混乱,必须是更好的方式。
elif event.key == pygame.K_w:
if Team1Point > Team2Point and Team1Point > Team3Point and Team1Point > Team4Point:
Win = True
win.play()
while Win:
gameDisplay.blit(boardwin,(0,0))
text = large_font.render(str(Team1Name)+" Wins!", True, black)
gameDisplay.blit(text, [display_width/2, display_height/2])
pygame.display.update()
clock.tick(5)
gameDisplay.blit(background,(0,0))
pygame.display.update()
clock.tick(5)
elif Team2Point > Team1Point and Team2Point > Team3Point and Team2Point > Team4Point:
Win = True
win.play()
while Win:
gameDisplay.blit(boardwin,(0,0))
text = large_font.render(str(Team2Name)+" Wins!", True, black)
gameDisplay.blit(text, [display_width/2, display_height/2])
pygame.display.update()
clock.tick(5)
gameDisplay.blit(background,(0,0))
pygame.display.update()
clock.tick(5)
elif Team3Point > Team2Point and Team3Point > Team1Point and Team3Point > Team4Point:
Win = True
win.play()
while Win:
gameDisplay.blit(boardwin,(0,0))
text = large_font.render(str(Team3Name)+" Wins!", True, black)
gameDisplay.blit(text, [display_width/2, display_height/2])
pygame.display.update()
clock.tick(5)
gameDisplay.blit(background,(0,0))
pygame.display.update()
clock.tick(5)
elif Team4Point > Team2Point and Team4Point > Team3Point and Team4Point > Team1Point:
Win = True
win.play()
while Win:
gameDisplay.blit(boardwin,(0,0))
text = large_font.render(str(Team4Name)+" Wins!", True, black)
gameDisplay.blit(text, [display_width/2, display_height/2])
pygame.display.update()
clock.tick(5)
gameDisplay.blit(background,(0,0))
pygame.display.update()
clock.tick(5)
elif Team1Point == Team2Point or Team1Point == Team3Point or Team1Point == Team4Point or Team2Point == Team3Point or Team2Point == Team4Point or Team3Point == Team4Point:
Win = True
win.play()
while Win:
gameDisplay.blit(boardwin,(0,0))
text = large_font.render("Tie Win!", True, black)
gameDisplay.blit(text, [display_width/2, display_height/2])
pygame.display.update()
clock.tick(5)
gameDisplay.blit(background,(0,0))
pygame.display.update()
clock.tick(5)
我尝试使用以下内容定义Win,但收到
错误:TypeError: Win() missing 1 required positional argument: 'Team1Name'
TypeError: Win() missing 1 required positional argument: 'Team1Name'
我没有收到错误,我的代码创建了名称并将其放在屏幕上:
def Win():
win.play()
Win = True
while Win:
gameDisplay.blit(boardwin,(0,0))
text = large_font.render(str(Team1Name)+" Wins!", True, white)
gameDisplay.blit(text, [display_width/2, display_height/2])
pygame.display.update()
clock.tick(5)
gameDisplay.blit(background,(0,0))
pygame.display.update()
clock.tick(5)
关于如何清理它的想法?也许我只是盯着我的屏幕太久了。
答案 0 :(得分:0)
我发现了这个问题。我需要将DEF项目放入循环中。
我在工作时大声说话时也玩过很多次。它让我意识到如何清理我的代码。我还将用户从4减少到2,因为我多年前制作的硬件中只有2个工作。
我从上面走到下面:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
gameOver = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
answer.play()
BlinkLeftImage()
Team1Answer()
elif event.key == pygame.K_2:
answer.play()
BlinkRightImage()
Team2Answer()
elif event.key == pygame.K_h:
Help()
elif event.key == pygame.K_w:
win.play()
Win()
elif event.key == pygame.K_q:
pygame.quit()
quit()
我现在还有另一个问题。有没有办法锚定(术语可能是错误的)文本blit?
目前我的代码是:
def Team2(Team2Name,Team2Point):
if display_width <= 800:
text = small_font.render(str(Team2Name)+": " + str(Team2Point), True, red)
gameDisplay.blit(text, [((display_width/4)*3),10])
elif display_width <= 1200:
text = medium_font.render(str(Team2Name)+": " + str(Team2Point), True, red)
gameDisplay.blit(text, [((display_width/4)*3),10])
elif display_width >= 1440:
text = large_font.render(str(Team2Name)+": " + str(Team2Point), True, red)
gameDisplay.blit(text, [((display_width/4)*3),10])
哪种方法很好,有点但是文字没有正确排列。我不确定是否有办法在python中自动缩放对象。猜猜这是我的下一个努力!