//This file is wabbit.h. #ifndef WABBITH #define WABBITH #include #include //for INT_MAX #include "terminal.h" using namespace std; class wabbit; //forward declaration class game { const terminal term; list master; list::size_type ecount; //number of edible animals list::size_type mcount; //number of manuals public: game(char initial_c = '.'); ~game(); void play(); wabbit *get(unsigned x, unsigned y) const; friend class wabbit; }; class wabbit { game *const g; unsigned x, y; const char c; public: wabbit(game *initial_g, unsigned initial_x, unsigned initial_y, char initial_c); wabbit(const wabbit& another); wabbit& operator=(const wabbit& another); virtual ~wabbit(); //Return false if this wabbit got eaten during the move, true otherwise. bool move(); //wabbit w1 will eat wabbit w2 if w1.hungry() > w2.bitter(), i.e., //if w1's hunger is stronger than w2's bitterness. virtual int hungry() const = 0; virtual int bitter() const = 0; //Decide which direction to move in. virtual void decide(int *dx, int *dy) const = 0; //Call this function if this wabbit falls off the screen, //or bumps into another wabbit without anyone getting eaten. virtual void punish() const {} //called by manual::decide char key() const {return g->term.key();} void beep() const {g->term.beep();} //called by visionary::decide typedef list::const_iterator const_iterator; const_iterator begin() const {return g->master.begin();} const_iterator end() const {return g->master.end();} friend double distance(const wabbit *w1, const wabbit *w2); friend void step(const wabbit *w1, const wabbit *w2, int *dx, int *dy); void einc(int bitter) const {if (bitter < INT_MAX) {++g->ecount;}} void edec(int bitter) const {if (bitter < INT_MAX) {--g->ecount;}} //called by constructors and destructor of class manual void minc() const {++g->mcount;} void mdec() const {--g->mcount;} friend wabbit *game::get(unsigned x, unsigned y) const; }; #endif