From ab3b6ca01c53d0b3c1b1ed07b3acdce44e6f9cc5 Mon Sep 17 00:00:00 2001 From: ankit918 <56554166+ankit918@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:51:02 +0530 Subject: [PATCH 1/6] Update index.html --- index.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 23510e9..87ce678 100644 --- a/index.html +++ b/index.html @@ -1,3 +1,6 @@ - - \ No newline at end of file +
EASY MODE
+
NORMAL MODE
+
HARD MODE
+
+ From cfc9ded272ce8cf942389a740ba1e2bd673f5dc1 Mon Sep 17 00:00:00 2001 From: ankit918 <56554166+ankit918@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:52:05 +0530 Subject: [PATCH 2/6] Update index.html --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 87ce678..e3e4756 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@
EASY MODE
-
NORMAL MODE
-
HARD MODE
+
NORMAL MODE
+
HARD MODE
From 13dcacdb7039b05c6b26c9578c6a4363ad8618ca Mon Sep 17 00:00:00 2001 From: ankit918 <56554166+ankit918@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:59:54 +0530 Subject: [PATCH 3/6] Update scripts.js --- scripts.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts.js b/scripts.js index 979cfd3..119945c 100644 --- a/scripts.js +++ b/scripts.js @@ -65,7 +65,7 @@ function Snake(length, bodyColour, outlineColour, startingPos) { }; this.create(); } - +var speed = 0.5 Snake.prototype.move = function() { if (this.nd.length) { this.direction = this.nd.shift(); @@ -77,16 +77,16 @@ Snake.prototype.move = function() { switch(this.direction) { case 'right': - this.nx++; + this.nx += speed; break; case 'left': - this.nx--; + this.nx -= speed; break; case 'up': - this.ny--; + this.ny -= speed; break; case 'down': - this.ny++; + this.ny += speed; break; } @@ -251,3 +251,8 @@ if (!window.cancelAnimationFrame) { clearTimeout(id); }; } +function easy(){speed = 0.4} + +function normal(){ speed = 0.8} + +function hard(){speed = 1.2} From 9065b8cd4c6077a8ebcbc553f7ba721c8da4c7ea Mon Sep 17 00:00:00 2001 From: ankit918 <56554166+ankit918@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:44:08 +0530 Subject: [PATCH 4/6] Update index.html --- index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index e3e4756..8c189c7 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@ -
EASY MODE
-
NORMAL MODE
-
HARD MODE
+
EASY MODE
+
NORMAL MODE
+
HARD MODE
From 95861c544f68e7170fe4c20fbbdf6407301448f2 Mon Sep 17 00:00:00 2001 From: ankit918 <56554166+ankit918@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:07:10 +0530 Subject: [PATCH 5/6] Update scripts.js --- scripts.js | 64 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/scripts.js b/scripts.js index 119945c..2a61664 100644 --- a/scripts.js +++ b/scripts.js @@ -65,7 +65,7 @@ function Snake(length, bodyColour, outlineColour, startingPos) { }; this.create(); } -var speed = 0.5 +var speed = 10 Snake.prototype.move = function() { if (this.nd.length) { this.direction = this.nd.shift(); @@ -77,16 +77,16 @@ Snake.prototype.move = function() { switch(this.direction) { case 'right': - this.nx += speed; + this.nx++ break; case 'left': - this.nx -= speed; + this.nx-- break; case 'up': - this.ny -= speed; + this.ny-- break; case 'down': - this.ny += speed; + this.ny++ break; } @@ -169,13 +169,15 @@ function Food() { } var game = new Object(); -game.fps = 20; +game.fps = speed; game.score = 0; game.scoreText = 'Score: '; game.drawScore = function() { canvas.paintText(this.scoreText + this.score); }; +var a = 1 game.runLoop = function(){ + if(a >= 1){ setTimeout(function() { requestAnimationFrame(game.runLoop); mainSnake.move(); @@ -183,7 +185,9 @@ game.runLoop = function(){ food.draw(); } game.drawScore(); - }, 1000 / game.fps); + }, 1000 / speed); + a++ +} }; game.start = function() { mainSnake = new Snake(10, 'red', 'white', {x: 5, y: 5}); @@ -251,8 +255,46 @@ if (!window.cancelAnimationFrame) { clearTimeout(id); }; } -function easy(){speed = 0.4} - -function normal(){ speed = 0.8} +var bt = document.getElementById('buttons') +function str(e){ + a = 1 + game.runLoop() + bt.style.display = 'none'; + if(e == 'bt1'){ + game.over(); + return; + } +} +function change(p) { + + if (p.value == 'Easy Mode') { + a = 0 + bt.style.display = 'block'; + speed = 5 + + + } + if (p.value == 'Normal Mode') { + a = 0 + bt.style.display = 'block'; + speed = 10 + } + if (p.value == 'Hard Mode') { + a = 0 + bt.style.display = 'block'; + speed = 20 + } + + if (p.value == 'Harder Mode') { + a = 0 + bt.style.display = 'block'; + speed = 25 + } + + if (p.value == 'Expert Mode') { + a = 0 + bt.style.display = 'block'; + speed = 30 + } -function hard(){speed = 1.2} +} From 37ec3c4064ecebbcaf5dea7c96d8f38836160be8 Mon Sep 17 00:00:00 2001 From: ankit918 <56554166+ankit918@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:09:37 +0530 Subject: [PATCH 6/6] Update index.html --- index.html | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 8c189c7..ba65f84 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,14 @@ - -
EASY MODE
-
NORMAL MODE
-
HARD MODE
+ + +
+ +