Advertisement
Guest User

5lab

a guest
Mar 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. class Enemy
  9. {
  10. protected:
  11.     bool isAlive;
  12.     bool countryOwn;
  13.     int x;
  14.     int y;
  15. public:
  16.     Enemy()
  17.     {
  18.         x = 0;
  19.         y = 0;
  20.         isAlive = 1;
  21.     }
  22.     Enemy(int x, int y)
  23.     {
  24.         this->x = x;
  25.         this->y = y;
  26.         isAlive = 1;
  27.     }
  28.     bool getIsAlive()
  29.     {
  30.         return isAlive;
  31.     }
  32.     int getX()
  33.     {
  34.         return x;
  35.     }
  36.     int getY()
  37.     {
  38.         return y;
  39.     }
  40.     bool getCountryOwn()
  41.     {
  42.         return countryOwn;
  43.     }
  44.     void setPos(int x, int y)
  45.     {
  46.         this->x = x;
  47.         this->y = y;
  48.     }
  49.     void ripEnemy()
  50.     {
  51.         isAlive = 0;
  52.     }
  53. };
  54. class Pirate : public Enemy
  55. {
  56. public:
  57.     Pirate() : Enemy()
  58.     {
  59.         countryOwn = 1;
  60.     }
  61.     Pirate(int x, int y) : Enemy (x,y)
  62.     {
  63.         countryOwn = 1;
  64.     }
  65.     void goStepX()
  66.     {
  67.         if (!isAlive)
  68.             return;
  69.         x += 1;
  70.     }
  71.     void goStepY()
  72.     {
  73.         if (!isAlive)
  74.             return;
  75.         y += 1;
  76.     }
  77.     void attack(Enemy* some)
  78.     {
  79.         if (!isAlive)
  80.             return;
  81.         if (countryOwn != some->getCountryOwn())
  82.             if ((((abs(x - some->getX()) <= 2) ||
  83.                 (abs(some->getX() - x) <= 2)) && (y == some->getY())) ||
  84.                 ((((abs(y - some->getY()) <= 2) ||
  85.                 (abs(some->getY() - y) <= 2)) && (x == some->getX()))))
  86.                 some->ripEnemy();
  87.     }
  88. };
  89.  
  90. class Booly : public Enemy
  91. {
  92.     short isRest;
  93.     bool isFear;
  94. public:
  95.     Booly() : Enemy()
  96.     {
  97.         isRest = 0;
  98.         isFear = 0;
  99.         countryOwn = 0;
  100.     }
  101.     Booly(int x, int y) : Enemy(x,y)
  102.     {
  103.         isRest = 0;
  104.         isFear = 0;
  105.         countryOwn = 0;
  106.     }
  107.     void goStepX()
  108.     {
  109.         if (!isAlive)
  110.             return;
  111.         if ((!isRest)&&(!isFear))
  112.         {
  113.             x += 2;
  114.             isRest = 2;
  115.         }
  116.         else if (!isRest)
  117.             isRest--;
  118.     }
  119.     void goStepY()
  120.     {
  121.         if (!isAlive)
  122.             return;
  123.         if ((!isRest) && (!isFear))
  124.         {
  125.             y += 2;
  126.             isRest = 2;
  127.         }
  128.         else if (!isRest)
  129.             isRest--;
  130.     }
  131.     void attack(Enemy* some)
  132.     {
  133.         if (!isAlive)
  134.             return;
  135.         if (isRest)
  136.         {
  137.             isRest--;
  138.             return;
  139.         }
  140.         if ((!isRest) && (!isFear) && (countryOwn != some->getCountryOwn()))
  141.         {
  142.             if ((((abs(x - some->getX()) <= 10) ||
  143.                 (abs(some->getX() - x) <= 10))&&(y==some->getY())) ||
  144.                 ((((abs(y - some->getY()) <= 10) ||
  145.                 (abs(some->getY() - y) <= 10))&&(x==some->getX()))))
  146.                 some->ripEnemy();
  147.         }
  148.     }
  149. };
  150.  
  151. class General : public Enemy
  152. {
  153.     bool countryOwn; // 0 - Неверляндия, 1 - Пиратомания
  154.     int count;      // кол-во бойцов;
  155.     Pirate** pArmy;
  156.     Booly** bArmy;
  157. public:
  158.     General() : Enemy()
  159.     {}
  160.     General(bool cntrOwn) : Enemy()
  161.     {
  162.         countryOwn = cntrOwn;
  163.     }
  164.     General(int x, int y) : Enemy(x, y)
  165.     {}
  166.    
  167. };
  168.  
  169. class Country
  170. {
  171.     char* name;
  172.     General* gen;
  173.     Pirate* pSoldiers;
  174.     Booly* bSoldiers;
  175.     bool isWin;
  176. };
  177.  
  178. int main()
  179. {
  180.     Pirate oliver;
  181.     cout << "Test1" << endl << oliver.getIsAlive();
  182.     oliver.setPos(9, 0);
  183.     Booly barry;
  184.     barry.attack(&oliver);
  185.     cout << endl;
  186.     cout << oliver.getIsAlive();
  187.  
  188.     General dokinz(0, 1);
  189.     Pirate zoom(0, 0);
  190.     cout << endl << "Test2" << endl << dokinz.getIsAlive();
  191.     zoom.attack(&dokinz);
  192.     cout << endl << dokinz.getIsAlive();
  193.  
  194.     Pirate test1, test2;
  195.     cout << endl << "Test3" << endl << test2.getIsAlive();
  196.     test1.attack(&test2);
  197.     cout << endl << test2.getIsAlive();
  198.     return 0;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement