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 stopwatch to begin ticking at the start of the program and when it reaches 10 seconds, do something (in this case, exit a loop)?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I use this function in my python programs. The input for the function is as example:
value = time.time()
In this example the loop is run every second for ten seconds:
Alternatively, if you've already got your loop:
This method works well with pygame, since it pretty much requires you to have a big main loop.
New to the python world!
I need a System Time independent Stopwatch so I did translate my old C++ class into Python:
This has no 49 days run over issue due to DWORD math but NOTICE that
GetTickCount
has about 15 milliseconds granularity so do not use this class if your need 1-100 milliseconds elapsed time ranges.Any improvement or feedback is welcome!
As a learning exercise for myself, I created a class to be able to create several stopwatch timer instances that you might find useful (I'm sure there are better/simpler versions around in the time modules or similar)
This is the Shortest Way I know of doing it: