Skip to content

Commit 14b1d9b

Browse files
committed
Fix starting move
1 parent cfb31c2 commit 14b1d9b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

js/snake.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ SNAKE.Snake = SNAKE.Snake || (function() {
118118
lastMove = 1,
119119
preMove = -1,
120120
isFirstMove = true,
121+
isFirstGameMove = true,
121122
currentDirection = -1, // 0: up, 1: left, 2: down, 3: right
122123
columnShift = [0, 1, 0, -1],
123124
rowShift = [-1, 0, 1, 0],
@@ -259,10 +260,11 @@ SNAKE.Snake = SNAKE.Snake || (function() {
259260
{
260261
preMove = directionFound;
261262
}
262-
if (Math.abs(directionFound - lastMove) !== 2 && isFirstMove) // Prevent snake from turning 180 degrees
263+
if (Math.abs(directionFound - lastMove) !== 2 && isFirstMove || isFirstGameMove) // Prevent snake from turning 180 degrees
263264
{
264265
currentDirection = directionFound;
265266
isFirstMove = false;
267+
isFirstGameMove = false;
266268
}
267269
};
268270

@@ -383,6 +385,7 @@ SNAKE.Snake = SNAKE.Snake || (function() {
383385
me.rebirth = function() {
384386
isDead = false;
385387
isFirstMove = true;
388+
isFirstGameMove = true;
386389
preMove = -1;
387390
};
388391

0 commit comments

Comments
 (0)