highscores
This commit is contained in:
parent
54ee9642d3
commit
06a3a31e11
2 changed files with 8 additions and 10 deletions
14
js/main.js
14
js/main.js
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue