MultiplayerMinesweeper/scripts/world/marker.mjs

33 lines
700 B
JavaScript
Raw Normal View History

2022-06-22 01:51:09 +00:00
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++){
2022-06-22 01:51:09 +00:00
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) {
2022-06-22 01:51:09 +00:00
if (world.data[tempx][tempy].type === 5) {
counter++;
}
}
});
if (counter !== 0) {
world.data[x][y].type = 15 + counter
}
}
}
}
world.isMarked = true;
return world;
}