Skip to content

Instantly share code, notes, and snippets.

@mausworks
Created July 27, 2020 11:59
Show Gist options
  • Save mausworks/f37f6773da6aaa7ddb839bc23ba1fdac to your computer and use it in GitHub Desktop.
Save mausworks/f37f6773da6aaa7ddb839bc23ba1fdac to your computer and use it in GitHub Desktop.
import 'dart:async';
class Game {
String id = null;
Duration tickDuration = const Duration(microseconds: (1000000 ~/ 60));
DateTime updated = DateTime(0);
Timer _timer = null;
Game(String this.id);
void update(Timer timer) {
final now = DateTime.now();
final delta = now.difference(updated);
print(delta.inMicroseconds);
updated = now;
}
void start() {
print("Game '$id' started");
_timer = Timer.periodic(tickDuration, update);
}
void stop() {
print("Game '$id' ended");
_timer?.cancel();
}
}
void main() async {
var game = Game("test")..start();
await Future.delayed(Duration(seconds: 10));
game.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment