-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
61 lines (43 loc) · 1.49 KB
/
main.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
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
import ImageSprite, {
getImage,
RenderImageSprites,
} from "./js/sprites/imageSprite.js";
import { sprites } from "./js/globals.js";
import Rover from "./js/sprites/rover.js";
import Background from "./js/sprites/background.js";
import Star from "./js/sprites/star.js";
import highscoreManager, { Score } from "./js/highscoreManager.js";
import Alien from "./js/sprites/alien.js";
import randomNumber from "./js/randomNumber.js";
const qs = (q) => document.querySelector(q);
const bSave = qs("#e");
const bGetL = qs("#g");
const bClrL = qs("#l");
const lScrL = qs("#o");
const header = qs("#lh");
const pScore = qs("#s");
let rover;
window.onload = () => {
new Background();
rover = new Rover();
new Alien();
console.log(sprites);
new Star();
};
bSave.onclick = () => {
document.body.innerHTML = "<p>Refresh for new game</p>";
let name = window.prompt("Your name", "Harry Potter");
let score = rover.getScore();
highscoreManager.write(Score(name !== null && name !== '' ? name : 'Anonymous' + randomNumber(500), score));
};
bGetL.onclick = () => {
const scores = highscoreManager.read();
scores.sort((a, b) => b.score - a.score);
header.innerHTML = "<=Leaderboard=>";
lScrL.innerHTML = "";
scores.map((v) => (lScrL.innerHTML += `<li>| ${v.name} -> ${v.score} |</li>`));
};
bClrL.onclick = () => confirm('are u sure?') ? highscoreManager.clear() : console.log('canceled');
export function DisplayScore(score) {
pScore.innerHTML = score;
};