Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <cstdlib>
- #include <ctime>
- #include <cmath>
- using namespace std;
- class Enemy
- {
- protected:
- bool isAlive;
- bool countryOwn;
- int x;
- int y;
- public:
- Enemy()
- {
- x = 0;
- y = 0;
- isAlive = 1;
- }
- Enemy(int x, int y)
- {
- this->x = x;
- this->y = y;
- isAlive = 1;
- }
- bool getIsAlive()
- {
- return isAlive;
- }
- int getX()
- {
- return x;
- }
- int getY()
- {
- return y;
- }
- bool getCountryOwn()
- {
- return countryOwn;
- }
- void setPos(int x, int y)
- {
- this->x = x;
- this->y = y;
- }
- void ripEnemy()
- {
- isAlive = 0;
- }
- };
- class Pirate : public Enemy
- {
- public:
- Pirate() : Enemy()
- {
- countryOwn = 1;
- }
- Pirate(int x, int y) : Enemy (x,y)
- {
- countryOwn = 1;
- }
- void goStepX()
- {
- if (!isAlive)
- return;
- x += 1;
- }
- void goStepY()
- {
- if (!isAlive)
- return;
- y += 1;
- }
- void attack(Enemy* some)
- {
- if (!isAlive)
- return;
- if (countryOwn != some->getCountryOwn())
- if ((((abs(x - some->getX()) <= 2) ||
- (abs(some->getX() - x) <= 2)) && (y == some->getY())) ||
- ((((abs(y - some->getY()) <= 2) ||
- (abs(some->getY() - y) <= 2)) && (x == some->getX()))))
- some->ripEnemy();
- }
- };
- class Booly : public Enemy
- {
- short isRest;
- bool isFear;
- public:
- Booly() : Enemy()
- {
- isRest = 0;
- isFear = 0;
- countryOwn = 0;
- }
- Booly(int x, int y) : Enemy(x,y)
- {
- isRest = 0;
- isFear = 0;
- countryOwn = 0;
- }
- void goStepX()
- {
- if (!isAlive)
- return;
- if ((!isRest)&&(!isFear))
- {
- x += 2;
- isRest = 2;
- }
- else if (!isRest)
- isRest--;
- }
- void goStepY()
- {
- if (!isAlive)
- return;
- if ((!isRest) && (!isFear))
- {
- y += 2;
- isRest = 2;
- }
- else if (!isRest)
- isRest--;
- }
- void attack(Enemy* some)
- {
- if (!isAlive)
- return;
- if (isRest)
- {
- isRest--;
- return;
- }
- if ((!isRest) && (!isFear) && (countryOwn != some->getCountryOwn()))
- {
- if ((((abs(x - some->getX()) <= 10) ||
- (abs(some->getX() - x) <= 10))&&(y==some->getY())) ||
- ((((abs(y - some->getY()) <= 10) ||
- (abs(some->getY() - y) <= 10))&&(x==some->getX()))))
- some->ripEnemy();
- }
- }
- };
- class General : public Enemy
- {
- bool countryOwn; // 0 - Неверляндия, 1 - Пиратомания
- int count; // кол-во бойцов;
- Pirate** pArmy;
- Booly** bArmy;
- public:
- General() : Enemy()
- {}
- General(bool cntrOwn) : Enemy()
- {
- countryOwn = cntrOwn;
- }
- General(int x, int y) : Enemy(x, y)
- {}
- };
- class Country
- {
- char* name;
- General* gen;
- Pirate* pSoldiers;
- Booly* bSoldiers;
- bool isWin;
- };
- int main()
- {
- Pirate oliver;
- cout << "Test1" << endl << oliver.getIsAlive();
- oliver.setPos(9, 0);
- Booly barry;
- barry.attack(&oliver);
- cout << endl;
- cout << oliver.getIsAlive();
- General dokinz(0, 1);
- Pirate zoom(0, 0);
- cout << endl << "Test2" << endl << dokinz.getIsAlive();
- zoom.attack(&dokinz);
- cout << endl << dokinz.getIsAlive();
- Pirate test1, test2;
- cout << endl << "Test3" << endl << test2.getIsAlive();
- test1.attack(&test2);
- cout << endl << test2.getIsAlive();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement