Procedural items
Now that the player and enemies have been taken care of, let's turn our attention to items. We have a number of classes that can have their member variables assigned randomly. We'll set up the potion class the way we set up the humanoid class, where we created a number of distinct objects from a single class.
Random Gem and Heart classes
We'll start with the smallest classes, namely Heart and Gem. These are very simple classes that have a single variable that is currently hard-coded. Let's update this so that their values are randomly generated every time they are created. Since we want this to happen each time an object is created, we'll place it in the items' constructors.
In Gem::Gem, we'll make the following change:
// Set the value of the gem.
// m_scoreValue = 50;
m_scoreValue = std::rand() % 100;
In Heart::Heart, we'll make the following change:
// Set health value.
// m_health = 15;
m_health = std::rand() % 11 + 10;
If we run the game now, and have a quick look around...