Skip to content

Commit 04c9abd

Browse files
committed
Update snake.js
1 parent 8a0bd95 commit 04c9abd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

js/snake.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ SNAKE.Snake = SNAKE.Snake || (function() {
127127
isPaused = false;
128128

129129
// ----- public variables -----
130-
130+
me.sessionHighScore = 1;
131131
me.snakeBody = {};
132132
me.snakeBody["b0"] = new SnakeBlock(); // create snake head
133133
me.snakeBody["b0"].row = config.startRow || 1;
@@ -324,6 +324,13 @@ SNAKE.Snake = SNAKE.Snake || (function() {
324324
* @method handleDeath
325325
*/
326326
me.handleDeath = function() {
327+
if (me.snakeLength > me.sessionHighScore) me.sessionHighScore = me.snakeLength;
328+
function highScoreAlert() {
329+
document.getElementById('high-score-dialog').innerHTML = 'Your current high score for this session is ' + me.sessionHighScore + '.';
330+
$(function() {
331+
$( "#high-score-dialog" ).dialog();
332+
})}
333+
highScoreAlert();
327334
me.snakeHead.elm.style.zIndex = getNextHighestZIndex(me.snakeBody);
328335
me.snakeHead.elm.className = me.snakeHead.elm.className.replace(/\bsnake-snakebody-alive\b/,'')
329336
me.snakeHead.elm.className += " snake-snakebody-dead";
@@ -709,7 +716,6 @@ SNAKE.Board = SNAKE.Board || (function() {
709716
tmpElm.appendChild(tryAgainStart);
710717
return tmpElm;
711718
}
712-
713719
// ---------------------------------------------------------------------
714720
// public functions
715721
// ---------------------------------------------------------------------
@@ -967,4 +973,4 @@ SNAKE.Board = SNAKE.Board || (function() {
967973
}
968974

969975
}; // end return function
970-
})();
976+
})();

0 commit comments

Comments
 (0)