Chapter 10. Games

A computer game, or other kind of simulated world, will contain a number of agents, or critters, each with its own sprite. It’s natural to have a Game base class to hold the active array of critters. As well as being a container, the Game class should take on some additional duties. When the play begins, the Game object initializes the geometry of the world and adds in the critters. While the play continues, the Game object repeatedly updates the critters and shows them on the screen. At the same time, the Game object tracks the critters’ status and decides when the world should be moved to a new level. And the play ends when the Game object decides that it’s over.

We implement these design ideas as the cGame class that makes ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.