Designing the Game


The Brainiac game probably sounds reasonably simple from the perspective of a player, but you'll find that it still requires some effort from a programming perspective. Games generally are not simply programs to write, and Brainiac represents probably the simplest game you'll ever develop. Even so, if you take your time and think through the design of your games , you'll be much farther ahead of the curve when you sit down to hack out the code.

As with most games, the key to designing the Brainiac game is to figure out how to accurately store the state of the game at any given moment. In other words, how will you reflect what's going on in the game in variables ? Because the game is arranged as a 4x4 grid of tiles, it makes sense that the first thing you'll need is a two-dimensional array of bitmaps that identifies the tile image to be displayed for each tile. Of course, the bitmap images alone don't say anything about whether a match has been made. So, you also need another two-dimensional array that keeps track of whether a tile has been matched. Together, these two arrays have most of the knowledge required to indicate the state of the game at any given moment.

The other missing pieces to the Brainiac puzzle primarily involve the tile matching process. More specifically , you need to keep up with the two tiles that the user has currently selected so that you can display them properly, as well as perform a match test on them. If the tiles match, you just update their status in the tile state array so that they remain turned over; if not, you make sure that they get returned to their hidden state. Most of the logic in the Brainiac game takes place in the mouse handling code because mouse clicks are the primary means in which the user selects tiles and attempts to make matches.

The two remaining pieces of information critical to the design of the game are the number of matches and number of tries . The number of matches is extremely important because it determines when the game is over; because there are eight pairs of tiles, eight matches constitutes winning the game. The number of tries has more to do with keeping up with how well you did ”it's sort of a scorekeeping piece of information.

To recap, the design of the Brainiac game has led us to the following pieces of information that must be managed by the game:

  • A two-dimensional array (4x4) of tile bitmaps

  • A two-dimensional array (4x4) of tile states

  • The tiles selected by the user as a potential match

  • The number of matches

  • The number of tries

With this information in mind, you're now ready to move on and put the code together for the Brainiac game.



Sams Teach Yourself Game Programming in 24 Hours
Sams Teach Yourself Game Programming in 24 Hours
ISBN: 067232461X
EAN: 2147483647
Year: 2002
Pages: 271

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net