首页 > 解决方案 > 我需要让基于时间的记分牌更好地工作

问题描述

所以我一直在使用海龟制作谷歌恐龙游戏,但我无法让记分牌不断更新,以至于每秒增加 100 分。非常感谢任何帮助,因为这是我的决赛。谢谢——谢伊

编辑:它不让我输入代码,因为它太长了

标签: pythonturtle-graphics

解决方案


这里有一些东西:

import turtle

delay = 0.1 # For the mainloop
count = 0 # To track when a second past
score = 0 # The score count

pen = turtle.Turtle(visible=False) # The turtle which will write the score
pen.penup()
pen.goto(0,200)
pen.write('Score: {}'.format(score),align='center',font=('Arial',10,'bold'))

while True: # Main game loop
    time.sleep(delay) # 1 frame per 0.1 second

    count += 1

    if count == 10: # When count is 10, that means 10*0.1 seconds have past
        score += 100
        pen.clear()
        pen.write('Score: {}'.format(score),align='center',font=('Arial',10,'bold'))
        count = 0 # Set count to zero to start tracking the second again

推荐阅读