-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTMLManager.js
72 lines (58 loc) · 2.07 KB
/
HTMLManager.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
62
63
64
65
66
67
68
69
70
71
72
function HTMLManager() {
this.gameComplete = document.getElementById('gameComplete');
this.puzzleScore = document.getElementById('puzzleScore');
this.gameEnd = document.getElementById('gameEnd');
this.scoreShow = document.getElementById('scoreShow');
this.nameInput = document.getElementById('nameInput');
this.addBtn = document.getElementById('addBtn');
this.highScoreList = document.getElementById('highScoreList');
this.header = document.querySelector('header');
this.canvas = document.querySelector('canvas');
}
HTMLManager.prototype.hide = function(elem) {
elem.style.display = 'none';
};
HTMLManager.prototype.show = function(elem) {
elem.style.display = '';
};
HTMLManager.prototype.updateHighScores = function(highScores) {
var self = this;
this.highScoreList.innerHTML = '';
highScores.forEach(function(user) {
var li = document.createElement('li');
li.innerHTML = user.score + ' by ' + user.name;
self.highScoreList.appendChild(li);
});
};
HTMLManager.prototype.showInitUI = function() {
this.show(this.canvas);
};
HTMLManager.prototype.showStartUI = function(puzzle, score) {
this.header.innerHTML = '<h2>Puzzle: ' + (puzzle+1) + ' Score: ' + score + '</h2>';
this.hide(this.gameComplete);
this.hide(this.gameEnd);
};
HTMLManager.prototype.showFinishUI = function() {
this.show(this.gameComplete);
};
HTMLManager.prototype.showEndUI = function(score) {
this.show(this.gameEnd);
this.show(this.nameInput);
this.show(this.addBtn);
this.hide(this.gameComplete);
this.hide(this.canvas);
this.header.innerHTML = '<h2>Congratulations!</h2>';
this.scoreShow.innerHTML = score;
};
HTMLManager.prototype.finishMessage = function(thisPuzzleScore, puzzle, score) {
if (thisPuzzleScore > 0) {
this.puzzleScore.innerHTML = 'You got ' + thisPuzzleScore + ' !';
} else {
this.puzzleScore.innerHTML = 'You got zero! haha...';
}
this.header.innerHTML = '<h2>Puzzle: ' + (puzzle+1) + ' Score: ' + score + '</h2>';
};
HTMLManager.prototype.showAddScoreUI = function() {
this.hide(this.addBtn);
this.hide(this.nameInput);
};