Step 19
We can keep score and when all bricks are broken, show a message indicating the user won the game.
if (!isGameOver) {
- window.requestAnimationFrame(draw);
+ if (score == brickRowCount * brickColumnCount) {
+ window.alert("You won!");
+ } else {
+ window.requestAnimationFrame(draw);
+ }
} else {
window.alert("Game over!");
}
Save your code and observer the changes in the browser.
You can add some final touches to this game. For instance, you can randomize the initial position of the ball and its movement direction. In addition, you can add difficulty levels by, e.g., arranging bricks more sparsely, etc. I will leave that to you!