Game Development Reference
In-Depth Information
Chapter 17
Finishing the Jewel Jam Game
In this chapter, you finish the Jewel Jam game. As a first step, you give the player extra points when
multiple combinations of three jewels happen. Second, you add a nice visual effect by showing
glitters on the jewels in the game. Finally, you add sound and music.
Extra Points for Multiple Combinations
You want to give the player extra points when multiple combinations occur. Whenever the player
makes a combination of three jewels, new random jewels are added to the playing field. These
jewels can form new combinations. In addition, new combinations can be formed by jewels falling
down. You award the player extra points in cases where there are two or three combinations.
In order to do that, you have to count how many combinations a player finds. You do this in the
JewelGrid class, by introducing an extra variable nrCombis :
var nrCombis = 0;
Every time you find a valid combination, you increment this variable. Now you can use an if
instruction to check when you should award extra points:
if (nrCombis === 2) {
score.score += 50;
}
else if (nrCombis >= 3) {
score.score += 100;
}
235
 
Search WWH ::




Custom Search