如何更改代码以使其显示在屏幕上


def victory_screen():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
screen.fill(WHITE)
largeText = pygame.font.Font(None,50)
screen.blit(largeText.render("Congratulations!",True,BLUE),(135,40))
largeText = pygame.font.Font(None,35)
screen.blit(largeText.render("You have completed the game!", True, BLUE), (205,90))
button("Try Beat me again", 130, 250, 150, 60, RED, GREEN, menu)
button("Quit", 130, 250, 150, 60, RED, GREEN, quit_game)
pygame.display.update()
pygame.display.flip()
clock.tick(frame_rate)
def instructions_screen():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
screen.fill(WHITE)
largeText = pygame.font.Font(None,50)
smallText = pygame.font.Font(None, 35)
screen.blit(largeText.render("Instructions", True, BLUE), (181, 50))
screen.blit(smallText.render("Goal of the game: Reach to 7 points first", True, BLACK), (148, 150))
screen.blit(smallText.render("How to move: Upper arrow - up", True, BLACK), (148, 210))
screen.blit(smallText.render("Lower arrow - down", True, BLACK), (429, 250))
button("Play", 240, 250, 150, 60, GREEN, BLACK, menu)
pygame.display.flip()
clock.tick(60)
def front_page():
next_screen = None
def start_game():
nonlocal next_screen
next_screen = menu
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
if next_screen is not None:
return next_screen
screen.fill(WHITE)
screen.blit(image1, (0,0))
largeText = pygame.font.Font(None, 65)
screen.blit(largeText.render("Wizard mania", True, BLUE),(240,50))
button("Start", 225, 200, 150, 60, GREEN, BLACK, start_game)
button("Quit", 225,250, 150, 60, GREEN, BLACK, quit_game)
button("Controls", 225, 300, 150, 60, GREEN, BLACK, instructions_screen)
pygame.display.flip()
clock.tick(frame_rate)
def menu():
vel = 4
ply1 = pygame.Rect(40, 45, 30, 30)
keys = pygame.key.get_pressed()

scoreA = 0
scoreB = 0

lefthandwalls = [
LeftHandwall(0, 545, 10, 5)
]
righthandwalls = [
RightHandwall(0, 545, 10, 5)
]
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game
keys = pygame.key.get_pressed()
if keys[pygame.K_UP] and ply1.y > 0:
ply1.y -= vel
if keys[pygame.K_DOWN] and ply1.y < 600 - ply1.height:
ply1.y += vel
for lefthandwalls in LeftHandwall:
if ply1.colliderect(lefthandwalls):
scoreB = scoreB + 1
print(scoreB)
if ply1.colliderect(righthandwalls):
scoreA = scoreA + 1
print(scoreA)
if scoreA == 7:
print("You have won the game")
victory_screen
screen.fill(WHITE)
for lefthandwalls in LeftHandwall:
pygame.draw.rect(screen, BLACK, lefthandwalls)
for righthandwalls in RightHandwall:
pygame.draw.rect(screen, BLACK, righthandwalls)
pygame.display.flip()
clock.tick(60)
def main():
scene = front_page
while scene is not None:
scene = scene()
main()
pygame.quit()


我正在为我的计算机科学项目用pygame编写一个乒乓球游戏。我预计游戏将从头版开始;"开始";按下则进入游戏;控件";按下一个教程将显示;退出";按下它,游戏结束。然而,我只得到一个黑屏

您必须调用front_page函数:

scene = front_page

scene = front_page()

相关内容

  • 没有找到相关文章

最新更新