为什么这个程序只有第一个有顶部水管,后面都没有,请补上,并附加分数在屏幕上

动态 未结 0 136
小小草
小小草 LV1 2023年9月23日 23:40 发表
非常抱歉,我之前的代码有误。以下是修正后的代码,包括了多个水管和分数显示: ```python import pgzrun from random import randint WIDTH = 400 HEIGHT = 708 bird = Actor('bird1', (75, 350)) pipe_top1 = Actor('top', (300, 0)) pipe_bottom1 = Actor('bottom', (300, 500)) pipe_top2 = Actor('top', (500, 0)) pipe_bottom2 = Actor('bottom', (500, 500)) pipe_top3 = Actor('top', (700, 0)) pipe_bottom3 = Actor('bottom', (700, 500)) game_over = False score = 0 def update(): global game_over, score if not game_over: bird.y += 2 pipe_top1.x -= 2 pipe_bottom1.x -= 2 pipe_top2.x -= 2 pipe_bottom2.x -= 2 pipe_top3.x -= 2 pipe_bottom3.x -= 2 if pipe_top1.right < 0: pipe_top1.left = WIDTH pipe_bottom1.left = WIDTH pipe_top1.y = randint(-250, -50) pipe_bottom1.y = pipe_top1.y + 800 score += 1 if pipe_top2.right < 0: pipe_top2.left = WIDTH pipe_bottom2.left = WIDTH pipe_top2.y = randint(-250, -50) pipe_bottom2.y = pipe_top2.y + 800 score += 1 if pipe_top3.right < 0: pipe_top3.left = WIDTH pipe_bottom3.left = WIDTH pipe_top3.y = randint(-250, -50) pipe_bottom3.y = pipe_top3.y + 800 score += 1 if bird.colliderect(pipe_top1) or bird.colliderect(pipe_bottom1) or \ bird.colliderect(pipe_top2) or bird.colliderect(pipe_bottom2) or \ bird.colliderect(pipe_top3) or bird.colliderect(pipe_bottom3): game_over = True if bird.bottom > HEIGHT: game_over = True def on_key_down(): bird.y
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复