我需要使基于时间的记分牌更好地工作

问题描述 投票:-3回答:1

所以我一直在使用乌龟开发Google恐龙游戏,但我无法使记分板不断更新,因此每秒钟它会增加100分。非常感谢您的帮助,因为这是我的决赛。谢谢-谢伊

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

python turtle-graphics
1个回答
1
投票

这里是一些东西:

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
© www.soinside.com 2019 - 2024. All rights reserved.