Teleportation cells remains teleportation cells after the snake leave them

This commit is contained in:
Pierre HUBERT 2020-04-01 13:16:32 +02:00
parent f9aa6a469b
commit 42c8da4578

View File

@ -212,9 +212,11 @@ async function startGame(gameID) {
})
// Teleportation
const teleportationCells = []
if(level.hasOwnProperty("teleportation"))
level.teleportation.forEach((f) => {
map[f[0]-1][f[1]-1] = TELEPORTATION
teleportationCells.push(JSON.stringify([f[0]-1,f[1]-1]));
})
@ -297,6 +299,10 @@ async function startGame(gameID) {
if(!increaseSize) {
const oldPos = snake.shift()
map[oldPos[0]][oldPos[1]] = map[oldPos[0]][oldPos[1]] == ICE_SNAKE ? ICE : EMPTY
// If the cell was a teleportation cell, then revert it back to the right state
if(teleportationCells.includes(JSON.stringify(oldPos)))
map[oldPos[0]][oldPos[1]] = TELEPORTATION
}
// Check if the user has won