This page is optimized for mobile devices, if you would prefer the desktop version just click here

0.12 Slick0220: simulating a pandemic

Learn how to write a program that simulates the spread of a fatal communicable disease within a population.

Table of contents

Preface

This module is one in a collection of modules designed to teach you about the anatomy of a game engine.

Although the modules in this collection will concentrate on the Java game library named Slick2D, theconcepts involved and the knowledge that you will gain is applicable to different game engines written in different programming languages as well.

The purpose of this module is to teach you how to write a program that simulates the spread of a fatal communicable disease within a population (a pandemic) .

Viewing tip

I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the imagesand listings while you are reading about them.

Figures

  • Figure 1 . The disease has gained a foothold.
  • Figure 2 . The disease has spread into the population.
  • Figure 3 . The disease has receded after killing many in the population.

Listings

Preview

In an earlier module titled Slick0210: Collision detection and sound , you learned how to write a non-trivial program involving thousands ofsprites, collision detection, and sound. We will take that concept considerably further in this module by writing a program that simulates thespread of a fatal communicable disease within a population (a pandemic) and displays the results in animated graphic form.

The disease has gained a foothold

Figure 1 shows the result of inserting a single infected sprite into a population of healthy sprites. Healthy sprites arecolored green and infected sprites are colored red.

By the time the screen shot in Figure 1 was taken, the disease had gained a foothold, several other sprites had become infected, andeight of the original 1000 sprites had died, leaving only 992 live sprites including the seven that are infected.

Figure 1 . The disease has gained a foothold.

The disease has spread into the population

Figure 2 shows the situation some time later when the disease has spread considerably. By this point, many sprites have becomeinfected (and are infecting others) and only 763 of the original 1000 sprites are still alive including those that are infected.

Figure 2 . The disease has spread into the population.

The disease has receded

Figure 3 shows the situation much later. For the set of properties used to run this simulation, the pandemic appears to be receding with 341 of the 1000 original spritesstill alive.

<< Chapter < Page Page > Chapter >>

Read also:

OpenStax, Anatomy of a game engine. OpenStax CNX. Feb 07, 2013 Download for free at https://legacy.cnx.org/content/col11489/1.13
Google Play and the Google Play logo are trademarks of Google Inc.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.