Game Development Reference
In-Depth Information
Listing 19-12. The
Enemy
Class
class Enemy
: public Entity
{
public:
enum class EnemyType
{
Dragon,
Orc
};
private:
EnemyType m_type;
bool m_alive{ true };
public:
Enemy(EnemyType type)
: m_type{ type }
{
}
bool IsAlive() const
{
return m_alive;
}
void Kill()
{
m_alive = false;
}
};
Text Adventure will support two different kinds of enemies for now, Dragons and Orcs. These types
have been represented in the
EnemyType enum
. The only other member variable is a
bool
that
determines if the
Enemy
is dead or alive; this goes along with the two helper methods,
IsAlive
and
Kill
, which query and set the state of the
m_alive
variable.
As you might have guessed, there is a new class derived from
Option
that allows the user to kill the
enemies. Listing 19-13 shows the
AttackEnemyOption
class.
Listing 19-13. The
AttackEnemyOption
Class
class AttackEnemyOption
: public Option
{
private:
Enemy* m_enemy;
public:
AttackEnemyOption(Enemy* enemy, const std::string& outputText);
virtual void Evaluate(Player& player);
};