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 9bda519

Browse filesBrowse files
committed
Edit high-score system
1 parent cb8a9cb commit 9bda519
Copy full SHA for 9bda519

File tree

Expand file treeCollapse file tree

2 files changed

+66
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+66
-7
lines changed
Open diff view settings
Collapse file

‎index.html‎

Copy file name to clipboard
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<!--<html manifest="snake.appcache">-->
3+
<head>
4+
<!--
5+
6+
JavaScript Snake
7+
By Patrick Gillespie
8+
http://patorjk.com/games/snake
9+
10+
Source code is available here: https://github.com/patorjk/JavaScript-Snake
11+
12+
-->
13+
<title>JavaScript Snake</title>
14+
<link rel=stylesheet id=style type=text/css href=./css/main-snake.css />
15+
<button onclick=getTheme()>Click to use this theme.</button>
16+
<select id="select">
17+
<option>Dark Theme</option>
18+
<option id="option">Revert To Original</option>
19+
</select>
20+
<script>
21+
function getTheme () {
22+
function changeTheme (Theme) {
23+
document.getElementById('style').setAttribute('href', Theme);
24+
}
25+
var index = document.getElementById("select").selectedIndex;
26+
switch (index) {
27+
case 0:
28+
changeTheme('css/dark-snake.css');
29+
break;
30+
case 1: changeTheme('css/main-snake.css');
31+
}
32+
}
33+
if (navigator.onLine && window.location.hostname === 'patorjk.com') {
34+
var _gaq = _gaq || [];
35+
_gaq.push(['_setAccount', 'UA-3312460-1']);
36+
_gaq.push(['_trackPageview']);
37+
38+
(function() {
39+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
40+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
41+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
42+
})();
43+
}
44+
</script>
45+
</head>
46+
<body>
47+
<div id="game-area" tabindex="0">
48+
</div>
49+
<script type="text/javascript" src="./js/snake.js"></script>
50+
<script type="text/javascript">
51+
var mySnakeBoard = new SNAKE.Board( {
52+
boardContainer: "game-area",
53+
fullScreen: true
54+
});
55+
</script>
56+
<p class="high-score">High Score:</p><div id="score"></div>
57+
<div id="high-score-dialog"></div>
58+
</body>
59+
</html>
Collapse file

‎js/snake.js‎

Copy file name to clipboardExpand all lines: js/snake.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +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();
327+
function writeHighScore () {
328+
if (me.snakeLength > me.sessionHighScore)
329+
me.sessionHighScore = me.snakeLength;
330+
document.getElementById('score').innerHTML = me.sessionHighScore;
331+
332+
}
333+
writeHighScore();
334334
me.snakeHead.elm.style.zIndex = getNextHighestZIndex(me.snakeBody);
335335
me.snakeHead.elm.className = me.snakeHead.elm.className.replace(/\bsnake-snakebody-alive\b/,'')
336336
me.snakeHead.elm.className += " snake-snakebody-dead";

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.