Timer for Python game

前端 未结 10 1842
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 02:38

I\'m trying to create a simple game where the point is to collect as many blocks as you can in a certain amount of time, say 10 seconds. How can I get a timer to begin ticking a

10条回答
  •  深忆病人
    2021-01-31 02:59

    In this example the loop is run every second for ten seconds:

    import datetime, time
    then = datetime.datetime.now() + datetime.timedelta(seconds=10)
    while then > datetime.datetime.now():
        print 'sleeping'
        time.sleep(1)
    

提交回复
热议问题