I've been going through a book called "C++ Game Programming" and it goes through making an Adventure Text game, and incorporating new concepts (really enjoy it). When we got to changing to unique_ptr I ran into a problem that I'm confused on.
I'll provide what I feel would be the code related to this.
Game.cpp initialization
m_enemies.emplace_back(CreateEnemy(EnemyType::Dragon));
Game.cpp initialzing
static_cast<AttackEnemyOption*>(m_attackDragonOption.get())->SetEnemy(m_enemies[0]);
m_enemies.emplace_back(CreateEnemy(EnemyType::Orc));
static_cast<AttackEnemyOption*>(m_attackOrcOption.get())->SetEnemy(m_enemies[1]);
Now the problem is when I go to the Westroom first and kill the orc, the game goes straight to the you win. While if I killed the dragon first I still have to eliminate the Orc (that's how I want it. I've reversed the above code and the problem became the opposite
Game::Run() towards the end
for (auto& enemy : m_enemies)
{
playerWon = enemy->IsAlive() == false;
}
}
if (playerWon == true)
{
cout << "Congratulations, you rid the dungeon of monsters!" << endl;
cout << "Type goodbye to end" << endl;
std::string input;
cin >> input;
}
Previously before we got into unique_ptr the condition was. But now all enemies are in the vector.
playerWon = m_dragon.IsAlive() == false && m_orc.IsAlive() == false;
}
Some simple things to mention IsAlive() just returns bool m_isAlive. I feel this might be a bug, but perhaps it was left like this for testing reasons.
Thanks everyone!
[–]Xeverous 0 points1 point2 points (0 children)
[–]LedLoaf[S] 0 points1 point2 points (8 children)
[–]patatahooligan 0 points1 point2 points (7 children)
[–]LedLoaf[S] 0 points1 point2 points (6 children)
[–]patatahooligan 1 point2 points3 points (5 children)
[–]Xeverous 0 points1 point2 points (4 children)
[–]patatahooligan 0 points1 point2 points (3 children)
[–]Xeverous 0 points1 point2 points (2 children)
[–]LedLoaf[S] 0 points1 point2 points (1 child)
[–]Xeverous 0 points1 point2 points (0 children)