-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·182 lines (171 loc) · 6.06 KB
/
index.html
File metadata and controls
executable file
·182 lines (171 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!doctype html>
<html lang="en">
<head>
<!--
JavaScript Snake
https://patorjk.com/games/snake
Source code is available here: https://github.com/patorjk/JavaScript-Snake
-->
<meta charset="utf-8" />
<title>JavaScript Snake</title>
<link
rel="stylesheet"
id="style"
type="text/css"
href="css/main-snake.css"
/>
<link rel="shortcut icon" href="css/images/favicon.png" />
<style>
.snake-toolbar {
position: absolute;
top: 0;
left: 0;
z-index: 10000;
padding: 5px;
}
.speed-btn {
cursor: pointer;
border: 1px solid #ccc;
background-color: #f0f0f0;
border-radius: 3px;
}
.speed-btn:hover {
background-color: #e0e0e0;
}
.speed-btn-active {
background-color: #4CAF50;
color: white;
border-color: #4CAF50;
}
</style>
<script>
function getTheme() {
function changeTheme(themeUrl) {
const elm = document.getElementById("style");
elm && elm.remove();
const newCss = document.createElement("link");
newCss.id = "style";
newCss.rel = "stylesheet";
newCss.type = "text/css";
newCss.href = themeUrl;
document.head.appendChild(newCss);
}
const index = document.getElementById("select").selectedIndex;
switch (index) {
case 0:
changeTheme("./css/light-snake.css?" + Math.random());
break;
case 1:
changeTheme("./css/main-snake.css?" + Math.random());
break;
case 2:
changeTheme("css/dark-snake.css?" + Math.random());
break;
case 3:
changeTheme("css/green-snake.css?" + Math.random());
break;
case 4:
changeTheme("css/matrix-snake.css?" + Math.random());
break;
case 5:
changeTheme("css/Senura-snake.css?" + Math.random());
break;
case 6:
changeTheme("css/head-snake.css?" + Math.random());
break;
case 7:
changeTheme("css/black-snake.css?" + Math.random());
break;
case 8:
changeTheme("css/neon-snake.css?" + Math.random());
break;
default:
changeTheme("css/main-snake.css?" + Math.random());
break;
}
setTimeout(function () {
document.getElementById("game-area").focus();
}, 10);
}
</script>
<!--
<script async src="https://www.googletagmanager.com/gtag/js?id=G-352HTB3H82"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-352HTB3H82');
</script>
--></head>
<body>
<div class="snake-toolbar">
<div style="display: inline-block; margin-right: 10px">
<span>Theme:</span>
<select autocomplete="off" id="select">
<option>Light Theme by yokesharun</option>
<option selected>Main Theme by patorjk</option>
<option>Dark Theme by KenyStev</option>
<option>Green Theme by CoffeeCatDE</option>
<option>Matrix Theme by Geahad Haymor</option>
<option>Theme by Senura Ratnayake</option>
<option>Snake Head Theme by Rb64</option>
<option>Black and purple Theme by LucassSantoss</option>
<option>Neon Theme by Daisy21000</option>
</select>
</div>
<div style="display: inline-block; margin-right: 10px">
<span>Speed:</span>
<button id="speed-1x" class="speed-btn speed-btn-active" data-speed="300" style="padding: 5px 10px; margin-left: 5px;">1x</button>
<button id="speed-2x" class="speed-btn" data-speed="150" style="padding: 5px 10px; margin-left: 5px;">2x</button>
<button id="speed-3x" class="speed-btn" data-speed="100" style="padding: 5px 10px; margin-left: 5px;">3x</button>
<button id="speed-5x" class="speed-btn" data-speed="60" style="padding: 5px 10px; margin-left: 5px;">5x</button>
</div>
<select id="selectMode" style="display: none;">
<option value="300" selected>1x</option>
<option value="150">2x</option>
<option value="100">3x</option>
<option value="60">5x</option>
</select>
<button id="go_full_screen">Full Screen</button>
<br />
</div>
<div id="mode-wrapper" style="display: inline; width: auto"></div>
<div id="game-area" tabindex="0"></div>
<script type="text/javascript" src="js/snake.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript">
document.getElementById('select').addEventListener('change', getTheme);
function go_full_screen() {
const elem = document.documentElement;
try {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
} catch (err) {
console.error(err);
alert("Sorry, fullscreen won't work in this setup.");
}
}
document.getElementById('go_full_screen').addEventListener('click', go_full_screen);
document.querySelectorAll('.speed-btn').forEach(function(btn) {
btn.addEventListener('click', function() {
document.querySelectorAll('.speed-btn').forEach(function(b) {
b.classList.remove('speed-btn-active');
});
btn.classList.add('speed-btn-active');
var speed = parseInt(btn.getAttribute('data-speed'));
var selectDropDown = document.getElementById('selectMode');
selectDropDown.value = speed;
var event = new Event('change');
selectDropDown.dispatchEvent(event);
});
});
</script>
</body>
</html>