Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
776B

  1. import time
  2. class desktop_SequentialTimer():
  3. def __init__(self):
  4. self.activeTimeout = None
  5. self.callback = None
  6. self.queue = []
  7. #}
  8. def update(self):
  9. # Get current time in milliseconds.
  10. now = time.time_ns() // 1000000
  11. # Schedule an item.
  12. if (
  13. self.activeTimeout == None and
  14. len(self.queue) > 0
  15. ):
  16. self.activeTimeout = now + self.queue[0][0]
  17. elif (
  18. self.activeTimeout != None and
  19. now >= self.activeTimeout
  20. ):
  21. # Report when the time is up.
  22. key = self.queue[0][1]
  23. value = self.queue[0][2]
  24. self.queue.pop(0)
  25. self.activeTimeout = None
  26. self.callback(key, value)
  27. #}
  28. #}
  29. def schedule(self, key, value, timeout):
  30. self.queue.append([timeout, key, value])
  31. #}