-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (56 loc) · 2.23 KB
/
Copy pathscript.js
File metadata and controls
64 lines (56 loc) · 2.23 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Game from './modules/Game.js';
import Params from './modules/Params.js';
const strings = {
"fr": {
"title": "Boole and the Boulders",
"description": "C'est la fin du monde. Des rochers tombent du ciel et Boole la grenouille veut survivre.",
"game-over": "Game Over",
"game-over-description": "R.I.P. Boole",
"instruction-1": "Évite les rochers qui tombent",
"instruction-2": "Déplace Boole avec les flèches",
"instruction-3": "Ramasse les bonus pour que Boole utilise ses pouvoirs de reproduction",
"click-start": "Clique ici pour jouer",
"click-dead": "Clique ici pour réessayer",
"score": "Score :",
"best-score": "Record :",
"mute": "Muet"
},
"en": {
"title": "Boole and the Boulders",
"description": "This is the end of the world. Boulders are falling from the sky and Boole the frog wants to live.",
"game-over": "Game Over",
"game-over-description": "R.I.P. Boole",
"instruction-1": "Avoid the falling boulders",
"instruction-2": "Move Boole with the arrow keys",
"instruction-3": "Pick up the bonuses to activate Boole's reproductive powers",
"click-start": "Click here to play",
"click-dead": "Click here to try again",
"score": "Score:",
"best-score": "Best score:",
"mute": "Mute"
}
};
let game;
window.addEventListener('DOMContentLoaded', () => {
// Translate game
const requestedLang = (new URLSearchParams(window.location.search)).get('lang') ?? '';
let lang = 'en';
switch (requestedLang) {
case 'fr': lang = 'fr'; break;
}
document.querySelectorAll('[data-string]').forEach(e => e.innerText = strings[lang][e.getAttribute('data-string')]) ?? 'undefined string';
document.body.setAttribute('data-translated', 'true');
// Display best score
const bestScoreElements = document.querySelectorAll('.best-score');
bestScoreElements.forEach(e => e.innerHTML = Number(localStorage.getItem(Params.savePath)) || 0);
// Enable play buttons
const playButtons = document.querySelectorAll('.play-button');
playButtons.forEach(button => {
button.addEventListener('click', () => {
game = new Game();
game.start();
});
});
// Focus title screen play button
document.querySelector('.first-start').focus();
});