fixed holes in snake

This commit is contained in:
2024-01-28 11:47:51 +01:00
parent 28258d7b32
commit 4ae67b1e08

View File

@@ -86,9 +86,14 @@ function moveSnake(x: number, y: number) {
if (snake.value.history.length > length) {
const currentLength = snake.value.history.length
const allowedLength = snake.value.length
const toDelete = snake.value.history.slice(0, currentLength - allowedLength)
for (const cell of toDelete) {
cell.color = 'white'
if (currentLength > allowedLength) {
const toDelete = snake.value.history.shift()
if (toDelete !== undefined) {
toDelete.color = 'white'
}
}
}
}