game-of-death

antagonistic game of life  https://xi.github.io/game-of-death/
git clone https://git.ce9e.org/game-of-death.git

commit
3170dbee1004ac281a08b06e1ec1c8b77464ced9
parent
a189f32febc6e8271edeb5fffa81af7abcbdb6e7
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-10-26 19:29
add reset button

Diffstat

M TODO.md 1 -
M src/index.js 20 ++++++++++++++++++++
M src/template.js 4 ++++

3 files changed, 24 insertions, 1 deletions


diff --git a/TODO.md b/TODO.md

@@ -3,7 +3,6 @@
    3     3 + [Multiplayer]
    4     4 + Display: Where may a player build?
    5     5 + keyboard controls
    6    -1 + reset board after play
    7     6 + better win/loose indication
    8     7 + structure board controls
    9     8 

diff --git a/src/index.js b/src/index.js

@@ -78,10 +78,22 @@ on('click', '.js-next-gen', function(state) {
   78    78 });
   79    79 
   80    80 on('click', '.js-play', function(state) {
   -1    81     if (!state.game.playing) {
   -1    82         state.game.gameOnPlay.board = clone(state.game.board);
   -1    83         state.game.gameOnPlay.turnCounter = state.game.turnCounter;
   -1    84     }
   81    85     state.game.playing = !state.game.playing;
   82    86     play();
   83    87 });
   84    88 
   -1    89 on('click', '.js-reset', function(state) {
   -1    90     if (state.game.playing) {
   -1    91         return;
   -1    92     }
   -1    93     state.game.board = clone(state.game.gameOnPlay.board);
   -1    94     state.game.turnCounter = state.game.gameOnPlay.turnCounter;
   -1    95 });
   -1    96 
   85    97 on('click', '.js-current-player', function(state) {
   86    98     state.game.currentPlayer = (state.game.currentPlayer + 1) % constants.playerCount;
   87    99 });
@@ -109,6 +121,10 @@ on('click', '.js-menu-sandbox', function(state) {
  109   121         steps: 0,
  110   122         turnCounter: 0,
  111   123         sandbox: true,
   -1   124         gameOnPlay: {
   -1   125             board: logic.setupBoard(),
   -1   126             turnCounter: 0,
   -1   127         },
  112   128     }
  113   129 });
  114   130 
@@ -122,6 +138,10 @@ on('click', '.js-menu-scenario', function(state) {
  122   138         playing: false,
  123   139         steps: 0,
  124   140         turnCounter: 0,
   -1   141         gameOnPlay: {
   -1   142             board: clone(scenarios[i].board),
   -1   143             turnCounter: 0,
   -1   144         },
  125   145     }
  126   146 });
  127   147 

diff --git a/src/template.js b/src/template.js

@@ -30,6 +30,8 @@ const renderControls = function(state) {
   30    30             ' ',
   31    31             h('button', {'class': 'js-play'}, state.game.playing ? 'Pause' : 'Play'),
   32    32             ' ',
   -1    33             h('button', {'class': 'js-reset'}, 'Reset'),
   -1    34             ' ',
   33    35             h('button', {'class': `js-current-player fg-${state.game.currentPlayer}`}, 'Current Player'),
   34    36             ' ',
   35    37             h('button', {'class': 'js-export'}, 'Export'),
@@ -48,6 +50,8 @@ const renderControls = function(state) {
   48    50             ' ',
   49    51             h('button', {'class': 'js-play'}, state.game.playing ? 'Pause' : 'Play'),
   50    52             ' ',
   -1    53             h('button', {'class': 'js-reset'}, 'Reset'),
   -1    54             ' ',
   51    55             h('button', {'class': 'js-quit'}, 'Quit'),
   52    56         ]);
   53    57     }