Skip to content

Commit 7db70d4

Browse files
committed
Adding Mode -Rush- in which the snake's speed increases every time food is eaten up to a certain limit
1 parent 75f92b3 commit 7db70d4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<option>Dark Theme by KenyStev</option>
9090
<option>Green Theme by CoffeeCatDE</option>
9191
<option>Matrix Theme by Geahad Haymor</option>
92-
<option>Theme by Senura Ratnayake</option>
92+
<option>Theme by Senura Ratnayake</option>
9393
</select>
9494
</div>
9595
<div style="display:inline-block;margin-right:10px;">
@@ -98,6 +98,7 @@
9898
<option value="100">Easy</option>
9999
<option value="75" selected>Medium</option>
100100
<option value="50">Hard</option>
101+
<option value="110">Rush</option>
101102
</select>
102103
</div>
103104
<button onclick="go_full_screen()">Full Screen</button><br />

js/snake.js

+14
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ SNAKE.Snake = SNAKE.Snake || (function() {
382382
return false;
383383
}
384384

385+
//Checks if the current selected option is that of "Rush"
386+
//If so, "increase" the snake speed
387+
var selectDropDown = document.getElementById("selectMode");
388+
var selectedOption = selectDropDown.options[selectDropDown.selectedIndex];
389+
390+
if(selectedOption.text.localeCompare("Rush") == 0)
391+
{
392+
snakeSpeed > 30 ? snakeSpeed -=5 : snakeSpeed = 30;
393+
}
394+
385395
return true;
386396
};
387397

@@ -390,6 +400,10 @@ SNAKE.Snake = SNAKE.Snake || (function() {
390400
* @method handleDeath
391401
*/
392402
me.handleDeath = function() {
403+
//Reset speed
404+
var selectedSpeed = document.getElementById("selectMode").value;
405+
snakeSpeed = parseInt(selectedSpeed);
406+
393407
handleEndCondition(playingBoard.handleDeath);
394408
};
395409

0 commit comments

Comments
 (0)