Game Development Reference
In-Depth Information
Listing 19-14 shows the code for the Evaluate method.
Listing 19-14. AttackEnemyOption::Evaluate
void AttackEnemyOption::Evaluate(Player& player)
{
std::cout << std::endl << "You have chosen to " << m_outputText
<< std::endl << std::endl;
if (player.HasWeapon())
{
if (m_enemy->IsAlive())
{
m_enemy->Kill();
std::cout << "You killed it!" << std::endl << std::endl;
}
}
else
{
std::cout << "You need to find a weapon before attacking monsters!"
<< std::endl << std::endl;
}
}
The Player::HasWeapon method is put to good use here to make sure that the user can only attack
enemies when they are armed. The final changes required to tie everything together are in the Game
class, which is shown in Listing 19-15.
Listing 19-15. The Updated Game Class
class Game
{
private:
static const unsigned int m_numberOfRooms = 4;
using Rooms = std::array<Room, m_numberOfRooms>;
Rooms m_rooms;
Player m_player;
AttackEnemyOption m_attackDragonOption;
AttackEnemyOption m_attackOrcOption;
MoveOption m_moveNorthOption;
MoveOption m_moveEastOption;
MoveOption m_moveSouthOption;
MoveOption m_moveWestOption;
OpenChestOption m_openSwordChest;
QuitOption m_quitOption;
Sword m_sword;
Chest m_swordChest;
Enemy m_dragon;
Enemy m_orc;
 
Search WWH ::




Custom Search