-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.js
57 lines (54 loc) · 1.74 KB
/
View.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
const currentScoreDisplay = document.querySelectorAll('.current-score');
const numOfBallsDisplay = document.getElementById('ball-count');
const highScoreDisplay = document.getElementById('high-score');
const View = {
drawBlocks() {
blocks = blocks.filter(block => block.number > 0);
blocks.forEach(block => block.draw());
blocks.forEach(block => block.drawNum());
},
moveBlocks() {
blocks.forEach(block => block.move());
},
moveBalls() {
balls = balls.filter(ball => !Boundary.checkOut(ball));
balls.forEach(ball => {
ball.move();
});
return balls;
},
drawLauncher() {
const launchball = new Ball(0, canvas.width/2, canvas.height - 15);
launchball.draw();
BallDirection.changeAngle(launchAngle);
},
updateCurrentScore() {
for (let i = 0; i < currentScoreDisplay.length; i += 1) {
currentScoreDisplay[i].textContent = currentScore;
}
},
updateBallCount() {
numOfBallsDisplay.textContent = numOfBalls;
},
updateInfo() {
this.updateBallCount();
this.updateCurrentScore();
},
updateHighScore() {
highScoreDisplay.textContent = highScore;
},
gameOver() {
if (currentScore > highScore) {
localStorage.setItem('BlockBreakerHighScore', currentScore);
highScore = currentScore;
this.updateHighScore()
document.querySelector('.results').style.color = '#00FF00';
document.querySelector('.results').textContent = 'New High Score!';
} else {
document.querySelector('.results').style.color = '#FF0000';
document.querySelector('.results').textContent = 'Try Again!';
}
document.querySelector('.game-over').classList.toggle('display-modal');
document.getElementById('blocks').classList.toggle('game-is-over');
}
}