Venciity

function fillRandomSquares

Jul 23rd, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fillRandomSquares(level,rows,cols){
  2.    
  3.     var matrixForGame = matrix(rows, cols, false);
  4.  
  5.  
  6.  
  7.  
  8.     // create matrix
  9.     function matrix( rows, cols, defaultValue){
  10.  
  11.         var arr = [];
  12.        
  13.         // Creates all lines:
  14.         for(var i=0; i < rows; i++){
  15.        
  16.             // Creates an empty line
  17.             arr.push([]);
  18.        
  19.             // Adds cols to the empty line:
  20.             arr[i].push( new Array(cols));
  21.        
  22.             for(var j=0; j < cols; j++){
  23.                 // Initializes:
  24.                 arr[i][j] = defaultValue;
  25.             }
  26.         }
  27.     return arr;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment