const util = require("./util.js") const log = require("./log.js") const searchLoc = [ [-1,1], [0,1], [1,1], [-1,0], [1,0], [-1,-1],[0,-1],[1,-1] ] function generateWorld(gridSize, perlinScale){ let x, y = 0 let tempWorld = Array.from(Array(gridSize[0]), () => new Array(gridSize[1])); for (x = 0; x < gridSize[0]; x++){ for (y = 0; y < gridSize[1]; y++){ tempWorld[x][y] = {type: 0, structure: 0, flag: 0, mask: true} } } // Generate board for(let x = 0; x < gridSize[0]; x++){ for(let y = 0; y < gridSize[1]; y++){ const value = util.randomNumber(0, 6); var n; switch (value) { case 0: n = 0; break; case 1: n = 0 break; case 2: n = 0 break; case 3: n = 0 break; case 4: n = 0 break; case 5: n = 5 break; default: log.log("OTHER") n = 7 } tempWorld[x][y].type = n } } // Place Numbers for(let x = 0; x < gridSize[0]; x++){ for(let y = 0; y < gridSize[1]; y++){ if (tempWorld[x][y].type === 0) { var counter = 0; searchLoc.forEach(location => { const tempx = x + location[0] const tempy = y + location[1] if (tempx >= 0 && tempy >= 0 && tempx < gridSize[0] && tempy < gridSize[1]) { if (tempWorld[tempx][tempy].type === 5) { counter++; } } }); if (counter !== 0) { tempWorld[x][y].type = 15 + counter } } } } return tempWorld; } module.exports = { generateWorld };