From 6c9179b833886f81f77bc503e876af255547dc37 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 24 Aug 2018 20:02:43 +0200 Subject: [PATCH] make canvas argument optional on instantiating engine --- lib/src/Engine.dart | 11 +++++++---- test/src/engine_test.dart | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/src/engine_test.dart diff --git a/lib/src/Engine.dart b/lib/src/Engine.dart index 6f7ff16..a52df66 100644 --- a/lib/src/Engine.dart +++ b/lib/src/Engine.dart @@ -6,7 +6,7 @@ class Engine { // Elapsed Time Counter - useful for Safety Timeout Stopwatch _elapsed = new Stopwatch(); - // Game Tick Rate - *does* impact game speed + // Game Tick Rate - *does* impact game speed TODO add configurable option int _MS_PER_STEP = 1000 ~/ 3; // Max Frame (i.e. Rendering) rate - does *not* impact game speed @@ -15,14 +15,18 @@ class Engine { // ms stuck in updateloop after which game will declare itself unresponsive final int SAFETY_TIMEOUT = 2000; + // Grid Size TODO add as configurable option + static final GRID_X = 100; + static final GRID_Y = 100; + num _updateLag = 0.0; num _drawLag = 0.0; final html.CanvasElement canvas; - Grid _grid = new Grid(100, 100); + Grid _grid = new Grid(GRID_X, GRID_Y); bool _running = false; - Engine(this.canvas) { + Engine([this.canvas]) { _elapsed.start(); _grid.addPattern(amount: 15, dispersal: 5); } @@ -59,7 +63,6 @@ class Engine { } void update() { -// print("updating"); if (!_grid.update()) running = false; } diff --git a/test/src/engine_test.dart b/test/src/engine_test.dart new file mode 100644 index 0000000..92794ff --- /dev/null +++ b/test/src/engine_test.dart @@ -0,0 +1,12 @@ +@TestOn('browser') + +import 'dart:html'; + +import 'package:rules_of_living/src/Engine.dart'; +import 'package:test/test.dart'; + +void main() { + test("Engine can be instantiated without canvas", () { + expect(Engine(), isNot(throwsA(anything))); + }); +} \ No newline at end of file