Advertisement
xuan1287

robot.h

Jun 30th, 2024 (edited)
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.11 KB | Source Code | 0 0
  1. /***|***|****|
  2.  Program: main.cpp / Robot.h
  3. Course: OOPDS
  4.  Name: MUHAMMAD AQIL BIN RAHMAT
  5.  ID: 1211107976
  6.  Lecture Section: TC4L
  7.  Tutorial Section: T13L
  8.  Email: 1211107976@student.mmu.edu.my
  9.  Phone: 019-8148313
  10.  
  11.  Name: TENG CHAY XUAN
  12.  ID: 1231300802
  13.  Lecture Section: TC4L
  14.  Tutorial Section: T13L
  15.  Email: 1231300802@student.mmu.edu.my
  16.  Phone: 011-10588063
  17.  
  18.  Name: Akid Syazwan bin Nor Azman Shah
  19.  ID: 1211111238
  20.  Lecture Section: TC4L
  21.  Tutorial Section: T13L
  22.  Email: 121111123@student.mmu.edu.my
  23.  Phone: 014-9020901
  24.  
  25.  Name: MUHAMMAD NABIL NAUFAL BIN MD ZAID
  26.  ID: 1221101160
  27.  Lecture Section: TC4L
  28.  Tutorial Section: T13L
  29.  Email: 1221101160@student.mmu.edu.my
  30.  Phone: 010-5509230
  31. ***|***|****/
  32.  
  33. #pragma once
  34. #include <bits/stdc++.h>
  35.  
  36. using namespace std;
  37.  
  38. //Movement
  39. class Robot {
  40. public:
  41.     virtual void setPos(int x, int y){}
  42.     virtual string getType(){ return {};}
  43.     virtual string getName(){ return {};}
  44.     virtual char getLabel(){ return {};}
  45.     virtual int getPosX(){ return {};}
  46.     virtual int getPosY(){ return {};}
  47.     virtual bool getAlive(){ return {};}
  48.     virtual int getLives(){ return {};}
  49.     virtual void respawned(){}
  50.     virtual void died(){}
  51.     virtual void minusLife(){}
  52.     virtual int getKills(){ return {};}
  53.     virtual void kill(){}
  54.  
  55.     void checkAlive(char (*Bfield), int m, int n)
  56.     {
  57.         char label = getLabel();
  58.         bool isAlive = getAlive();
  59.         for(int i=0; i<m; i++)
  60.         {
  61.             for(int j=0; j<n; j++)
  62.             {
  63.                 if (*((Bfield + i * n) + j*2) != label)
  64.                 {
  65.                     isAlive = false;
  66.                 }
  67.                 else
  68.                 {
  69.                     isAlive = true;
  70.                     return;
  71.                 }
  72.             }
  73.         }
  74.  
  75.         if(!isAlive)
  76.            died();
  77.  
  78.     }
  79.  
  80.     virtual char move(char (*Bfield), int m, int n, ofstream &output) = 0;
  81.     virtual char fire(char (*Bfield), int m, int n, ofstream &output) = 0;
  82.     virtual char look(char (*Bfield), int m, int n, ofstream &output) = 0;
  83.     virtual char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output) = 0;
  84.  
  85.     // Friend function to overload the << operator
  86.     friend ostream& operator<<(ostream& os, Robot& robot);
  87. };
  88.  
  89. // We overload the << operator to printout the name of the robot.
  90. ostream& operator<<(ostream& os, Robot& Robot)
  91. {
  92.     os << "[" << Robot.getLabel() << "]" << "(" << Robot.getType() << ")" << Robot.getName();
  93.     return os;
  94. }
  95.  
  96.  
  97.  
  98. //--------------Robot Functions--------------------
  99. class MovingRobot : virtual public Robot {
  100. public:
  101.     virtual char move(char (*Bfield), int m, int n, ofstream &output)
  102.     {
  103.         bool invalid = false;
  104.         int PosX = getPosX();
  105.         int PosY = getPosY();
  106.         char label = getLabel();
  107.         int moveX = 0;
  108.         int moveY = 0;
  109.  
  110.         //loop to check if there are no valid movements
  111.         for(int i=PosY-1; i<PosY+2; i++)
  112.         {
  113.             for(int j=PosX-1; j<PosX+2; j++)
  114.             {
  115.                 //Not a single valid movement found for the robot
  116.                 if(*((Bfield + i * n) + j*2) != '-' && *((Bfield + i * n) + j*2) == label && j == 0 && j == m-1 && i == 0 && (i*2) == n)
  117.                 {
  118.                     invalid = true;
  119.                     cout << getName() << "[" << getType() << "] is stuck and cannot move!" << endl;
  120.                     output << getName() << "[" << getType() << "] is stuck and cannot move!" << endl;
  121.                     return *Bfield;
  122.                 }
  123.  
  124.                 else //Any single valid movement found
  125.                 {
  126.                     break;
  127.                 }
  128.             }
  129.         }
  130.  
  131.         if(!invalid)
  132.         {
  133.             //set previous position to '-' to make empty
  134.             *((Bfield + PosY * n) + PosX*2) = '-';
  135.  
  136.             //loop to get where the robot moves using rand
  137.             do{
  138.                 moveX = -1 + (1-(-1)) * rand() % 3;
  139.                 moveY = -1 + (1-(-1)) * rand() % 3;
  140.             }while((moveX == 0 && moveY == 0) || PosY + moveY == 0 || PosY + moveY == m-1 || *((Bfield + (PosY + moveY) * n) + (PosX + moveX)*2) != '-');
  141.         }
  142.  
  143.         //add movex and movey to respective x and y positions to change robot position
  144.         int newPosX = PosX + moveX;
  145.         int newPosY = PosY + moveY;
  146.  
  147.         //move robot label to its position
  148.         *((Bfield + newPosY * n) + newPosX*2) = label;
  149.  
  150.         cout << getName() << " at (" << PosX << "," << PosY << ") moved to (" << newPosX << "," << newPosY << ")" << endl;
  151.         output << getName() << " at (" << PosX << "," << PosY << ") moved to (" << newPosX << "," << newPosY << ")" << endl;
  152.  
  153.         //change robot position
  154.         setPos(newPosX, newPosY);
  155.  
  156.         return *Bfield;
  157.     }
  158.  
  159.     virtual void nothing() = 0;
  160. };
  161.  
  162. class ShootingRobot : virtual public Robot {
  163. public:
  164.     virtual char fire(char (*Bfield), int m, int n, ofstream &output)
  165.     {
  166.         int PosX = getPosX();
  167.         int PosY = getPosY();
  168.         int shootCoordX, shootCoordY;
  169.         int shootX = 0;
  170.         int shootY = 0;
  171.  
  172.         while(shootX == 0 && shootY == 0 || abs(shootX)+abs(shootY) > 5 || *((Bfield + shootCoordY * n) + shootCoordX*2) == '*')
  173.         {
  174.             shootCoordX = rand() % (n-3)/2+1;
  175.             shootCoordY = rand() % (m-2)+1;
  176.             shootX = shootCoordX - PosX;
  177.             shootY = shootCoordY - PosY;
  178.         }
  179.  
  180.         if(*((Bfield + shootCoordY * n) + shootCoordX*2) != '-' && *((Bfield + shootCoordY * n) + shootCoordX*2) != '*')
  181.         {
  182.             cout << getName() << " hit another robot at (" << shootX << "," << shootY << ") from it's own position!" << endl;
  183.             *((Bfield + shootCoordY * n) + shootCoordX*2) = '*';
  184.             output << getName() << " hit another robot at (" << shootX << "," << shootY << ") from it's own position!" << endl;
  185.             *((Bfield + shootCoordY * n) + shootCoordX*2) = '*';
  186.             kill();
  187.             return *Bfield;
  188.         }
  189.  
  190.         cout << getName() << " hit nothing at (" << shootX << "," << shootY << ") from it's own position" << endl;
  191.         output << getName() << " hit nothing at (" << shootX << "," << shootY << ") from it's own position" << endl;
  192.  
  193.         { return {};}
  194.     }
  195.  
  196.     virtual void nothing() = 0;
  197. };
  198.  
  199. class SteppingRobot : virtual public Robot {
  200. public:
  201.     virtual char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output)
  202.     {
  203.         int PosX = getPosX();
  204.         int PosY = getPosY();
  205.         char label = getLabel();
  206.  
  207.         //Set previous position in battlefield to '-' to mark as empty
  208.         *((Bfield + PosY * n) + PosX*2) = '-';
  209.  
  210.         PosX = targetX;
  211.         PosY = targetY;
  212.  
  213.         //Change robot position
  214.         setPos(PosX, PosY);
  215.  
  216.         //Move to new position in battlefield
  217.         *((Bfield + PosY * n) + PosX*2) = label;
  218.  
  219.         cout << getName() << " found a target and stepped on another robot at (" << PosX << "," << PosY << ")!" << endl;
  220.         output << getName() << " found a target and stepped on another robot at (" << PosX << "," << PosY << ")!" << endl;
  221.  
  222.         //Increase robot kill
  223.         kill();
  224.  
  225.         return *Bfield;
  226.     }
  227.  
  228.     virtual void nothing() = 0;
  229. };
  230.  
  231. class SeeingRobot : virtual public Robot {
  232. public:
  233.     virtual char look(char (*Bfield), int m, int n, ofstream &output)
  234.     {
  235.         int PosX = getPosX();
  236.         int PosY = getPosY();
  237.         char label = getLabel();
  238.         bool target;
  239.         int targetX, targetY;
  240.  
  241.         //loop to find any target 1 tile around the robot
  242.         for(int i=PosY-1; i<PosY+2; i++)
  243.         {
  244.             for(int j=PosX-1; j<PosX+2; j++)
  245.             {
  246.                 //if a target is found
  247.                 if(*((Bfield + i * n) + j*2) != '-' && *((Bfield + i * n) + j*2) != '|' && *((Bfield + i * n) + j*2) != '+' && *((Bfield + i * n) + j*2) != label && *((Bfield + i * n) + j*2) != '*')
  248.                 {
  249.                     target = true;
  250.                     targetX = j;
  251.                     targetY = i;
  252.                     step((char*)Bfield, m, n, targetX, targetY, output);
  253.                     return *Bfield;
  254.                 }
  255.  
  256.             }
  257.  
  258.         }
  259.  
  260.         move((char*)Bfield, m, n, output);
  261.         { return {};}
  262.     }
  263.  
  264.     virtual void nothing() = 0;
  265.  
  266. };
  267.  
  268.  
  269. //-------------ROBOT TYPES-----------------
  270.  
  271.  
  272. ///RoboCop: Moves and Shoots - Upgrade: TerminatorRoboCop
  273. class RoboCop : public SeeingRobot, public MovingRobot, public ShootingRobot {
  274. private:
  275.     string type, name;
  276.     char label;
  277.     int kills, lives;
  278.     int PosX, PosY;
  279.     bool alive;
  280.  
  281. public:
  282.     RoboCop(string Rname, char Rlabel, int Rlives, int x, int y)
  283.     {
  284.         type = "RoboCop";
  285.         name = Rname;
  286.         label = Rlabel;
  287.         kills = 0;
  288.         lives = Rlives;
  289.         PosX = x;
  290.         PosY = y;
  291.         alive = true;
  292.     }
  293.  
  294.     string getType(){return type;}
  295.     string getName(){return name;}
  296.     char getLabel(){return label;}
  297.     int getPosX(){return PosX;}
  298.     int getPosY(){return PosY;}
  299.     bool getAlive(){return alive;}
  300.     int getLives(){return lives;}
  301.     void respawned(){alive = true;}
  302.     void died(){alive = false;}
  303.     void minusLife(){lives--;}
  304.     int getKills(){return kills;}
  305.     void kill(){kills++;}
  306.     void nothing() {}
  307.  
  308.  
  309.     void setPos(int x,int y)
  310.     {
  311.         PosX = x;
  312.         PosY = y;
  313.     }
  314.  
  315.     ~RoboCop(){cout << getName() << "[" << getType() << "] Destroyed and Scrapped";}
  316.  
  317.     char move(char (*Bfield), int m, int n, ofstream &output){
  318.         return MovingRobot::move(Bfield,m,n,output);
  319.     }
  320.     char fire(char (*Bfield), int m, int n, ofstream &output){
  321.         return ShootingRobot::fire(Bfield,m,n,output);
  322.     }
  323.     char look(char (*Bfield), int m, int n, ofstream &output){ return {};}
  324.     char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output){ return {};}
  325.  
  326. };
  327.  
  328. ///Terminator: Looks and Moves - Upgrade: TerminatorRoboCop
  329. class Terminator : public SeeingRobot, public MovingRobot, public SteppingRobot {
  330. private:
  331.     string type, name;
  332.     char label;
  333.     int kills, lives;
  334.     int PosX, PosY;
  335.     int targetX, targetY;
  336.     bool alive;
  337.  
  338. public:
  339.     Terminator(string Rname, char Rlabel, int Rlives, int x, int y)
  340.     {
  341.         type = "Terminator";
  342.         name = Rname;
  343.         label = Rlabel;
  344.         kills = 0;
  345.         lives = Rlives;
  346.         PosX = x;
  347.         PosY = y;
  348.         alive = true;
  349.     }
  350.  
  351.     string getType(){return type;}
  352.     string getName(){return name;}
  353.     char getLabel(){return label;}
  354.     int getPosX(){return PosX;}
  355.     int getPosY(){return PosY;}
  356.     bool getAlive(){return alive;}
  357.     int getLives(){return lives;}
  358.     void respawned(){alive = true;}
  359.     void died(){alive = false;}
  360.     void minusLife(){lives--;}
  361.     void kill(){kills++;}
  362.     int getKills(){return kills;}
  363.     void nothing() {}
  364.  
  365.     void setPos(int x,int y)
  366.     {
  367.         PosX = x;
  368.         PosY = y;
  369.     }
  370.  
  371.     void setTarget(int x,int y)
  372.     {
  373.         targetX = x;
  374.         targetY = y;
  375.     }
  376.  
  377.     ~Terminator(){cout << getName() << "[" << getType() << "] Destroyed and Scrapped";}
  378.  
  379.     char move(char (*Bfield), int m, int n, ofstream &output){
  380.         return MovingRobot::move(Bfield,m,n,output);
  381.     }
  382.     char fire(char (*Bfield), int m, int n, ofstream &output){ return {};}
  383.     char look(char (*Bfield), int m, int n, ofstream &output){
  384.         return SeeingRobot::look(Bfield,m,n,output);
  385.     }
  386.     char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output){
  387.         return SteppingRobot::step(Bfield,m ,n, targetX, targetY,output);
  388.     }
  389.  
  390. };
  391.  
  392. ///BlueThunder: Shoots - Upgrade: MadBot
  393. class BlueThunder : public ShootingRobot {
  394. private:
  395.     string type, name;
  396.     char label;
  397.     int kills, lives;
  398.     int PosX, PosY;
  399.     bool alive;
  400.     int currentDirection;
  401.  
  402. public:
  403.     BlueThunder(string Rname, char Rlabel, int Rlives, int x, int y)
  404.     {
  405.         type = "BlueThunder";
  406.         name = Rname;
  407.         label = Rlabel;
  408.         kills = 0;
  409.         lives = Rlives;
  410.         PosX = x;
  411.         PosY = y;
  412.         alive = true;
  413.         currentDirection = 0;
  414.     }
  415.  
  416.     string getType(){return type;}
  417.     string getName(){return name;}
  418.     char getLabel(){return label;}
  419.     int getPosX(){return PosX;}
  420.     int getPosY(){return PosY;}
  421.     bool getAlive(){return alive;}
  422.     int getLives(){return lives;}
  423.     void respawned(){alive = true;}
  424.     void died(){alive = false;}
  425.     void minusLife(){lives--;}
  426.     void kill(){kills++;}
  427.     int getKills(){return kills;}
  428.     int getCD(){return currentDirection;}
  429.     void nothing() {}
  430.  
  431.     void setPos(int x,int y)
  432.     {
  433.         PosX = x;
  434.         PosY = y;
  435.     }
  436.  
  437.     char fire(char (*Bfield), int m, int n, ofstream &output) override
  438.     {
  439.         int targetX, targetY;
  440.         int directionX, directionY;
  441.  
  442.         //array to store BlueThunder's firing directions
  443.         int directions[8][2] = {
  444.         {0, 1},  // Up
  445.         {1, 1},  // Up-Right
  446.         {1, 0},   // Right
  447.         {1, -1},   // Down-Right
  448.         {0, -1},   // Down
  449.         {-1, -1},  // Down-Left
  450.         {-1, 0},  // Left
  451.         {-1, 1}  // Up-Left
  452.         };
  453.  
  454.         //Set X and Y positions of BlueThunder's next shot
  455.         do{
  456.             directionX = directions[currentDirection][0];
  457.             directionY = directions[currentDirection][1];
  458.             targetX = PosX + directionX;
  459.             targetY = PosY + directionY;
  460.  
  461.             //Set next direction for shot in the next turn
  462.             currentDirection++;
  463.             if (currentDirection == 8) {
  464.                 currentDirection = 0;
  465.             }
  466.  
  467.         }while(*((Bfield + targetY * n) + targetX*2) == '|' || targetY == 0 || targetY == m-1);// Check for Boundaries
  468.  
  469.         // If shot hits another robot
  470.         if(*((Bfield + targetY * n) + targetX*2) != '-' && *((Bfield + targetY * n) + targetX*2) != '*')
  471.         {
  472.             cout << getName() << " hit another robot at (" << directionX << "," << directionY << ") from it's own position!" << endl;
  473.             *((Bfield + targetY * n) + targetX*2) = '*';
  474.             output << getName() << " hit another robot at (" << directionX << "," << directionY << ") from it's own position!" << endl;
  475.             *((Bfield + targetY * n) + targetX*2) = '*';
  476.             kill();
  477.             return *Bfield;
  478.         }
  479.  
  480.         cout << getName() << " hit nothing at (" << directionX << "," << directionY << ") from it's own position" << endl;
  481.         output << getName() << " hit nothing at (" << directionX << "," << directionY << ") from it's own position" << endl;
  482.         { return {}; }
  483.     }
  484.  
  485.     char move(char (*Bfield), int m, int n, ofstream &output){ return {};}
  486.     char look(char (*Bfield), int m, int n, ofstream &output){ return {};}
  487.     char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output){ return {};}
  488.  
  489.  
  490. };
  491.  
  492. ///Madbot: Shoots - Upgrade: RoboTank
  493. class MadBot : public ShootingRobot {
  494. private:
  495.     string type, name;
  496.     char label;
  497.     int kills, lives;
  498.     int PosX, PosY;
  499.     bool alive;
  500.  
  501. public:
  502.     MadBot(string Rname, char Rlabel, int Rlives, int x, int y)
  503.     {
  504.         type = "MadBot";
  505.         name = Rname;
  506.         label = Rlabel;
  507.         kills = 0;
  508.         lives = Rlives;
  509.         PosX = x;
  510.         PosY = y;
  511.         alive = true;
  512.     }
  513.  
  514.     string getType(){return type;}
  515.     string getName(){return name;}
  516.     char getLabel() {return label;}
  517.     int getPosX() {return PosX;}
  518.     int getPosY() {return PosY;}
  519.     bool getAlive(){return alive;}
  520.     int getLives(){return lives;}
  521.     void respawned(){alive = true;}
  522.     void died(){alive = false;}
  523.     void minusLife(){lives--;}
  524.     void kill(){kills++;}
  525.     int getKills(){return kills;}
  526.     void nothing() {}
  527.  
  528.     void setPos(int x,int y)
  529.     {
  530.         PosX = x;
  531.         PosY = y;
  532.     }
  533.  
  534.     char fire(char (*Bfield), int m, int n, ofstream &output) override
  535.     {
  536.         int shootX, shootY;
  537.         int PosX = getPosX();
  538.         int PosY = getPosY();
  539.  
  540.         do{
  541.         shootX = -1 + (1-(-1)) * rand() % 3;
  542.         shootY = -1 + (1-(-1)) * rand() % 3;
  543.         }while((shootX == 0 && shootY == 0) || PosX + shootX == 0 || (PosX + shootX)*2 == n-1 || PosY + shootY == 0 || PosY + shootY == m-1);
  544.  
  545.         int shootCoordX = PosX + shootX;
  546.         int shootCoordY = PosY + shootY;
  547.  
  548.         if(*((Bfield + shootCoordY * n) + shootCoordX*2) != '-' && *((Bfield + shootCoordY * n) + shootCoordX*2) != '*')
  549.         {
  550.             cout << getName() << " hits another robot at (" << shootX << "," << shootY << ") from it's own position" << endl;
  551.             *((Bfield + shootCoordY * n) + shootCoordX*2) = '*';
  552.             output << getName() << " hits another robot at (" << shootX << "," << shootY << ") from it's own position" << endl;
  553.             *((Bfield + shootCoordY * n) + shootCoordX*2) = '*';
  554.             kill();
  555.             return *Bfield;
  556.         }
  557.  
  558.         cout << getName() << " shot and hit nothing at (" << shootX << "," << shootY << ") from it's own position" << endl;
  559.         output << getName() << " shot and hit nothing at (" << shootX << "," << shootY << ") from it's own position" << endl;
  560.  
  561.         return *Bfield;
  562.     }
  563.  
  564.     char move(char (*Bfield), int m, int n, ofstream &output){ return {};}
  565.     char look(char (*Bfield), int m, int n, ofstream &output){ return {};}
  566.     char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output){ return {};}
  567. };
  568.  
  569. ///RoboTank: Shoots - Upgrade: UltimateRobot
  570. class RoboTank : public ShootingRobot {
  571. private:
  572.     string type, name;
  573.     char label;
  574.     int kills, lives;
  575.     int PosX, PosY;
  576.     bool alive;
  577.  
  578. public:
  579.     RoboTank(string Rname, char Rlabel, int Rlives, int x, int y)
  580.     {
  581.         type = "RoboTank";
  582.         name = Rname;
  583.         label = Rlabel;
  584.         kills = 0;
  585.         lives = Rlives;
  586.         PosX = x;
  587.         PosY = y;
  588.         alive = true;
  589.     }
  590.  
  591.     string getType(){return type;}
  592.     string getName(){return name;}
  593.     char getLabel(){return label;}
  594.     int getPosX(){return PosX;}
  595.     int getPosY(){return PosY;}
  596.     bool getAlive(){return alive;}
  597.     int getLives(){return lives;}
  598.     void respawned(){alive = true;}
  599.     void died(){alive = false;}
  600.     void minusLife(){lives--;}
  601.     void kill(){kills++;}
  602.     int getKills(){return kills;}
  603.     void nothing() {}
  604.  
  605.     void setPos(int x,int y)
  606.     {
  607.         PosX = x;
  608.         PosY = y;
  609.     }
  610.  
  611.     char move(char (*Bfield), int m, int n, ofstream &output){ return {};}
  612.     char fire(char (*Bfield), int m, int n, ofstream &output){
  613.         return ShootingRobot::fire(Bfield,m,n, output);
  614.     }
  615.     char look(char (*Bfield), int m, int n, ofstream &output){ return {};}
  616.     char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output){ return {};}
  617. };
  618.  
  619. ///TerminatorRoboCop: Looks, Moves, Steps and Shoots - Upgrade: UltimateRobot
  620. class TerminatorRoboCop : public SeeingRobot, public MovingRobot, public SteppingRobot, public ShootingRobot{
  621. private:
  622.     string type, name;
  623.     char label;
  624.     int kills, lives;
  625.     int PosX, PosY;
  626.     bool alive;
  627.  
  628. public:
  629.     string getType(){return type;}
  630.     string getName(){return name;}
  631.     char getLabel(){return label;}
  632.     int getPosX(){return PosX;}
  633.     int getPosY(){return PosY;}
  634.     bool getAlive(){return alive;}
  635.     int getLives(){return lives;}
  636.     void respawned(){alive = true;}
  637.     void died(){alive = false;}
  638.     void minusLife(){lives--;}
  639.     void kill(){kills++;}
  640.     int getKills(){return kills;}
  641.     void nothing() {}
  642.  
  643.     void setPos(int x,int y)
  644.     {
  645.         PosX = x;
  646.         PosY = y;
  647.     }
  648.  
  649.     TerminatorRoboCop(string Rname, char Rlabel, int Rlives, int x, int y)
  650.     {
  651.         cout << endl << Rname << " has been upgraded to TerminatorRoboCop!" << endl;
  652.         type = "TerminatorRoboCop";
  653.         name = Rname;
  654.         label = Rlabel;
  655.         kills = 0;
  656.         lives = Rlives;
  657.         PosX = x;
  658.         PosY = y;
  659.         alive = true;
  660.     }
  661.  
  662.     char move(char (*Bfield), int m, int n, ofstream &output){
  663.         return MovingRobot::move(Bfield,m,n, output);
  664.     }
  665.     char fire(char (*Bfield), int m, int n, ofstream &output){
  666.         return ShootingRobot::fire(Bfield,m,n, output);
  667.     }
  668.     char look(char (*Bfield), int m, int n, ofstream &output){
  669.         return SeeingRobot::look(Bfield,m,n, output);
  670.     }
  671.     char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output){
  672.         return SteppingRobot::step(Bfield,m,n, targetX, targetY, output);
  673.     }
  674. };
  675.  
  676. ///UltimateRobot: Looks, Moves and Shoots - Upgrade: MAX
  677. class UltimateRobot : public SeeingRobot, public MovingRobot, public SteppingRobot, public ShootingRobot {
  678. private:
  679.     string type, name;
  680.     char label;
  681.     int kills, lives;
  682.     int PosX, PosY;
  683.     bool alive;
  684.  
  685. public:
  686.  
  687.     string getType(){return type;}
  688.     string getName(){return name;}
  689.     char getLabel(){return label;}
  690.     int getPosX(){return PosX;}
  691.     int getPosY(){return PosY;}
  692.     bool getAlive(){return alive;}
  693.     int getLives(){return lives;}
  694.     void respawned(){alive = true;}
  695.     void died(){alive = false;}
  696.     void minusLife(){lives--;}
  697.     void kill(){kills++;}
  698.     int getKills(){return kills;}
  699.     void nothing() {}
  700.  
  701.     void setPos(int x,int y)
  702.     {
  703.         PosX = x;
  704.         PosY = y;
  705.     }
  706.  
  707.     UltimateRobot(string Rname, char Rlabel, int Rlives, int x, int y)
  708.     {
  709.         cout << endl << Rname << " has been upgraded to UltimateRobot!" << endl;
  710.         type = "UltimateRobot";
  711.         name = Rname;
  712.         label = Rlabel;
  713.         kills = 0;
  714.         lives = Rlives;
  715.         PosX = x;
  716.         PosY = y;
  717.         alive = true;
  718.     }
  719.  
  720.     char move(char (*Bfield), int m, int n, ofstream &output){
  721.         return MovingRobot::move(Bfield,m,n, output);
  722.     }
  723.     char fire(char (*Bfield), int m, int n, ofstream &output){
  724.         return ShootingRobot::fire(Bfield,m,n, output);
  725.     }
  726.     char look(char (*Bfield), int m, int n, ofstream &output){
  727.         return SeeingRobot::look(Bfield,m,n, output);
  728.     }
  729.     char step(char (*Bfield), int m, int n, int targetX, int targetY, ofstream &output){ return {};}
  730. };
  731.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement