#include #include "RobotT.h" #include "SquareT.h" #include "BoardT.h" #include #include using namespace std; void PrintBoard(const BoardT & b); int main() { vector robots; BoardT board; size_t cx, cy; cx = board.Width()/2; cy = board.Height()/2; RobotPtr robot = make_shared(board, cx, cy); robots.push_back(robot); //robot->IsSafe(); //robot->IsSafe(2); board.Set(cx,cy).SetRobot(robot); cy = board.Height()/4; robot = make_shared(board, cx, cy); robots.push_back(robot); board.Set(cx,cy).SetRobot(robot); cy = board.Height() /4 * 3; robot = make_shared(board, cx, cy); robots.push_back(robot); board.Set(cx,cy).SetRobot(robot); cx = board.Width() / 4; robot = make_shared(board, cx, cy); robots.push_back(robot); board.Set(cx,cy).SetRobot(robot); cout << endl; cout << "Robot Report " << endl; for (size_t i = 0; i < robots.size(); ++i) { cout << "Robot " << i << " (" << robots[i]->Rep() << ")"; if (dynamic_pointer_cast(robots[i])) { cout << " can squeek!"; } cout << endl; } cout << endl; cin.ignore(); for(int i =0; i < 1; i++) { cout << endl << endl; for (auto & bot: robots) { bot->Move(); //bot->Squeek(); if (nullptr != dynamic_pointer_cast(bot)){ dynamic_cast(bot.get())->Squeek(); } } /* auto ptr = dynamic_cast (botptr); if (nullptr != ptr) { ptr->Squeek(); } */ PrintBoard(board); cin.ignore(); } return 0; } void PrintBoard(const BoardT & b){ size_t x, y; for(y = 0; y < b.Height(); ++y) { for( x = 0; x < b.Width(); ++x) { if (b.Get(x,y).HasRobot()) { cout << b.Get(x,y).GetRobot()->Rep(); } else { cout << "."; } } cout << endl; } }