Skip to content

Commit b365249

Browse files
committed
updates
1 parent e4cc40e commit b365249

16 files changed

Lines changed: 2391 additions & 1983 deletions

‎.all-contributorsrc‎

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"projectName": "JavaScript-Snake",
33
"projectOwner": "patorjk",
4-
"files": [
5-
"README.md"
6-
],
4+
"files": ["README.md"],
75
"commitType": "docs",
86
"commitConvention": "angular",
97
"contributorsPerLine": 7,
@@ -13,153 +11,105 @@
1311
"name": "patorjk",
1412
"avatar_url": "https://avatars.githubusercontent.com/u/521224?v=4",
1513
"profile": "http://patorjk.com/",
16-
"contributions": [
17-
"code",
18-
"doc",
19-
"design",
20-
"bug",
21-
"example"
22-
]
14+
"contributions": ["code", "doc", "design", "bug", "example"]
2315
},
2416
{
2517
"login": "ultra17",
2618
"name": "ultra17",
2719
"avatar_url": "https://avatars.githubusercontent.com/u/27869698?v=4",
2820
"profile": "https://github.com/ultra17",
29-
"contributions": [
30-
"code",
31-
"doc",
32-
"design",
33-
"bug"
34-
]
21+
"contributions": ["code", "doc", "design", "bug"]
3522
},
3623
{
3724
"login": "Rb64",
3825
"name": "Rb64",
3926
"avatar_url": "https://avatars.githubusercontent.com/u/91498309?v=4",
4027
"profile": "https://github.com/Rb64",
41-
"contributions": [
42-
"code",
43-
"bug"
44-
]
28+
"contributions": ["code", "bug"]
4529
},
4630
{
4731
"login": "legoman8304",
4832
"name": "Wyatt Nulton",
4933
"avatar_url": "https://avatars.githubusercontent.com/u/43346988?v=4",
5034
"profile": "https://github.com/legoman8304",
51-
"contributions": [
52-
"code",
53-
"bug"
54-
]
35+
"contributions": ["code", "bug"]
5536
},
5637
{
5738
"login": "ashishsiot",
5839
"name": "Ashish Bhoir",
5940
"avatar_url": "https://avatars.githubusercontent.com/u/63919950?v=4",
6041
"profile": "https://github.com/ashishsiot",
61-
"contributions": [
62-
"doc"
63-
]
42+
"contributions": ["doc"]
6443
},
6544
{
6645
"login": "dginovker",
6746
"name": "Dan G",
6847
"avatar_url": "https://avatars.githubusercontent.com/u/32943174?v=4",
6948
"profile": "http://dginovker.github.io",
70-
"contributions": [
71-
"code",
72-
"bug"
73-
]
49+
"contributions": ["code", "bug"]
7450
},
7551
{
7652
"login": "Megas4ever",
7753
"name": "Megas4ever",
7854
"avatar_url": "https://avatars.githubusercontent.com/u/28103886?v=4",
7955
"profile": "https://github.com/Megas4ever",
80-
"contributions": [
81-
"code",
82-
"design"
83-
]
56+
"contributions": ["code", "design"]
8457
},
8558
{
8659
"login": "mamamia5x",
8760
"name": "Bugs Bunny",
8861
"avatar_url": "https://avatars.githubusercontent.com/u/57536929?v=4",
8962
"profile": "https://github.com/mamamia5x",
90-
"contributions": [
91-
"code",
92-
"bug"
93-
]
63+
"contributions": ["code", "bug"]
9464
},
9565
{
9666
"login": "Coteh",
9767
"name": "James Cote",
9868
"avatar_url": "https://avatars.githubusercontent.com/u/3276350?v=4",
9969
"profile": "https://www.jamescote.ca",
100-
"contributions": [
101-
"code",
102-
"bug",
103-
"doc"
104-
]
70+
"contributions": ["code", "bug", "doc"]
10571
},
10672
{
10773
"login": "yokesharun",
10874
"name": "Arun Yokesh",
10975
"avatar_url": "https://avatars.githubusercontent.com/u/12830078?v=4",
11076
"profile": "http://yokesharun.github.io/",
111-
"contributions": [
112-
"code",
113-
"design"
114-
]
77+
"contributions": ["code", "design"]
11578
},
11679
{
11780
"login": "GregFrench",
11881
"name": "Greg French",
11982
"avatar_url": "https://avatars.githubusercontent.com/u/17938510?v=4",
12083
"profile": "https://github.com/GregFrench",
121-
"contributions": [
122-
"code"
123-
]
84+
"contributions": ["code"]
12485
},
12586
{
12687
"login": "KT360",
12788
"name": "KT360",
12889
"avatar_url": "https://avatars.githubusercontent.com/u/31077743?v=4",
12990
"profile": "https://github.com/KT360",
130-
"contributions": [
131-
"code",
132-
"design"
133-
]
91+
"contributions": ["code", "design"]
13492
},
13593
{
13694
"login": "Thusal06",
13795
"name": "Thusal Ranawaka",
13896
"avatar_url": "https://avatars.githubusercontent.com/u/66709891?v=4",
13997
"profile": "https://thusal06.github.io/",
140-
"contributions": [
141-
"code",
142-
"design"
143-
]
98+
"contributions": ["code", "design"]
14499
},
145100
{
146101
"login": "Furtano",
147102
"name": "C. S.",
148103
"avatar_url": "https://avatars.githubusercontent.com/u/4115133?v=4",
149104
"profile": "https://github.com/Furtano",
150-
"contributions": [
151-
"code",
152-
"design"
153-
]
105+
"contributions": ["code", "design"]
154106
},
155107
{
156108
"login": "akhill2606",
157109
"name": "Akhil Manohar",
158110
"avatar_url": "https://avatars.githubusercontent.com/u/56164681?v=4",
159111
"profile": "https://github.com/akhill2606",
160-
"contributions": [
161-
"code"
162-
]
112+
"contributions": ["code"]
163113
}
164114
]
165115
}

