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
7dc409383c1e8455fac3b28e0c5c32df7caef847
parent
bd44e05c72b6d48c19449d46d4d8ce384600c0dd
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-01-02 09:53
add createGame()

Diffstat

M src/index.js 52 ++++++++++++++++++++++++----------------------------

1 files changed, 24 insertions, 28 deletions


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

@@ -49,6 +49,26 @@ const play = function() {
   49    49     setTimeout(play, timeout);
   50    50 };
   51    51 
   -1    52 const createGame = function(scenario) {
   -1    53     return {
   -1    54         board: clone(scenario.board),
   -1    55         description: scenario.description,
   -1    56         winCondition: scenario.winCondition,
   -1    57         tileLimit: scenario.tileLimit || Infinity,
   -1    58         limitBuildSpace: scenario.limitBuildSpace,
   -1    59         sandbox: false,
   -1    60         currentPlayer: 1,
   -1    61         playing: false,
   -1    62         steps: 0,
   -1    63         turnCounter: 0,
   -1    64         resetGame: {
   -1    65             board: clone(scenario.board),
   -1    66             tileLimit: scenario.tileLimit || Infinity,
   -1    67             turnCounter: 0,
   -1    68         },
   -1    69     };
   -1    70 };
   -1    71 
   52    72 on('mousedown', '.board-cell', function(state, event) {
   53    73     if (state.game.playing) {
   54    74         return;
@@ -117,39 +137,15 @@ on('click', '.js-quit', function(state) {
  117   137 });
  118   138 
  119   139 on('click', '.js-menu-sandbox', function(state) {
  120    -1     state.game = {
   -1   140     state.game = createGame({
  121   141         board: logic.setupBoard(),
  122    -1         currentPlayer: 1,
  123    -1         playing: false,
  124    -1         steps: 0,
  125    -1         turnCounter: 0,
  126    -1         sandbox: true,
  127    -1         resetGame: {
  128    -1             board: logic.setupBoard(),
  129    -1             tileLimit: Infinity,
  130    -1             turnCounter: 0,
  131    -1         },
  132    -1     }
   -1   142     });
   -1   143     state.game.sandbox = true;
  133   144 });
  134   145 
  135   146 on('click', '.js-menu-scenario', function(state) {
  136   147     const i = parseInt(this.dataset.scenario, 10);
  137    -1     state.game = {
  138    -1         board: clone(scenarios[i].board),
  139    -1         description: scenarios[i].description,
  140    -1         winCondition: scenarios[i].winCondition,
  141    -1         tileLimit: scenarios[i].tileLimit || Infinity,
  142    -1         limitBuildSpace: scenarios[i].limitBuildSpace,
  143    -1         currentPlayer: 1,
  144    -1         playing: false,
  145    -1         steps: 0,
  146    -1         turnCounter: 0,
  147    -1         resetGame: {
  148    -1             board: clone(scenarios[i].board),
  149    -1             tileLimit: scenarios[i].tileLimit || Infinity,
  150    -1             turnCounter: 0,
  151    -1         },
  152    -1     }
   -1   148     state.game = createGame(scenarios[i]);
  153   149 });
  154   150 
  155   151 init(document.body);