Merge branch 'gh-pages' of https://github.com/teamsnowman/hextris into gh-pages

This commit is contained in:
lengstrom 2014-06-23 22:26:05 -04:00
commit b7f475724f
2 changed files with 20 additions and 16 deletions

View file

@ -1,9 +1,9 @@
var prevGameState; var prevGameState;
function showText(text){ function showText(text){
var messages = { var messages = {
'paused':"<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectablecenteredSubHeader'>Press p to resume</div>", 'paused':"<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectable centeredSubHeader'>Press p to resume</div>",
'start':"<div class='centeredHeader unselectable' style='line-height:80px;' >Press enter to start</div>", 'start':"<div class='centeredHeader unselectable' style='line-height:80px;' >Press enter to start</div>",
'gameover':"<div class='centeredHeader unselectable'> Game Over: "+score+" pts</div><br><div class='unselectablecenteredSubHeader'>Press enter to restart</div>", 'gameover':"<div class='centeredHeader unselectable'> Game Over: "+score+" pts</div><br><table class='tg' style='margin:0px auto'> <tr> <th class='tg-031e'>1.</th> <th class='tg-031e'>"+highscores[0]+"</th> </tr> <tr> <td class='tg-031e'>2.</td> <th class='tg-031e'>"+highscores[1]+"</th> </tr> <tr> <td class='tg-031e'>3.</td> <th class='tg-031e'>"+highscores[2]+"</th> </tr> </table><br><div class='unselectable centeredSubHeader'>Press enter to restart</div>",
}; };
var pt = document.getElementById("overlay"); var pt = document.getElementById("overlay");

View file

@ -319,25 +319,27 @@ function animLoop() {
requestAnimFrame(animLoop); requestAnimFrame(animLoop);
update(); update();
render(); render();
gameOverDisplay(); }
highscores = localStorage.getItem('highscores').split(',').map(Number);
for (var i = 0; i < numHighScores; i++) {
if (highscores[i] < score) {
for (var j = numHighScores - 1; j > i; j--) {
highscores[j] = highscores[j - 1];
}
highscores[i] = score;
break;
}
}
localStorage.setItem('highscores', highscores);
}
else { else {
setStartScreen(); setStartScreen();
} }
} }
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);
break;
}
}
localStorage.setItem('highscores', highscores);
}
requestAnimFrame(animLoop); requestAnimFrame(animLoop);
function isInfringing(clock){ function isInfringing(clock){
for(var i=0;i<clock.sides;i++){ for(var i=0;i<clock.sides;i++){
@ -355,6 +357,8 @@ function isInfringing(clock){
function checkGameOver() { function checkGameOver() {
for (var i = 0; i < MainClock.sides; i++) { for (var i = 0; i < MainClock.sides; i++) {
if (isInfringing(MainClock)) { if (isInfringing(MainClock)) {
updateHighScore();
gameOverDisplay();
return true; return true;
} }
} }