Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 14b1d9b

Browse filesBrowse files
committed
Fix starting move
1 parent cfb31c2 commit 14b1d9b
Copy full SHA for 14b1d9b

File tree

Expand file treeCollapse file tree

1 file changed

+4
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-1
lines changed
Open diff view settings
Collapse file

‎js/snake.js‎

Copy file name to clipboardExpand all lines: js/snake.js
+4-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.