// File: main2.cpp // // Last update: 02/26/2007 20:02 // // See Project 2 description for documentation. // #include #include #include "proj2.h" #include "Car.h" #include "RaceCourse.h" using namespace std ; // This function initializes the obstacle vector. // It's a pain, because STL vectors cannot be // initialized using the braces syntax. void SetObstacles(vector& obs) { Position arr[] = { // five in a row to help counting { 4, 2}, { 4, 3}, { 4, 4}, { 4, 5}, { 8, 1}, // 5 { 8, 2}, { 8, 3}, { 7, 6}, { 8, 6}, { 9, 6}, // 10 {12, 5}, {12, 6}, {12, 7}, {12, 8} // 15 } ; unsigned int N = 14 ; // count number of obstacles obs.clear() ; for(unsigned int i = 0 ; i < N ; i++) { obs.push_back(arr[i]) ; } } int main() { vector obs ; Car *CarPtr1, *CarPtr2 ; SetObstacles(obs) ; RaceCourse R(15, 8, 2, obs) ; CarPtr1 = R.GetCar(1) ; CarPtr2 = R.GetCar(2) ; cout << "Initial Race Course: \n" ; R.PrettyPrintCourse() ; cout << "#Cars=" << R.GetNumOfCars() << endl ; cout << "#Rows=" << R.GetNumOfRows() << endl ; cout << "#Cols=" << R.GetNumOfCols() << endl ; R.StartRace() ; cout << "\n\nCar 2 Zoomed Right: \n" ; CarPtr2->ZoomRight() ; R.PrettyPrintCourse() ; cout << "Car 2 fuel level = " << CarPtr2->GetFuelLevel() << "\n" ; for (int i = 1 ; i <= 6 ; i++) { cout << "\n\nCar 1 Zoomed Down: \n" ; CarPtr1->ZoomDown() ; R.PrettyPrintCourse() ; cout << "Car 1 is at (" << CarPtr1->GetPosition().row << "," << CarPtr1->GetPosition().col << ") with fuel level=" << CarPtr1->GetFuelLevel() << "\n" ; cout << "\n\nCar 2 Zoomed Down: \n" ; CarPtr2->ZoomDown() ; R.PrettyPrintCourse() ; cout << "Car 2 is at (" << CarPtr2->GetPosition().row << "," << CarPtr2->GetPosition().col << ") with fuel level=" << CarPtr2->GetFuelLevel() << "\n" ; cout << "\n\nCar 1 Zoomed Up: \n" ; CarPtr1->ZoomUp() ; R.PrettyPrintCourse() ; cout << "Car 1 is at (" << CarPtr1->GetPosition().row << "," << CarPtr1->GetPosition().col << ") with fuel level=" << CarPtr1->GetFuelLevel() << "\n" ; cout << "\n\nCar 2 Zoomed Up: \n" ; CarPtr2->ZoomUp() ; R.PrettyPrintCourse() ; cout << "Car 2 is at (" << CarPtr2->GetPosition().row << "," << CarPtr2->GetPosition().col << ") with fuel level=" << CarPtr2->GetFuelLevel() << "\n" ; } }