Commits

Pedro Ferreira committed 8004a27

- add control for the spawn values range (of the added blocks)

  • Participants
  • Parent commits 82ee006

Comments (0)

Files changed (3)

 var line = blockPosition.line;
 
     // get the value
-var possibleValues = [ 2, 4 ];
+var possibleValues = G.SPAWN_VALUES;
 
 position = getRandomInt( 0, possibleValues.length - 1 );
 
 
 
 
+export function setSpawnValues( min, max )
+{
+clearBlocks();
+
+var value = min;
+var possibleValues = [];
+
+while ( value <= max )
+    {
+    possibleValues.push( value );
+
+    value *= 2;
+    }
+
+G.SPAWN_VALUES = possibleValues;
+}
+
+
 
 function addBlock( args )
 {

scripts/game_menu.ts

             var max = values[ ui.values[ 1 ] ];
 
             $( spawnRangeLabel ).text( '[ ' + min + ', ' + max + ' ]' );
+            },
+        stop: function( event, ui )
+            {
+            var min = values[ ui.values[ 0 ] ];
+            var max = values[ ui.values[ 1 ] ];
+
+            Game.setSpawnValues( min, max );
+            Game.addRandomBlock();
             }
     });
 }
 
     - to doo:
 
-        - add control with the limits to the values that can spawn (default 2-4, but can be 2-8, 2-16 etc)
         - center the grid
         - resize the canvas according to the grid length
  */
         CANVAS: null,
         STAGE: null,
         MAP_LENGTH: 4,
-        GRID_LINE_SIZE: 2
+        GRID_LINE_SIZE: 2,
+        SPAWN_VALUES: [ 2, 4 ]
     };
 
 window.onload = function()