int main(void) { Zombie * marvin; Zombie * random; std::cout << "<Main> Creation of a zombie by default" << std::endl; Zombie livingDead; livingDead.announce(); std::cout << std::endl; ZombieEvent event; std::cout << std::endl << "<Main> Adding a type to the existing zombie" << std::endl; event.setZombieType("Hungry"); std::cout << "<Main> Checking the zombie type in the main : [" << event.getZombieType() << "]" << std::endl; std::cout << std::endl << "<Main> Creation of a zombie called Marvin" << std::endl; marvin = event.newZombie("Marvin"); std::cout << "<Main> What is it zombie?" << std::endl; marvin->announce(); std::cout << "<Main> Get away Marvin!" << std::endl; delete marvin; std::cout << std::endl << "<Main> Creation of a random zombie with type Hungry" << std::endl; random = event.randomChump(); std::cout << "<Main> I will destroy you now" << std::endl; delete random; std::cout << "<Main> This is the end, computer always win." << std::endl; return (0); }
int main( void ) { srand(time(NULL)); std::string name[10] = { "Stephanie", "Geoffroy", "Ezio", "Thomas", "Hubert", "Matthieu", "Stephane", "Clara", "Gregory", "Aurelien", }; int index = rand() % 10; ZombieEvent one; Zombie* test = one.newZombie(name[index]); index = rand() % 10; Zombie* test1 = one.newZombie(name[index]); test->announce(); one.setZombieType(test, "mangeur"); test->announce(); test1->announce(); delete test; delete test1; return 0; }
void ZombieEvent::randomChump() { int i; std::string s; std::srand(time(0)); i = rand() % 10 + 1; if (i == 1) s = "Bob"; else if (i == 2) s = "James"; else if (i == 3) s = "Georges"; else if (i == 4) s = "Charlotte"; else if (i == 5) s = "Frederic"; else if (i == 6) s = "Brenda"; else if (i == 7) s = "Thibault"; else if (i == 8) s = "Francoise"; else if (i == 9) s = "Anne"; else s = "Romane"; Zombie *zombie = new Zombie(this->type, s); zombie->announce(); delete zombie; }
Zombie *ZombieEvent::newZombie(STRING name) { Zombie *tempZombie = new Zombie(); tempZombie->setName(name); tempZombie->setType(this->_type); tempZombie->announce(); return tempZombie; }
Zombie *ZombieEvent::randomChamp(void) { static char const namePool[20][20] = { "Brain", "Imotep", "charlotte", "Charlot", "Robert", "Elisa", "Berangere", "Sangoku", "Bulma", "Patrick", "Patricia", "Elise", "Jesus", "Marie", "Jeniffer", "Carolle", "William", "Rambo", "Anakin", "Popey" }; int i = rand(); if (i < 0) i *= 1; Zombie *tempZombie = new Zombie(); tempZombie->setName(namePool[i % 20]); tempZombie->setType(this->_type); tempZombie->announce(); return tempZombie; }
void ZombieEvent::randomChump(void) { Zombie *Zom; Zom = newZombie(_randName()); Zom->announce(); delete Zom; Zom = NULL; }
void wave(ZombieEvent &event, const char *type, int len) { Zombie *tmp; event.setZombieType(type); while (len-- > 0) { tmp = event.newZombie("LAAAL"); tmp->announce(); delete tmp; } }
int main(void) { Zombie *zombie; Zombie zom_heap("Olly", "Juggernaut"); ZombieEvent event_zomb; zom_heap.announce(); event_zomb.setZombieType("Rot worm"); zombie = event_zomb.newZombie("Jimmy"); zombie->announce(); event_zomb.randomChump(); delete zombie; return (0); }
Zombie *ZombieEvent::randomChump() const { static bool srand_init = false; if (!srand_init) { std::srand(std::time(0)); srand_init = true; } std::string s; s.reserve(10); for (int i = 0;i < 10; ++i) s += ('a' + (std::rand() % ('z' - 'a' + 1))); Zombie *z = new Zombie(s, this->_type); z->announce(); return z; }