started writing highscore code

This commit is contained in:
meadowstream 2014-07-24 11:16:53 -04:00
parent 37f9345a27
commit f3a0741ab8
4 changed files with 18 additions and 34 deletions

View file

@ -20,7 +20,6 @@ function hidebottombar() {
}
function initialize(a) {
//view.js
window.iframHasLoaded = false;
window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"];
window.hexColorsToTintedColors = {
@ -46,7 +45,7 @@ function initialize(a) {
window.hexagonBackgroundColor = 'rgb(236, 240, 241)';
window.hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)';
window.centerBlue = 'rgb(44,62,80)'; //tumblr?
window.centerBlue = 'rgb(44,62,80)';
window.angularVelocityConst = 4;
window.scoreOpacity = 0;
window.textOpacity = 0;
@ -123,11 +122,11 @@ function initialize(a) {
window.prevScore = 0;
window.numHighScores = 3;
window.highscores = [0, 0, 0];
window.highscores = [];
if(localStorage.getItem('highscores'))
highscores = localStorage.getItem('highscores').split(',').map(Number);
highscores = JSON.parse(JSON.parse(localStorage.getItem('highscores')));
localStorage.setItem('highscores', highscores);
localStorage.setItem('highscores', JSON.stringify(highscores));
window.blocks = [];
window.MainHex;

View file

@ -213,6 +213,9 @@ function animLoop() {
render();
if (checkGameOver() && !importing) {
gameState = 2;
highscores.push(score);
localStorage.setItem('highscores', JSON.stringify(highscores));
setTimeout(function(){
enableRestart();
}, 150);
@ -273,18 +276,6 @@ function enableRestart() {
canRestart = 1;
}
function updateHighScore(){
for(var i = 0; i<numHighScores;i++) {
if(highscores[i]<=score) {
highscores.splice(i,0,score);
highscores = highscores.slice(0,3);
break;
}
}
localStorage.setItem('highscores', highscores);
}
function isInfringing(hex){
for(var i=0;i<hex.sides;i++){
var subTotal=0;

View file

@ -27,6 +27,8 @@ function exportSaveState() {
state.blocks.map(descaleBlock);
}
localStorage.setItem('highscores', JSON.stringify(highscores));
return JSONfn.stringify(state);
}

View file

@ -72,17 +72,6 @@ function drawPolygon(x, y, sides, radius, theta, fillColor, lineWidth, lineColor
ctx.strokeStyle = 'rgba(0,0,0,0)';
}
function showHighScores() {
$('#highscores').html(function() {
var str = '<li> High Scores: </li><br><br>';
for (var i = 0; i < highscores.length; i++) {
str += '<li>' + highscores[i]+'</li>';
}
return str;
});
toggleClass('#highscores', 'not-visible');
}
function toggleClass(element, active) {
if ($(element).hasClass(active)) {
$(element).removeClass(active);
@ -104,8 +93,11 @@ function showText(text){
debugger;
var allZ = 1;
var i;
highscores.sort(function(a,b){a = parseInt(a, 10); b = parseInt(b, 10); if (a < b) {return 1;} else if (a > b) {return -1;}else {return 0;}});
localStorage.setItem('highscores', JSON.stringify(highscores));
debugger;
for (i = 0; i < 3; i++) {
if (highscores[i] !== undefined && (highscores[i] != 0 || (highscores[0] == 0 && i==0))) {
if (highscores.length > i) {
messages['gameover'] += "<tr> <th class='tg-031e'>"+(i+1)+".</th> <th class='tg-031e'>"+highscores[i] + " pts</th> </tr>";
}
}
@ -121,14 +113,14 @@ function showText(text){
if (allZ) {
for (i = 0; i < highscores.length; i++) {
if (highscores[i] != 0) {
if (highscores[i] !== 0) {
allZ = 0;
}
}
}
}
$("#overlay").html(messages[text]);
$("#overlay").fadeIn("1000","swing")
$("#overlay").fadeIn("1000","swing");
if (text == 'paused') {
if (settings.platform == 'mobile') {
text = 'pausedMobile';
@ -157,12 +149,11 @@ function setMainMenu() {
}
}
function hideText(text){
function hideText() {
$("#overlay").fadeOut("1000",function(){$("#overlay").html("");})
}
function gameOverDisplay(){
updateHighScore();
$("#attributions").show();
var c = document.getElementById("canvas");
c.className = "blur";
@ -182,6 +173,7 @@ function togglePlayIcon (){
function pause(o) {
localStorage.setItem('highscores', JSON.stringify(highscores));
var message;
togglePlayIcon();
if (o) {