PART FIVE
CROPS

NEW CLASSES

Adding Entities

PROJECT ORGANIZATION

Composition "has-a"

Inheritance  "is-a"

IMPLEMENTING ENTITIES

Entity

Corn and Potato

Cell 

World

CHECKPOINT
At this point, you should be able to see the image above, with at least one corn and potato hardcoded into the program

CHECKING VALID TERRAIN

Dirt Class

Entity Class

We do two things here, and the order matters.  

First, we check if the terrain is a Dirt.  Then, we tell Java: "Hey, I promise this Terrain is actually a Dirt.  So let's treat it as a an object of class Dirt."

This allows you to access Dirt-specific methods by explicitly casting it.  Be careful - if you convert something improperly, you'll get a ClassCastException

World Class

CHECKPOINT
Try placing crops on invalid terrain locations, such as Water and Grass. 

GROWTH

Entity

Plant

Crop

World

Notice that in this example, I chose to make a temporary variable rather than casting twice.  This just makes it easier to read.

CHECKPOINT
Run your program and water crops and try ending the day a few times.
The crops counter should increase each time.

MATURITY

Plant 

Corn and Potato

For now, we can demonstrated maturity in the render() method by making a circle around the plant.

CHECKPOINT
Run your code... at this point, we' should now be able to see