Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·202 lines (178 loc) · 6.85 KB
/
Copy pathindex.html
File metadata and controls
executable file
·202 lines (178 loc) · 6.85 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!doctype html>
<html lang="en">
<head>
<!--
JavaScript Snake
https://patorjk.com/games/snake
Source code is available here: https://github.com/patorjk/JavaScript-Snake
Dos styling: https://github.com/vinibiavatti1/TuiCss
-->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>JavaScript Snake</title>
<link
rel="preload"
href="css/tuicss/fonts/perfect-dos-vga-437.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link rel="stylesheet" type="text/css" href="css/tuicss/tuicss.min.css" />
<link rel="stylesheet" type="text/css" href="css/common-snake.css" />
<link rel="stylesheet" type="text/css" href="css/dos-snake.css" />
<link rel="stylesheet" id="style" type="text/css" href="css/main-snake.css" />
<link rel="shortcut icon" href="css/images/favicon.png" />
<style>
body {
touch-action: manipulation; /* no double-tap zoom during play */
}
.snake-gamepad {
display: none;
position: fixed;
right: 15px;
bottom: calc(15px + env(safe-area-inset-bottom, 0px));
z-index: 10001;
grid-template-columns: repeat(3, 52px);
grid-template-rows: repeat(3, 52px);
gap: 6px;
user-select: none;
-webkit-user-select: none;
}
.snake-gamepad button {
padding: 0;
font-size: 20px;
color: #333;
background: rgba(255, 255, 255, 0.55);
border: 1px solid #999;
border-radius: 10px;
touch-action: manipulation;
-webkit-tap-highlight-color: transparent;
}
.snake-gamepad button:active {
background: rgba(180, 180, 180, 0.8);
}
@media (pointer: coarse) {
.snake-gamepad {
display: grid;
}
/* the fullscreen API isn't useful on phones */
#go_full_screen {
display: none;
}
}
</style>
<script>
// To add a theme, add its stylesheet to src/css and push an entry here.
// The dropdown is built from this array. "selected" marks the default theme.
const THEMES = [
{ label: "Light Theme by yokesharun", url: "css/light-snake.css" },
{ label: "Main Theme by patorjk", url: "css/main-snake.css", selected: true },
{ label: "Dark Theme by KenyStev", url: "css/dark-snake.css" },
{ label: "Green Theme by CoffeeCatDE", url: "css/green-snake.css" },
{ label: "Matrix Theme by Geahad Haymor", url: "css/matrix-snake.css" },
{ label: "Theme by Senura Ratnayake", url: "css/Senura-snake.css" },
{ label: "Snake Head Theme by Rb64", url: "css/head-snake.css" },
{ label: "Black and purple Theme by LucassSantoss", url: "css/black-snake.css" },
{ label: "Neon Theme by Daisy21000", url: "css/neon-snake.css" },
{ label: "Clean Theme by CrashoutKing123", url: "css/clean-snake.css" },
{ label: "Original Theme by DylanLCrocker", url: "css/blue-snake.css" },
{ label: "Golden Theme By JosephVoboril29", url: "css/golden-snake.css" },
{ label: "Cotton Candy Theme by KiwiNguyen29", url: "css/cotton-candy-snake.css" },
{ label: "OG Theme by NevanJohnson", url: "css/og-snake.css" },
];
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;
const theme = THEMES[index] || THEMES.find((t) => t.selected) || THEMES[0];
changeTheme(theme.url + "?" + Math.random());
setTimeout(function () {
document.getElementById("game-area").focus();
}, 10);
}
</script>
<!-- Google tag (gtag.js) -->
<!--
<script async src="https://www.googletagmanager.com/gtag/js?id=G-1EFCMZ1JX6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-1EFCMZ1JX6');
</script>
-->
</head>
<body>
<!-- SNAKE.Board puts this into whichever dialog is shown.
It is passed to the board via the dialogControls config option. -->
<div class="snake-dialog-controls" id="snake-dialog-controls">
<div class="snake-control-row">
<label for="select">Theme:</label>
<select autocomplete="off" id="select" class="tui-input"></select>
</div>
<div class="snake-control-row">
<label for="selectMode">Mode:</label>
<select id="selectMode" class="tui-input">
<option value="100">Easy</option>
<option value="75" selected>Medium</option>
<option value="50">Hard</option>
<option value="25">Impossible</option>
<option value="110">Rush</option>
</select>
</div>
<div class="snake-control-buttons">
<button id="go_full_screen" class="tui-button">Full Screen</button>
</div>
</div>
<div id="mode-wrapper" style="display: inline; width: auto"></div>
<div id="game-area" tabindex="0"></div>
<!-- On-screen controls, only shown on touch devices (wired up in js/init.js) -->
<div class="snake-gamepad" id="snake-gamepad">
<button data-key="38" style="grid-area: 1 / 2" aria-label="Up">▲</button>
<button data-key="37" style="grid-area: 2 / 1" aria-label="Left">◀</button>
<button data-key="32" style="grid-area: 2 / 2" aria-label="Pause">❚❚</button>
<button data-key="39" style="grid-area: 2 / 3" aria-label="Right">▶</button>
<button data-key="40" style="grid-area: 3 / 2" aria-label="Down">▼</button>
</div>
<script type="text/javascript" src="js/snake.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript">
const themeSelect = document.getElementById('select');
THEMES.forEach(function (theme) {
const option = document.createElement('option');
option.text = theme.label;
option.selected = !!theme.selected;
themeSelect.add(option);
});
themeSelect.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);
SNAKE.showAlert("Sorry, fullscreen won't work in this setup.");
}
}
document.getElementById('go_full_screen').addEventListener('click', go_full_screen);
</script>
</body>
</html>