- commit
- 05f585a737999500ab133ac9817ec9676c729295
- parent
- 940cb09060122ed6b3900923f5e93299e2b2d150
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2019-10-26 18:51
refactor steps to reuse more functionality from playing
Diffstat
| M | src/index.js | 12 | ++++++++---- |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/index.js b/src/index.js
@@ -33,11 +33,14 @@ const clone = function(obj) {
33 33 };
34 34
35 35 const play = function() {
36 -1 if (!state.game.playing && !state.game.steps) {
-1 36 if (!state.game.playing) {
37 37 return;
38 38 }
39 -1 if (!state.game.playing) {
-1 39 if (state.game.steps) {
40 40 state.game.steps -= 1;
-1 41 if (!state.game.steps) {
-1 42 state.game.playing = false;
-1 43 }
41 44 }
42 45 logic.calculateNextGen(state);
43 46 update();
@@ -47,7 +50,7 @@ const play = function() {
47 50 };
48 51
49 52 on('mousedown', '.board-cell', function(state, event) {
50 -1 if (state.game.playing || state.game.steps) {
-1 53 if (state.game.playing) {
51 54 return;
52 55 }
53 56 if (event.buttons != 1) {
@@ -66,10 +69,11 @@ on('mousedown', '.board-cell', function(state, event) {
66 69 });
67 70
68 71 on('click', '.js-next-gen', function(state) {
69 -1 if (state.game.playing || state.game.steps) {
-1 72 if (state.game.playing) {
70 73 return;
71 74 }
72 75 state.game.steps = document.querySelector('[name="steps"]').value;
-1 76 state.game.playing = true;
73 77 play();
74 78 });
75 79