int StudentWorld::move() { setDisplayText(); double roundFactor = 0.9 + 0.1*roundNumber(); if (testParamsProvided() == true) { if (m_actors.empty()) { int whichActor = getTestParam(TEST_PARAM_ACTOR_INDEX); if (whichActor == TEST_PARAM_NACHLING) m_actors.push_back(new Nachling(this, int(5*roundFactor))); else if (whichActor == TEST_PARAM_WEALTHY_NACHLING) m_actors.push_back(new WealthyNachling(this, int(8*roundFactor))); else if (whichActor == TEST_PARAM_SMALLBOT) m_actors.push_back(new SmallBot(this, int(12*roundFactor))); else if (whichActor == TEST_PARAM_GOODIE_ENERGY) m_actors.push_back(new Goodie(IID_ENERGY_GOODIE, this, 15, 39)); else if (whichActor == TEST_PARAM_GOODIE_TORPEDO) m_actors.push_back(new Goodie(IID_TORPEDO_GOODIE, this, 15, 39)); else if (whichActor == TEST_PARAM_GOODIE_FREE_SHIP) m_actors.push_back(new Goodie(IID_FREE_SHIP_GOODIE, this, 15, 39)); } } else { int numActiveAliens = numberOfActiveAliens(); m_nMaxAliens = maxAliensAllowed(); if (numActiveAliens < m_nMaxAliens) { if (numActiveAliens < m_nNeeded) { int p1 = rand() % 100 + 1; if (p1 < 70) { int p2 = rand() % 100 + 1; if (p2 < 20) m_actors.push_back(new WealthyNachling(this, int(8*roundFactor))); else m_actors.push_back(new Nachling(this, int(5*roundFactor))); } else m_actors.push_back(new SmallBot(this, int(12*roundFactor))); } } if (rand() % 3 == 0) // There is a 1 in 3 chance that you will add a single Star to the space field m_actors.push_back(new Star(this)); } m_player->doSomething(); std::list<Actor*>::iterator position; std::list<Actor*>::iterator temp; position = m_actors.begin(); while (position != m_actors.end()) { (*position)->doSomething(); if (!(*position)->isAlive()) { temp = position; position++; delete (*temp); m_actors.erase(temp); continue; } position++; } if (m_nNeeded <= 0) { m_roundNumber++; nextRound(); } if (m_player->currentEnergy() > 0) return GWSTATUS_CONTINUE_GAME; else { decLives(); return GWSTATUS_PLAYER_DIED; } }
int StudentWorld::move() { //ADD NEW ALIENS OR STARS if (testParamsProvided() == true) { if (m_actors.size() == 0) /*int countAliensAndGoodies = 0; for (int i = 0; i <m_actors.size(); i++) { Alien* a = dynamic_cast<Alien*>(m_actors[i]); if (a != NULL) countAliensAndGoodies++; Goodie* g = dynamic_cast<Goodie*>(m_actors[i]); if (g != NULL) countAliensAndGoodies++; } if (countAliensAndGoodies = 0)*/ { int whichActor = getTestParam(TEST_PARAM_ACTOR_INDEX); if (whichActor == TEST_PARAM_NACHLING) m_actors.push_back(new Nachling(this, m_RoundNumber)); if (whichActor == TEST_PARAM_WEALTHY_NACHLING) m_actors.push_back(new WealthyNachling(this,m_RoundNumber)); if (whichActor == TEST_PARAM_SMALLBOT) m_actors.push_back(new Smallbot(this, m_RoundNumber)); if (whichActor == TEST_PARAM_GOODIE_ENERGY) m_actors.push_back(new EnergyGoodie(this, 15, 39)); if (whichActor == TEST_PARAM_GOODIE_TORPEDO) m_actors.push_back(new TorpedoGoodie(this, 15, 39)); if (whichActor == TEST_PARAM_GOODIE_FREE_SHIP) m_actors.push_back(new FreeShipGoodie(this, 15, 39)); } } /////////////// else { int maxAliens = int(m_RoundNumber * .5 + 2); if (m_nActiveAliens < maxAliens && m_nActiveAliens < 4 * m_RoundNumber - m_AliensDestroyed) { int random1 = rand() % 100; if (random1 < 70) { int random2 = rand() %100; if (random2 < 20) { m_actors.push_back(new WealthyNachling(this, m_RoundNumber)); m_nActiveAliens++; } else { m_actors.push_back(new Nachling(this, m_RoundNumber)); m_nActiveAliens++; } } else { m_actors.push_back(new Smallbot(this, m_RoundNumber)); m_nActiveAliens++; } } } int random3 = rand() % 100; if (random3 < 33) { m_actors.push_back(new Star(this)); //m_nStars++; } //UPDATE THE GAME STATUS LINE updateDisplayText(); //GIVE EACH ACTOR A CHANCE TO DO SOMETHING if (ptrToShip->isStillAlive()) ptrToShip->doSomething(); for (int i = 0; i < m_actors.size(); i++) { if (m_actors[i]->isStillAlive() == true) m_actors[i]->doSomething(); } //DELETE DEAD ACTORS for (int i = 0; i <m_actors.size(); i++)//WHY DOES THIS MAKE IT CRASH { if (m_actors[i]->isStillAlive() == false) { Alien* a = dynamic_cast<Alien*>(m_actors[i]); if (a != NULL) { m_nActiveAliens--; if (a->diedByCollision() == false) m_AliensDestroyed++; } delete m_actors[i]; m_actors.erase(m_actors.begin()+i); i--; } } if (m_AliensDestroyed >= m_RoundNumber * 4) { m_RoundNumber++; m_AliensDestroyed = 0; } if (ptrToShip->isStillAlive() == false) { decLives(); return GWSTATUS_PLAYER_DIED; } else return GWSTATUS_CONTINUE_GAME; //decLives(); //return GWSTATUS_PLAYER_DIED;// This code is here merely to allow the game to build, run, and terminate after hitting enter a few times }