Creating a random player character
In Chapter 3, Using RNG with C++ Data Types, we gave our player random stats. Let's continue and develop the player
object further. We'll give our player
a random class, and use this to set an appropriate sprite and stats. We'll also give the player random traits that will buff certain stats.
Choosing a player class
Let's start by assigning the player a random class. The first step is to define an enumerator that will define the possible classes. We'll place this with the rest of the enumerators in Util.h
:
// Player classes. enum class PLAYER_CLASS { WARRIOR, MAGE, ARCHER, THIEF, COUNT };
Now, in the constructor of the player
class, we'll select one of these classes at random. To do this, we need to generate a number from 0 to 3, and use it as an index in the enumerator. We'll also create a variable to hold the selection in case we wish to use it later.
We'll start by declaring the variable in Player.h
, as...