MultiplayerMinesweeper/scripts/world/marker.mjs

33 lines
700 B
JavaScript

const searchLoc =
[
[-1,1], [0,1], [1,1],
[-1,0], [1,0],
[-1,-1],[0,-1],[1,-1]
]
// Place Numbers
export function mark(world) {
for(let x = 0; x < world.width; x++){
for(let y = 0; y < world.height; y++){
if (world.data[x][y].type === 1) {
var counter = 0;
searchLoc.forEach(location => {
const tempx = x + location[0]
const tempy = y + location[1]
if (tempx >= 0 && tempy >= 0 && tempx < world.width && tempy < world.height) {
if (world.data[tempx][tempy].type === 5) {
counter++;
}
}
});
if (counter !== 0) {
world.data[x][y].type = 15 + counter
}
}
}
}
world.isMarked = true;
return world;
}