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]
|
|
|
|
]
|
|
|
|
|
2022-06-23 05:44:57 +00:00
|
|
|
export function reveal(x, y, data) {
|
|
|
|
if (data[x][y].type !== 5) {
|
2022-06-22 01:51:09 +00:00
|
|
|
|
|
|
|
var toSearch = [];
|
|
|
|
var searchedLocations = [];
|
2022-06-23 05:44:57 +00:00
|
|
|
toSearch.push([x, y])
|
2022-06-22 01:51:09 +00:00
|
|
|
|
2022-06-23 05:44:57 +00:00
|
|
|
if (data[x][y].type === 1) {
|
2022-06-22 01:51:09 +00:00
|
|
|
while (toSearch.length > 0) {
|
2022-06-23 05:44:57 +00:00
|
|
|
console.log("LoopReveal")
|
2022-06-22 01:51:09 +00:00
|
|
|
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])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data[tempx][tempy].type !== 5) {
|
|
|
|
data[tempx][tempy].mask = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
}
|