36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
// This is the maximum level the player has reached.
|
|
let maximum_level = localStorage.getItem("maximum_level");
|
|
|
|
if (maximum_level == null) {
|
|
// This should be 1. 10 is for testing.
|
|
maximum_level = 1;
|
|
} else {
|
|
maximum_level = parseInt(maximum_level);
|
|
}
|
|
|
|
// From this, we generate a list of buttons. We also check if the
|
|
// player has already played the level but quit inbetween, thus having
|
|
// a saved state. The order is from the highest level, because
|
|
// naturally, the player wants to get back to playing there.
|
|
for (let i = maximum_level; i > 0; --i) {
|
|
let button = document.createElement("button");
|
|
// Check if the level is stored.
|
|
if (localStorage.getItem(i + "-seconds_elapsed") == null) {
|
|
button.innerText = "Level " + i;
|
|
} else {
|
|
button.innerText = "(Continue) Level " + i;
|
|
}
|
|
|
|
let high_score = localStorage.getItem(i + "-high_score");
|
|
if (high_score != null) {
|
|
button.innerText += " (high score: " + get_seconds_readable(parseInt(high_score)) + ")";
|
|
}
|
|
|
|
button.onclick = function() {
|
|
$("#main-menu").style = "display:none;";
|
|
$("#game-view").style = "display:flex;";
|
|
start_or_continue_game(i);
|
|
};
|
|
$("#button-list").appendChild(button);
|
|
}
|