开发者

How would I go about making a local highscore table for my game?(Javascript)

Well, I made a quick whack-a-mole game in javascript. I have a counter that counts the number of clicks on the mole. My animate function is as so

    function animate0(pos) {
    pos %= urls.length;
    var animation0 = document.getElementById('animation0');
    var counter = document.getElementById('counter');
    animation0.src = urls[pos];
    if (pos == 1) { // only make onclick when have a certain image
        animation0.onclick = function() {
            counter.innerHTML = parseInt(counter.innerHTML) + 1;
    开发者_StackOverflow    }
    }
    else {
        animation0.onclick = function() {
            //do nothing
        }
    }
    setTimeout(function() {
        animate0(++pos);
    }, (Math.random()*500) + 1000);
}

I display the counter via this code,

<div id='counter'>0</div>

Although this is un-related, this is how I display the animation,

<img id='animation0' src ='http://i51.tinypic.com/sxheeo.gif'/>

I can't figure out how to make a local computer highscore table(perhaps with 5 or so spots for scores). Help? Thanks, Steven


Use cookies or HTML5 databases.

A really bad cookie example:
setCookie('highscores', '100,120,130,140,150')

And later

var highscores = getCookie('highscores').split(',') //now contains [100,120...]

Alternatively, you could store a json object as a string if you wanted to store names and other data. The data format might look like this:

[{name: 'STK', score: 1100}, {name: 'ASS', score:'1000'}]

You would need to use a JSON handling library (in jquery, or something else) to stringify your array and then parse it later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