-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
35 lines (27 loc) · 1 KB
/
main.js
File metadata and controls
35 lines (27 loc) · 1 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
import { HighScoreManager } from './game/HighScoreManager.js';
import { UI, hideScreens, showStartScreenScores, showGameOverScores } from './ui/ui.js';
import { Game } from './game/Game.js';
const scoreManager = new HighScoreManager();
const game = new Game('gameCanvas', 20, scoreManager);
window.addEventListener('DOMContentLoaded', async () => {
await scoreManager.load();
await scoreManager.display(); // shows scores on home screen
});
async function startGame() {
hideScreens();
await scoreManager.load();
await showStartScreenScores(scoreManager);
game.start();
}
async function submitHighScore() {
const input = UI.playerNameInput;
const name = input.value.trim().substring(0, 8).toUpperCase();
if (!name) return;
const score = scoreManager.pendingScore;
await scoreManager.submit(name);
await showGameOverScores(scoreManager, name, score);
UI.nameInput.style.display = 'none';
}
window.startGame = startGame;
window.restartGame = startGame;
window.submitHighScore = submitHighScore;