void Arena::moveZombies() { // Move all zombies for (int k = m_nZombies - 1; k >= 0; k--) { Zombie* zp = m_zombies[k]; zp->move(); if (m_player != nullptr && zp->row() == m_player->row() && zp->col() == m_player->col()) m_player->setDead(); if (zp->isDead()) { m_history.record(zp->row(), zp->col()); delete zp; // The order of Zombie pointers in the m_zombies array is // irrelevant, so it's easiest to move the last pointer to // replace the one pointing to the now-deleted zombie. Since // we are traversing the array from last to first, we know this // last pointer does not point to a dead zombie. m_zombies[k] = m_zombies[m_nZombies - 1]; m_nZombies--; } } // Another turn has been taken m_turns++; }
int Arena::numberOfZombiesAt(int r, int c) const { int count = 0; for (int k = 0; k < m_nZombies; k++) { Zombie* zp = m_zombies[k]; if (zp->row() == r && zp->col() == c) count++; } return count; }