This final project in Introduction to C++ was designed to demonstrate polymorphic routines and pointer arrays. Since arrays are immutable once set, objects directly stored inside of them can not be added, modified or removed. As a result, establishing an array of pointers to pointers is required, as the value of a pointer can be modified to either be null or point to an object.
This program consists of one abstract superclass (organism) and two subclasses (humans and zombies). With every iteration of the program each pointer in the array is checked to see if an organism is referenced and then, depending on what kind of organism is located within that part of the array, the program executes one of several behavioral functions:
- Humans can only move on either the X or Y axis (vertically or horizontally) and move into an available space in the array.
- If a Human has moved more than 3 times it will try to give birth into an available ajacent space in the array.
- Zombies can move on both the X and Y axis simultaneously (vertically, horizontally and diagonally) into an available space in the array.
- Zombies look around for an available Human to eat and move to the cell that the Human occupies.
- If a Zombie has moved more than 8 times, it will convert the next Human it encounters into a Zombie.
- If a Zombie has not eaten in more than 2 moves it will starve and convert back into a Human.