Skip to content

Commit

Permalink
add javascript file from different repo
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielhere committed Feb 3, 2016
1 parent 45c6f1d commit 0a5944a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
var food;
var snake;
var score;
var highscore = 0;
var highscore = localStorage.topScore;
var speed;
var headColor = "green",
colorFood = "yellow",
bodyColor = "white",
canvasFill = "black";
var storage;
var run = $("#run")[0];
var die = $("#die")[0];
var eat = $("#eat")[0];

function startGame(){
score = 0;
Expand All @@ -29,14 +31,17 @@
if(typeof loop_game !== "undefined")
clearInterval(loop_game);
loop_game = setInterval(render, speed);
}
run.play();
};


// BUTTON FUNCTIONS
$(".start").on("click", function(event) {
startGame();
$("#canvas").css("visibility", "100");
$(".start").css("display", "none");
$(".reset").css("display", "inline-block");
$(".pause").css("display", "inline-block");
});

$(".reset").on("click", function(event) {
Expand Down Expand Up @@ -76,13 +81,13 @@
$(".pause").css("display", "inline-block");
$(".reset").css("display", "inline-block");
$(".playAgain").css("display", "none");
$(".home").css("display", "none");
});

$(".home").on('click', function(event) {
location.reload(true);
});


function snakeMake(){
var length = 10;
snake = [];
Expand Down Expand Up @@ -135,14 +140,22 @@
$(".playAgain").css("display", "inline-block");
$(".home").css("display", "inline-block");
$(".score").text("TOTAL SCORE: " + score);
return;
run.pause();
die.pause();
die.play();
}

storage = localStorage.setItem('topScore', highscore);
$(".currentScore").text("Your score: " + score);
$("#highScore").text(localStorage.topScore);
if(score > localStorage.getItem('topScore')){
highscore ++;
}

if(newX === food.x && newY === food.y){
tail = {x: newX, y: newY};
score ++;
eat.play();
randomGoods();
} else {
tail = snake.pop();
Expand Down

0 comments on commit 0a5944a

Please sign in to comment.