From 42c8da4578727becba29186a4b994f70ceddbaf3 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Wed, 1 Apr 2020 13:16:32 +0200 Subject: [PATCH] Teleportation cells remains teleportation cells after the snake leave them --- script.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/script.js b/script.js index e0162f8..420c860 100644 --- a/script.js +++ b/script.js @@ -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