// File: Thing.cpp // // Thing, Wall and Goal class implementations. // // You must not alter this file. // #include #include "Thing.h" #include "RaceCourse.h" using namespace std ; //-------------------------------------------------------------- // Thing class implementation //-------------------------------------------------------------- // // Default Constructor // // You wouldn't want to create a Thing with // the default constructor, but the derived // class might fix up m_row and m_col. // Thing::Thing() : m_row(0), m_col(0) { // no code } // Alternate Constructor // Thing::Thing(unsigned int row, unsigned int col) : m_row(row), m_col(col) { // no code } // Virtual Destructor // Thing does not have dynamically allocated data, but dervied // class might. // Thing::~Thing() { // no code } // Crash Management // void Thing::encounter(Car *ptr) { // no code } // Accessors // // A limited number of accessors, but derived classes // can add more unsigned int Thing::GetRow() const { return m_row ; } unsigned int Thing::GetCol() const { return m_col ; } // Mutators // // Note that m_row and m_col are in the protected section // so derived classes can add mutators. void Thing::SetRaceCoursePtr(RaceCourse *ptr) { Rptr = ptr ; } //-------------------------------------------------------------- // Wall class implementation //-------------------------------------------------------------- // Wall::Wall() { // no code } Wall::Wall(unsigned int row, unsigned int col) : Thing(row,col) { // no code } char Wall::DrawMe() const { return '#' ; } //-------------------------------------------------------------- // Goal class implementation //-------------------------------------------------------------- // Goal::Goal() : winner(NULL) { // no code } Goal::Goal(unsigned int row, unsigned int col) : Thing(row,col), winner(NULL) { // no code } char Goal::DrawMe() const { return '%' ; } void Goal::encounter(Car *ptr) { if (winner != NULL) { cerr << "Someone is cheating! We already have a winner!\n" ; exit(1) ; } winner = ptr ; // remember who won Rptr->StopRace() ; // we're all done } Car *Goal::GetWinner() const { return winner ; }