11.7 Growing Plants
In our initial description of the bears and fish model, we mentioned that fish can also be considered predators—that is, they can eat plants that exist in the water. If not enough plants are available, the fish will starve and die. It is relatively easy to include another class to represent the plants by taking code that already exists and “repackaging” it as required for a plant.
We can begin by realizing that plants will not be able to move. In addition, we will not have them eat anything. So, their only action is breeding. LISTING 11.13 shows the liveALittle method for the Plant class. Note that we are assuming that plants can attempt to breed after five time units.
LISTING 11.13 The liveALittle method in the Plant ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access