2022-06-24 13:37:03 +00:00
|
|
|
const searchLoc = [
|
|
|
|
[-1, 1], [0, 1], [1, 1],
|
|
|
|
[-1, 0], [1, 0],
|
|
|
|
[-1, -1], [0, -1], [1, -1]
|
|
|
|
];
|
|
|
|
export function reveal(x, y, data) {
|
2022-06-24 16:22:44 +00:00
|
|
|
if (data[x][y].type === 5)
|
|
|
|
return data;
|
|
|
|
var toSearch = [];
|
|
|
|
var searchedLocations = [];
|
|
|
|
toSearch.push([x, y]);
|
|
|
|
if (data[x][y].type === 1) {
|
|
|
|
while (toSearch.length > 0) {
|
|
|
|
const x = toSearch[0][0];
|
|
|
|
const y = toSearch[0][1];
|
|
|
|
searchedLocations.push(toSearch[0]);
|
|
|
|
toSearch.shift();
|
|
|
|
searchLoc.forEach(loc => {
|
|
|
|
const tempx = x + loc[0];
|
|
|
|
const tempy = y + loc[1];
|
|
|
|
if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) {
|
|
|
|
if (data[tempx][tempy].type === 1 && data[tempx][tempy].mask === true) {
|
|
|
|
if (!toSearch.includes([tempx, tempy]) && !searchedLocations.includes([tempx, tempy])) {
|
|
|
|
toSearch.push([tempx, tempy]);
|
2022-06-24 13:37:03 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-24 16:22:44 +00:00
|
|
|
if (data[tempx][tempy].type !== 5) {
|
|
|
|
data[tempx][tempy].mask = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-06-24 13:37:03 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-24 16:22:44 +00:00
|
|
|
return data;
|
2022-06-24 13:37:03 +00:00
|
|
|
}
|
2022-06-24 16:29:05 +00:00
|
|
|
//# sourceMappingURL=revealer.js.map
|