Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
1
Indexable
Never
#include <iostream>
using namespace std;

class Enemy {
protected:
    int attackPower;
public:
    void setAttackPower(int a) {
        attackPower = a;
    }
};

class Ninja : public Enemy {
public:
    void attack() {
        cout << "Ninja! - " << attackPower << endl;
    }
};

class Monster : public Enemy {
public:
    void attack() {
        cout << "Monster! - " << attackPower << endl;
    }
};

class Defender {
protected:
    int protectPower;
public:
    void setProtectPower(int a) {
        protectPower = a;
    }
};

class sniper : public Defender {
public:
    void protect() {
        cout << "Sniper!- " << protectPower << endl;
    }
};

class superman : public Defender {
public:
    void protect() {
        cout << "Superman!- " << protectPower << endl;
    }
};


int main() {
    Ninja n;
    Monster m;
    Enemy* e1 = &n;
    Enemy* e2 = &m;

    e1->setAttackPower(20);
    e2->setAttackPower(80);

    n.attack();
    m.attack();

    sniper k;
    superman s;
    Defender* d1 = &k;
    Defender* d2 = &s;

    d1->setProtectPower(50);
    d2->setProtectPower(100);

    k.protect();
    s.protect();
}