#include "RobotT.h" #include "BoardT.h" #include using namespace std; RobotT::RobotT(BoardT & b, size_t xpos, size_t ypos): board{b}, x{xpos}, y{ypos} { } RobotT::~RobotT(){ cout << "A base class robot goes away" << endl; } bool RobotT::IsSafe(int ) const { cout << "Base class is safe" << endl; return true; } void StatRobotT::Move() { return; } bool StatRobotT::IsSafe() const { cout << "Stat class is safe" << endl; return true; } char StatRobotT::Rep() const { return 'R'; } void RandomRobotT::Move() { size_t newX{x}, newY{y}; RobotPtr r; newX += rand() % 3 -1; newY += rand() % 3 -1; if (board.ValidCoord(newX, newY)) { if (not board.Get(newX,newY).HasRobot()) { r = board.Get(x,y).GetRobot(); board.Set(newX,newY).SetRobot(r); board.Set(x,y).RemoveRobot(); x = newX; y = newY; } else { cout << "Move failed: Robot there" << endl; } } else { cout << "Move Failed: Coordinates not valid " << endl; } } char RandomRobotT::Rep() const { return '?'; } void HuntedRobotT::Move() { size_t newX{x}, newY{y}; RobotPtr r; switch (dir) { case 0: if (x > 0) { newX--; } else { dir=1; } break; case 1: if (y > 0) { newY--; } else { dir = 2; } break; case 2: if (x < board.Width() -1) { newX++; } else { dir = 3; } break; case 3: if (y < board.Height() -1) { newY++; } else { dir = 0; } break; } if (x != newX or y != newY) { r = board.Get(x,y).GetRobot(); board.Set(newX,newY).SetRobot(r); board.Set(x,y).RemoveRobot(); x = newX; y = newY; } } HuntedRobotT::~HuntedRobotT(){ cout << "\tA hunted Robot goes away" << endl;; } char HuntedRobotT::Rep() const { return 'h'; } void HuntedRobotT::Squeek() const { cout << "Run, run away!" << endl; } BigHuntedRobotT::~BigHuntedRobotT(){ cout << "\t\tA big hunted Robot goes away" << endl;; } char BigHuntedRobotT::Rep() const { //cout << " My parent's rep is a " << HuntedRobotT::Rep() << endl; return 'H'; } void BigHuntedRobotT::Squeek() const { cout << "RUN, RUN AWAY!" << endl; }