Skip to content

Commit

Permalink
Use Firebase for highscores
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielhere committed Feb 3, 2016
1 parent b760429 commit 5b02ce7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ $(document).ready(function() {
var canvasWidth = $("#canvas").width();
var canvasHeight = $("#canvas").height();


// CREATING THE SNAKE
var snakeWidth = 15;
var direction;
var food;
var snake;
var score;
var speed;
var highscore = localStorage.getItem("highscore") || 0;
var highscore;
var newHS = new Firebase("https://blinding-torch-4399.firebaseio.com/");
newHS.child("highscore").on("value", function(snap){
highscore = snap.val();
$("#highScore").text(highscore);
});
var headColor = "green",
colorFood = "yellow",
bodyColor = "white",
Expand Down Expand Up @@ -148,7 +152,7 @@ $(document).ready(function() {
$(".currentScore").text("Your score: " + score);
if(score > highscore) {
highscore = parseInt(score);
localStorage.setItem("highscore", highscore);
newHS.child('highscore').set(highscore);
}
$("#highScore").text(highscore);

Expand Down

0 comments on commit 5b02ce7

Please sign in to comment.