Modeling High Score Data


I would love to tell you that I'm going to show you how to create a classic arcade game high score feature in which you get to enter your name or initials, and then see them displayed for all to see. Unfortunately, the seemingly simple task of allowing a player to enter his name or initials is fairly complex from a game programming perspective. Or more accurately, it requires a significant enough sidestep from the topic at hand that I don't want to burden you with the details. So, you're instead going to focus on a high score list that simply keeps up with the top five scores for a game, without any personalization associated with the scores. Although this approach to keeping track of a high score list doesn't give credit for each score, it's still a useful means of keeping up with the top five scores for a game.

Because you aren't going to worry with storing the name of the person for each score, you only have to contend with storing away five numbers . At this point, you have to consider how many digits you need to represent the maximum possible score for a game. In the case of the Space Out game, it's virtually impossible to score beyond four digits, which means that you can safely make a five-digit score the maximum. This also means that each score in the high score list is capable of having five digits. Of course, the number of digits in an integer in the game isn't really a critical factor; the number of digits enters the picture when it comes time to store the scores to disk, and then read them back.

The maximum number of digits in a high score is important because you're going to store that many digits for a score even if it doesn't need that many. This makes the scores much easier to read after you've written them to disk. So, as an example, if the highest score is 1250, you obviously only need four digits to represent the score. However, the score needs to be stored on disk as 01250 to make it fit within a five-digit storage space. Each of the numbers in the high score list is stored this way.

Getting back to the Space Out game itself, after the high scores are read from disk, they are treated as normal integers. In fact, a simple array of integers is sufficient to represent the high score list. So, the process of reading and writing the high score list involves initializing and then storing away an array of integers. The next section gets into more detail about how exactly you use the Win32 API to read and write data using files.



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