Placing the gems for real

Preventing the game field from starting with successful streaks means coding all the required routines to see if a given gem is part of a successful streak. There is a lot to code, but the good news is the functions to check for successful streaks that we are about to write are the same as we will use when the player starts swapping gems.

The idea: When it's time to place a gem, check if the gem we are about to place will form a successful streak. In this case, keep generating random gems until it's no longer part of a streak. Finally place the gem.

The development: Checking for a successful streak is not different from checking for victory in Connect 4. We can even say it's easier since we only have to look horizontally ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.