‎README.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ You can now play and edit the game live in codesandbox:
88

99
https://codesandbox.io/s/github/patorjk/JavaScript-Snake?file=/index.html
1010

11-
On first load sometimes the game frame will not load correctly and you'll need to press the refresh icon above its display panel to get the game to show.
11+
On first load sometimes the game frame will not load correctly and you'll need to press the refresh icon above its display panel to get the game to show.
1212

1313
Original game is located here:
1414

1515
http://patorjk.com/games/snake
1616

17-
1817
## How to use
18+
1919
The index.html file should give an idea of how to use this code. However, below you can see how to initialize it into any div within a webpage.
2020

2121
const mySnakeBoard = new SNAKE.Board( {
@@ -24,7 +24,7 @@ The index.html file should give an idea of how to use this code. However, below
2424
width: 580,
2525
height:400
2626
});
27-
27+
2828
The comments within the source code are formatted a little strange because at the time I was playing around with YUI Doc which generates documentation from code. Kind of sucks that there's so much churn in the JavaScript world. However, I'm glad the rest of the code doesn't use any external libraries, as this game still works the same after over a decade.
2929

3030
## Running
@@ -74,3 +74,8 @@ Thanks goes to these people: ([emoji key](https://allcontributors.org/docs/en/em
7474
<!-- prettier-ignore-end -->
7575

7676
<!-- ALL-CONTRIBUTORS-LIST:END -->
77+
78+
TODO:
79+
80+
- Add in what was added to Subpixel Snake
81+
-

‎src/ai-example.html‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<!--
5+
6+
JavaScript Snake
7+
https://patorjk.com/games/snake
8+
9+
Source code is available here: https://github.com/patorjk/JavaScript-Snake
10+
11+
-->
12+
<meta charset="utf-8" />
13+
<title>JavaScript Snake - AI Example</title>
14+
<link
15+
rel="stylesheet"
16+
id="style"
17+
type="text/css"
18+
href="css/main-snake.css"
19+
/>
20+
<link rel="shortcut icon" href="css/images/favicon.png" />
21+
<style>
22+
.snake-toolbar {
23+
position: absolute;
24+
top: 0;
25+
left: 0;
26+
z-index: 10000;
27+
padding: 5px;
28+
}
29+
</style>
30+
<script>
31+
function getTheme() {
32+
function changeTheme(themeUrl) {
33+
const elm = document.getElementById("style");
34+
elm && elm.remove();
35+
36+
const newCss = document.createElement("link");
37+
newCss.id = "style";
38+
newCss.rel = "stylesheet";
39+
newCss.type = "text/css";
40+
newCss.href = themeUrl;
41+
document.head.appendChild(newCss);
42+
}
43+
44+
const index = document.getElementById("select").selectedIndex;
45+
switch (index) {
46+
case 0:
47+
changeTheme("./css/light-snake.css?" + Math.random());
48+
break;
49+
case 1:
50+
changeTheme("./css/main-snake.css?" + Math.random());
51+
break;
52+
case 2:
53+
changeTheme("css/dark-snake.css?" + Math.random());
54+
break;
55+
case 3:
56+
changeTheme("css/green-snake.css?" + Math.random());
57+
break;
58+
case 4:
59+
changeTheme("css/matrix-snake.css?" + Math.random());
60+
break;
61+
case 5:
62+
changeTheme("css/Senura-snake.css?" + Math.random());
63+
break;
64+
case 6:
65+
changeTheme("css/head-snake.css?" + Math.random());
66+
break;
67+
case 7:
68+
changeTheme("css/black-snake.css?" + Math.random());
69+
break;
70+
case 8:
71+
changeTheme("css/neon-snake.css?" + Math.random());
72+
break;
73+
default:
74+
changeTheme("css/main-snake.css?" + Math.random());
75+
break;
76+
}
77+
setTimeout(function () {
78+
document.getElementById("game-area").focus();
79+
}, 10);
80+
}
81+
</script>
82+
<!--
83+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-352HTB3H82"></script>
84+
<script>
85+
window.dataLayer = window.dataLayer || [];
86+
function gtag(){dataLayer.push(arguments);}
87+
gtag('js', new Date());
88+
89+
gtag('config', 'G-352HTB3H82');
90+
</script>
91+
-->
92+
</head>
93+
<body>
94+
<div class="snake-toolbar">
95+
<div style="display: inline-block; margin-right: 10px">
96+
<span>Theme:</span>
97+
<select autocomplete="off" onchange="getTheme()" id="select">
98+
<option>Light Theme by yokesharun</option>
99+
<option selected>Main Theme by patorjk</option>
100+
<option>Dark Theme by KenyStev</option>
101+
<option>Green Theme by CoffeeCatDE</option>
102+
<option>Matrix Theme by Geahad Haymor</option>
103+
<option>Theme by Senura Ratnayake</option>
104+
<option>Snake Head Theme by Rb64</option>
105+
<option>Black and purple Theme by LucassSantoss</option>
106+
<option>Neon Theme by Daisy21000</option>
107+
</select>
108+
</div>
109+
<div style="display: inline-block; margin-right: 10px">
110+
<span>Mode:</span>
111+
<select id="selectMode">
112+
<option value="100">Easy</option>
113+
<option value="75" selected>Medium</option>
114+
<option value="50">Hard</option>
115+
<option value="25">Impossible</option>
116+
<option value="110">Rush</option>
117+
</select>
118+
</div>
119+
<button onclick="go_full_screen()">Full Screen</button>
120+
<br />
121+
</div>
122+
123+
<div id="mode-wrapper" style="display: inline; width: auto"></div>
124+
125+
<div id="game-area" tabindex="0"></div>
126+
<script type="text/javascript" src="js/snake.js"></script>
127+
<script type="text/javascript" src="js/init.js"></script>
128+
<script type="text/javascript">
129+
function go_full_screen() {
130+
const elem = document.documentElement;
131+
try {
132+
if (elem.requestFullscreen) {
133+
elem.requestFullscreen();
134+
} else if (elem.msRequestFullscreen) {
135+
elem.msRequestFullscreen();
136+
} else if (elem.mozRequestFullScreen) {
137+
elem.mozRequestFullScreen();
138+
} else if (elem.webkitRequestFullscreen) {
139+
elem.webkitRequestFullscreen();
140+
}
141+
} catch (err) {
142+
console.error(err);
143+
alert("Sorry, fullscreen won't work in this setup.");
144+
}
145+
}
146+
</script>
147+
</body>
148+
</html>

0 commit comments

Comments
 (0)