#include #include //for the srand function and EXIT_SUCCESS #include //for the time function #include "terminal.h" #include "wolf.h" #include "rabbit.h" using namespace std; int main() { srand(static_cast(time(0)));//Seed the random number generator const terminal term {'.'}; const unsigned xmax {term.xmax()}; const unsigned ymax {term.ymax()}; wabbit::master.push_back(new wolf {term, xmax * 1 / 3, ymax * 2 / 4}); wabbit::master.push_back(new rabbit {term, xmax * 2 / 3, ymax * 3 / 4}); wabbit::master.push_back(new rabbit {term, xmax * 2 / 3, ymax * 2 / 4}); wabbit::master.push_back(new rabbit {term, xmax * 2 / 3, ymax * 1 / 4}); for (; wabbit::master.size() > 1; term.wait(250)) { for (list::iterator it {wabbit::master.begin()}; it != wabbit::master.end(); /* ++it */) { wabbit *const p {*it}; const bool alive {p->move()}; ++it; if (!alive) { delete p; //Destruct the wabbit that moved. break; } } } term.put(0, 0, "You killed all the rabbits!"); term.wait(3000); //Give the user three seconds to read the message. for (auto p: wabbit::master) { //Destruct any remaining wabbits. delete p; } return EXIT_SUCCESS; //Destruct the terminal. }