From c1fe61517bb853b5ed1ec3f3712a6b789c3cefb6 Mon Sep 17 00:00:00 2001
From: SDR0512 <58349712+SDR0512@users.noreply.github.com>
Date: Sun, 5 Jul 2020 16:29:42 +0530
Subject: [PATCH 04/97] Update index.html
---
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/index.html b/index.html
index ce912c50..8d200103 100755
--- a/index.html
+++ b/index.html
@@ -48,7 +48,7 @@
break;
case 5:
changeTheme('css/Senura-snake.css?' + Math.random());
-
+ break;
default:
changeTheme('css/main-snake.css?' + Math.random());
break;
From fccdbe73b68bf4101a1c0a394c315aa524807fc0 Mon Sep 17 00:00:00 2001
From: Ashish Bhoir <63919950+ashishsiot@users.noreply.github.com>
Date: Fri, 6 Nov 2020 09:54:25 +0530
Subject: [PATCH 05/97] Update Readme.md
Update Readme.md File And Add Some Emojis Also
---
README.md | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index f2181309..85d29f8e 100755
--- a/README.md
+++ b/README.md
@@ -1,10 +1,13 @@
-JavaScript Snake
-By Patrick Gillespie
+# 🐛 Snake Game 🐛
+## JavaScript Snake Game By Patrick Gillespie
+This is a DOM-based game of Snake that I wrote in JavaScript a few years back.
+
+# ▶ Play Game ▶
License: MIT
http://patorjk.com/games/snake
-This is a DOM-based game of Snake that I wrote in JavaScript a few years back.
+# 📋 Note 📋
Other than the full screen mode demonstrated in the code, it can also be
initialized in div tags within a page. Example:
From 3b127ce3c1bfc40bced6114ed0168386a510533d Mon Sep 17 00:00:00 2001
From: Ashish Bhoir <63919950+ashishsiot@users.noreply.github.com>
Date: Wed, 23 Dec 2020 16:47:09 +0530
Subject: [PATCH 06/97] Remove licence Form Live Demo Category And Move T
Remove licence Form Live Demo Category And Move To Seperate Licence
---
README.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 85d29f8e..adccd626 100755
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
This is a DOM-based game of Snake that I wrote in JavaScript a few years back.
# ▶ Play Game ▶
-License: MIT
+
http://patorjk.com/games/snake
@@ -20,3 +20,6 @@ initialized in div tags within a page. Example:
The comments are formatted a little strange because at the time I was playing
around with YUI Doc.
+
+# License: MIT
+LICENSE
From 8e0861c10c0a9718f3c1a75abc582576dc4a7e46 Mon Sep 17 00:00:00 2001
From: Ashish Bhoir <63919950+ashishsiot@users.noreply.github.com>
Date: Wed, 23 Dec 2020 16:52:02 +0530
Subject: [PATCH 07/97] Add Licence Link On Readme.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index adccd626..79073590 100755
--- a/README.md
+++ b/README.md
@@ -22,4 +22,4 @@ The comments are formatted a little strange because at the time I was playing
around with YUI Doc.
# License: MIT
-LICENSE
+[LICENSE](https://github.com/ashishsiot/JavaScript-Snake/blob/master/LICENSE)
From 5769d9e3459ac50848d46a8fff758fec895ffc51 Mon Sep 17 00:00:00 2001
From: Ashish Bhoir <63919950+ashishsiot@users.noreply.github.com>
Date: Wed, 23 Dec 2020 16:53:09 +0530
Subject: [PATCH 08/97] Add Raw Document To The Live Demo Link
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 79073590..b7db34de 100755
--- a/README.md
+++ b/README.md
@@ -22,4 +22,4 @@ The comments are formatted a little strange because at the time I was playing
around with YUI Doc.
# License: MIT
-[LICENSE](https://github.com/ashishsiot/JavaScript-Snake/blob/master/LICENSE)
+[LICENSE](https://raw.githubusercontent.com/ashishsiot/JavaScript-Snake/master/LICENSE)
From f59d3b4cabcf3376bd5299295b1eaeced1edac04 Mon Sep 17 00:00:00 2001
From: patorjk
Date: Wed, 17 Feb 2021 13:09:41 -0500
Subject: [PATCH 09/97] Removing needless file
---
webpack.config.js | 12 ------------
1 file changed, 12 deletions(-)
delete mode 100644 webpack.config.js
diff --git a/webpack.config.js b/webpack.config.js
deleted file mode 100644
index 17b96eeb..00000000
--- a/webpack.config.js
+++ /dev/null
@@ -1,12 +0,0 @@
-const webpack = require('webpack');
-
-/*
- TODO: Idea here was to make it so the game could be accessible via codesandbox.io, however, it looks like
- that will require larger charges than I realized.
-*/
-
-module.exports = {
- entry: {
- app: './js/snake.js'
- }
-};
From e4fedca2582f9c1b5430ee9aa9f66e96584b0600 Mon Sep 17 00:00:00 2001
From: patorjk
Date: Wed, 17 Feb 2021 13:10:06 -0500
Subject: [PATCH 10/97] made index.html the main file
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 381a117a..80912d93 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "javascript-snake",
"version": "1.0.0",
"description": "JavaScript Snake By Patrick Gillespie License: MIT http://patorjk.com/games/snake",
- "main": "js/snake.js",
+ "main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
From 569ecd936565c9b2928a53550cf695adde49595e Mon Sep 17 00:00:00 2001
From: patorjk
Date: Wed, 17 Feb 2021 13:26:50 -0500
Subject: [PATCH 11/97] updates
---
package.json | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index 80912d93..a8e13a48 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,8 @@
"description": "JavaScript Snake By Patrick Gillespie License: MIT http://patorjk.com/games/snake",
"main": "index.html",
"scripts": {
+ "start": "parcel index.html --open",
+ "build": "parcel build index.html",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@@ -16,8 +18,8 @@
"url": "https://github.com/patorjk/JavaScript-Snake/issues"
},
"homepage": "https://github.com/patorjk/JavaScript-Snake#readme",
+ "dependencies": {},
"devDependencies": {
- "webpack": "^4.41.1",
- "webpack-cli": "^3.3.9"
+ "parcel-bundler": "^1.6.1"
}
}
From dc0a05ccc7b4bfa451de21d0a98743530d74394a Mon Sep 17 00:00:00 2001
From: patorjk
Date: Wed, 17 Feb 2021 21:40:21 -0500
Subject: [PATCH 12/97] Updated README.md
---
README.md | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index b7db34de..73527fa3 100755
--- a/README.md
+++ b/README.md
@@ -1,15 +1,14 @@
-# 🐛 Snake Game 🐛
-## JavaScript Snake Game By Patrick Gillespie
-This is a DOM-based game of Snake that I wrote in JavaScript a few years back.
+# JavaScript Snake Game
-# ▶ Play Game ▶
+This is a DOM-based game of Snake that I wrote in JavaScript over a decade ago. It was made to have sort of a nostalgic feel to it.
+
+## Play Game
http://patorjk.com/games/snake
-# 📋 Note 📋
-Other than the full screen mode demonstrated in the code, it can also be
-initialized in div tags within a page. Example:
+## How to use
+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.
var mySnakeBoard = new SNAKE.Board( {
boardContainer: "game-area",
@@ -18,8 +17,4 @@ initialized in div tags within a page. Example:
height:400
});
-The comments are formatted a little strange because at the time I was playing
-around with YUI Doc.
-
-# License: MIT
-[LICENSE](https://raw.githubusercontent.com/ashishsiot/JavaScript-Snake/master/LICENSE)
+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.
From 68dd4fdd073c69ae19ea3abae1da6e3b4ccd02ce Mon Sep 17 00:00:00 2001
From: patorjk
Date: Wed, 17 Feb 2021 21:41:12 -0500
Subject: [PATCH 13/97] Delete min-snake.js
---
js/min-snake.js | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 js/min-snake.js
diff --git a/js/min-snake.js b/js/min-snake.js
deleted file mode 100644
index 6c09ee9b..00000000
--- a/js/min-snake.js
+++ /dev/null
@@ -1 +0,0 @@
-var SNAKE=SNAKE||{};function getHighScore(){document.getElementById("high-score").addEventListener("click",function(){null==localStorage.jsSnakeHighScore?alert("You have not played this game yet!"):alert("Your current high score is "+localStorage.jsSnakeHighScore+".")})}SNAKE.addEventListener=window.addEventListener?function(e,t,n,a){e.addEventListener(t,n,a)}:window.attachEvent?function(e,t,n){e.attachEvent("on"+t,n)}:void 0,SNAKE.removeEventListener=window.removeEventListener?function(e,t,n,a){e.removeEventListener(t,n,a)}:window.detachEvent?function(e,t,n){e.detachEvent("on"+t,n)}:void 0,SNAKE.Snake=SNAKE.Snake||function(){var f=[],v=function(){this.elm=null,this.elmStyle=null,this.row=-1,this.col=-1,this.xPos=-1e3,this.yPos=-1e3,this.next=null,this.prev=null};return function(o){if(o&&o.playingBoard){var d=this,l=o.playingBoard,i=(0,[]),s=1,r=[0,1,0,-1],c=[-1,0,1,0],u=[],h=[],k=75,p=!1,m=!1;e("Easy",100),e("Medium",75),e("Difficult",50),d.snakeBody={},d.snakeBody.b0=new v,d.snakeBody.b0.row=o.startRow||1,d.snakeBody.b0.col=o.startCol||1,d.snakeBody.b0.xPos=d.snakeBody.b0.row*l.getBlockWidth(),d.snakeBody.b0.yPos=d.snakeBody.b0.col*l.getBlockHeight(),d.snakeBody.b0.elm=g(),d.snakeBody.b0.elmStyle=d.snakeBody.b0.elm.style,l.getBoardContainer().appendChild(d.snakeBody.b0.elm),d.snakeBody.b0.elm.style.left=d.snakeBody.b0.xPos+"px",d.snakeBody.b0.elm.style.top=d.snakeBody.b0.yPos+"px",d.snakeBody.b0.next=d.snakeBody.b0,d.snakeBody.b0.prev=d.snakeBody.b0,d.snakeLength=1,d.snakeHead=d.snakeBody.b0,d.snakeTail=d.snakeBody.b0,d.snakeHead.elm.className=d.snakeHead.elm.className.replace(/\bsnake-snakebody-dead\b/,""),d.snakeHead.elm.className+=" snake-snakebody-alive",d.setPaused=function(e){m=e},d.getPaused=function(){return m},d.handleArrowKeys=function(e){if(!p&&!m){var t=d.snakeLength,n=i[0]||s;switch(e){case 37:case 65:1===n&&1!==t||i.unshift(3);break;case 38:case 87:2===n&&1!==t||i.unshift(0);break;case 39:case 68:3===n&&1!==t||i.unshift(1);break;case 40:case 83:0===n&&1!==t||i.unshift(2)}}},d.go=function(){var e=d.snakeHead,t=d.snakeTail,n=s,a=l.grid;!0!==m?(d.snakeTail=t.prev,a[(d.snakeHead=t).row]&&a[t.row][t.col]&&(a[t.row][t.col]=0),i.length&&(n=s=i.pop()),t.col=e.col+r[n],t.row=e.row+c[n],t.xPos=e.xPos+u[n],t.yPos=e.yPos+h[n],t.elmStyle||(t.elmStyle=t.elm.style),t.elmStyle.left=t.xPos+"px",t.elmStyle.top=t.yPos+"px",0===a[t.row][t.col]?(a[t.row][t.col]=1,setTimeout(function(){d.go()},k)):0e&&(alert("Congratulations! You have beaten your previous high score, which was "+e+"."),localStorage.setItem("jsSnakeHighScore",d.snakeLength)),d.snakeHead.elm.style.zIndex=function(e){var t,n=0,a=0;for(t in e)e[t].elm.currentStyle?a=parseFloat(e[t].elm.style["z-index"],10):window.getComputedStyle&&(a=parseFloat(document.defaultView.getComputedStyle(e[t].elm,null).getPropertyValue("z-index"),10)),!isNaN(a)&&n[Paused]Press [space] to unpause.
",(w=document.createElement("div")).className="snake-panel-component",w.innerHTML="more patorjk.com apps - source code",(B=document.createElement("div")).className="snake-panel-component",B.innerHTML="Length: 1",t=function(){var e=document.createElement("div");e.id="sbWelcome"+l,e.className="snake-welcome-dialog";var t=document.createElement("div"),n="";E.fullScreen&&(n="On Windows, press F11 to play in Full Screen mode.");t.innerHTML="JavaScript SnakeUse the arrow keys on your keyboard to play the game. "+n+"";var a=document.createElement("button");a.appendChild(document.createTextNode("Play Game"));var o=function(){SNAKE.removeEventListener(window,"keyup",d,!1),e.style.display="none",b.setBoardState(1),b.getBoardContainer().focus()},d=function(e){if(!e)var e=window.event;var t=e.which?e.which:e.keyCode;32!==t&&13!==t||o()};return SNAKE.addEventListener(window,"keyup",d,!1),SNAKE.addEventListener(a,"click",o,!1),e.appendChild(t),e.appendChild(a),e}(),n=function(){var n=document.createElement("div");n.id="sbTryAgain"+l,n.className="snake-try-again-dialog";var e=document.createElement("div");e.innerHTML="JavaScript SnakeYou died :(";var t=document.createElement("button");t.appendChild(document.createTextNode("Play Again?"));var a=function(){n.style.display="none",b.resetBoard(),b.setBoardState(1),b.getBoardContainer().focus()};return SNAKE.addEventListener(window,"keyup",function(e){if(0===o&&"block"===n.style.display){if(!e)var e=window.event;var t=e.which?e.which:e.keyCode;32!==t&&13!==t||a()}},!0),SNAKE.addEventListener(t,"click",a,!1),n.appendChild(e),n.appendChild(t),n}(),SNAKE.addEventListener(f,"keyup",function(e){if(!e)e=window.event;return e.cancelBubble=!0,e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault(),!1},!1),f.className="snake-game-container",a.style.zIndex=1e4,f.appendChild(a),f.appendChild(v),f.appendChild(w),f.appendChild(B),f.appendChild(t),f.appendChild(n),g=new SNAKE.Snake({playingBoard:b,startRow:2,startCol:2}),m=new SNAKE.Food({playingBoard:b}),t.style.zIndex=1e3}b.grid=[],b.setPaused=function(e){d=e,g.setPaused(e),a.style.display=d?"block":"none"},b.getPaused=function(){return d},b.resetBoard=function(){SNAKE.removeEventListener(f,"keydown",y,!1),g.reset(),B.innerHTML="Length: 1",b.setupPlayingField()},b.getBoardState=function(){return o},b.setBoardState=function(e){o=e},b.getGridFoodValue=function(){return-1},b.getPlayingFieldElement=function(){return v},b.setBoardContainer=function(e){"string"==typeof e&&(e=document.getElementById(e)),e!==f&&(f=e,v=null,b.setupPlayingField())},b.getBoardContainer=function(){return f},b.getBlockWidth=function(){return 20},b.getBlockHeight=function(){return 20},b.setupPlayingField=function(){var e,t,n,a;v||S(),!0===E.fullScreen?(cTop=0,cLeft=0,a=0,"number"==typeof window.innerWidth?a=window.innerWidth:document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)?a=document.documentElement.clientWidth:document.body&&(document.body.clientWidth||document.body.clientHeight)&&(a=document.body.clientWidth),e=a-5,n=0,"number"==typeof window.innerHeight?n=window.innerHeight:document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)?n=document.documentElement.clientHeight:document.body&&(document.body.clientWidth||document.body.clientHeight)&&(n=document.body.clientHeight),t=n-5,document.body.style.backgroundColor="#FC5454"):(cTop=E.top,cLeft=E.left,e=E.width,t=E.height);var o=2*b.getBlockWidth()+e%b.getBlockWidth(),d=Math.min(250*b.getBlockWidth()-o,e-o),l=3*b.getBlockHeight()+t%b.getBlockHeight(),i=Math.min(250*b.getBlockHeight()-l,t-l);f.style.left=cLeft+"px",f.style.top=cTop+"px",f.style.width=e+"px",f.style.height=t+"px",v.style.left=b.getBlockWidth()+"px",v.style.top=b.getBlockHeight()+"px",v.style.width=d+"px",v.style.height=i+"px";var s=l-b.getBlockHeight(),r=b.getBlockHeight()+i+Math.round((s-30)/2)+"px";w.style.top=r,w.style.width="450px",w.style.left=Math.round(e/2)-Math.round(225)+"px",B.style.top=r,B.style.left=e-120+"px",w.style.display=e<700?"none":"block",b.grid=[];for(var c=d/b.getBlockWidth()+2,u=i/b.getBlockHeight()+2,h=0;h
Date: Wed, 17 Feb 2021 21:42:42 -0500
Subject: [PATCH 14/97] Added window.SNAKE
---
js/snake.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/js/snake.js b/js/snake.js
index 02b6653f..9c6d5587 100644
--- a/js/snake.js
+++ b/js/snake.js
@@ -10,6 +10,7 @@ http://patorjk.com/games/snake
*/
var SNAKE = SNAKE || {};
+window.SNAKE = SNAKE; // this will allow us to access the game in other JS files when the app is loaded up in a codesandbox.com sandbox, that's the only reason it's here
/**
* @method addEventListener
From c14d06af4fb48fdffad4a25a9ae30fdfe2ddf9fa Mon Sep 17 00:00:00 2001
From: patorjk
Date: Wed, 17 Feb 2021 22:04:10 -0500
Subject: [PATCH 15/97] initial creation
---
js/init.js | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 js/init.js
diff --git a/js/init.js b/js/init.js
new file mode 100644
index 00000000..924623bf
--- /dev/null
+++ b/js/init.js
@@ -0,0 +1,4 @@
+var mySnakeBoard = new SNAKE.board({
+ boardContainer: "game-area",
+ fullScreen: true
+});
From ff103b58f417b1eaf12df7868235e296e8fe50fa Mon Sep 17 00:00:00 2001
From: patorjk
Date: Wed, 17 Feb 2021 22:26:31 -0500
Subject: [PATCH 16/97] updated file for codesandbox
---
index.html | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/index.html b/index.html
index 8d200103..5b7eb1e5 100755
--- a/index.html
+++ b/index.html
@@ -1,5 +1,5 @@
-
+
+FuLaE#BUey8fWM+~bm0R*}sb
zyV^}>XU`vU%C2~IzMA!oqn