Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <string>
- using namespace std;
- class Spell {
- public:
- int dhp;
- int dmp;
- Spell(int dhp, int dmp) {
- this->dhp = dhp;
- this->dmp = dmp;
- }
- };
- class Character {
- public:
- int hp;
- Character(int hp) {
- this->hp = hp;
- }
- virtual void hit(Spell* spl) {
- this->hp -= spl->dhp;
- cout << " ударил персонажа и отнял " << spl->dhp << "hp" << endl;
- cout << "Теперь у персонажа " << hp << "hp" << endl;
- }
- };
- class Human: public Character {
- public:
- string name;
- Human(int hp): Character(hp) {
- this->name = "Uninitialized";
- }
- Human(string name, int hp): Character(hp) {
- this->name = name;
- }
- virtual void hit(Spell* spl) {
- this->hp -= spl->dhp;
- cout << " ударил человека " << name << " и отнял " << spl->dhp << "hp" << endl;
- cout << "Теперь у человека " << hp << "hp" << endl;
- }
- };
- class Mage: public Human {
- public:
- int mp;
- Mage(string name, int hp, int mp): Human(name, hp) {
- this->mp = mp;
- }
- void cast(Spell* spl, Character* target) {
- cout << "Маг " << name;
- target->hit(spl);
- }
- virtual void hit(Spell* spl) {
- this->hp -= spl->dhp;
- this->mp -= spl->dmp;
- cout << " ударил мага " << name << " и отнял " << spl->dhp << "hp и " << spl->dmp << " маны" << endl;
- cout << "Теперь у мага " << hp << "hp и " << mp << " маны" << endl;
- }
- };
- int main() {
- setlocale(0, "");
- Spell* drain = new Spell(16, 4);
- Spell* bolt = new Spell(5, 2);
- Human* vanya = new Human("Ваня", 100);
- Character* wolf = new Character(100);
- Human* kolya = new Human("Коля", 100);
- Mage* boris = new Mage("Борис", 100, 10);
- Mage* vlad = new Mage("Влад", 100, 10);
- vlad->cast(drain, vanya);
- boris->cast(bolt, vlad);
- delete vanya, wolf, kolya, boris, drain, bolt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement