Guest User

Untitled

a guest
Feb 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class GameEngine {
  2.  
  3. // time length 20 s
  4. val TIME_UNIT: Long = 21000
  5. var timer:CountDownTimer? = null
  6.  
  7. fun init(state: GameState){
  8. state.onStartEngine()
  9. // interval 1 s
  10. timer = object : CountDownTimer(TIME_UNIT, 1000){
  11.  
  12. override fun onFinish() {
  13. state.onFinish()
  14. }
  15.  
  16. override fun onTick(p0: Long) {
  17. state.onUpdate(p0)
  18. }
  19. }
  20. }
  21.  
  22. fun start(){
  23. timer?.start()
  24. }
  25.  
  26. fun stop(){
  27. timer?.cancel()
  28. }
  29.  
  30.  
  31. }
Add Comment
Please, Sign In to add comment