-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevels.js
34 lines (30 loc) · 1.36 KB
/
Levels.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Basically the same as getLeaderBoard() from the Save.js
//Returns the level access list stored in local storage,
//if it doesn't exist, creates a new one
function getLevelAccess(){
let access = JSON.parse(localStorage.getItem("levelAccess"));
if (access === null){
//Boolean list, index 0 - Medium access, index 1 - Hard access
//This is because Easy should always be accessable.
access = [false,false];
localStorage.setItem("levelAccess",JSON.stringify(access));
}
return access;
}
function leaderBoardLoad(diff){
sessionStorage.setItem("difficulty",diff);
goToPage('Leaderboard.html');
}
//Runs as the page loads:
//If player wishes to access the leaderboard, adjust the buttons to redirect them
if (sessionStorage.getItem("leaderBoard") == "true"){
document.getElementById("easy").setAttribute("onClick","leaderBoardLoad(0)");
document.getElementById("medium").setAttribute("onClick","leaderBoardLoad(1)");
document.getElementById("hard").setAttribute("onClick","leaderBoardLoad(2)");
}
//If the player is trying to play the game, lock certain levels until they meet a scoring thresh hold.
else if (sessionStorage.getItem("multiplayer") == 0){
let levelAccess = getLevelAccess();
document.getElementById("medium").disabled = !levelAccess[0];
document.getElementById("hard").disabled = !levelAccess[1];
}