highscores

This commit is contained in:
Garrett Finucane 2014-07-19 21:46:05 -04:00
parent 54ee9642d3
commit 06a3a31e11
2 changed files with 8 additions and 10 deletions

View file

@ -267,14 +267,11 @@ function enableRestart() {
}
function updateHighScore(){
if(localStorage.getItem('highscores')){
highscores = localStorage.getItem('highscores').split(',').map(Number);
}
for (var i = 0; i < numHighScores; i++) {
if (highscores[i] <= score) {
highscores.splice(i, 0, score);
highscores = highscores.slice(0,-1);
//debugger;
for(var i = 0; i<numHighScores;i++) {
if(highscores[i]<=score) {
highscores.splice(i,0,score);
highscores = highscores.slice(0,3);
break;
}
}
@ -298,7 +295,6 @@ function isInfringing(hex){
function checkGameOver() {
for (var i = 0; i < MainHex.sides; i++) {
if (isInfringing(MainHex)) {
updateHighScore();
gameOverDisplay();
return true;
}

View file

@ -103,9 +103,10 @@ function showText(text){
if (text == 'gameover') {
var allZ = 1;
var i;
console.log(highscores);
for (i = 0; i < 3; i++) {
if (highscores[i] !== undefined && highscores[i] != 0) {
messages['gameover'] += "<tr> <th class='tg-031e'>1.</th> <th class='tg-031e'>"+highscores[i] + " pts</th> </tr>";
messages['gameover'] += "<tr> <th class='tg-031e'>"+(i+1)+".</th> <th class='tg-031e'>"+highscores[i] + " pts</th> </tr>";
}
}
@ -204,6 +205,7 @@ function hideText(text){
pt.innerHTML = '';
}
function gameOverDisplay(){
updateHighScore();
var c = document.getElementById("canvas");
c.className = "blur";
showText('gameover');