Advertisement
Guest User

сиспрога, маг, хуман, спел, карактер

a guest
Dec 14th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Spell {
  8. public:
  9.     int dhp;
  10.     int dmp;
  11.     Spell(int dhp, int dmp) {
  12.         this->dhp = dhp;
  13.         this->dmp = dmp;
  14.     }
  15. };
  16.  
  17. class Character {
  18. public:
  19.     int hp;
  20.     Character(int hp) {
  21.         this->hp = hp;
  22.     }
  23.     virtual void hit(Spell* spl) {
  24.         this->hp -= spl->dhp;
  25.         cout << " ударил персонажа и отнял " << spl->dhp << "hp" << endl;
  26.         cout << "Теперь у персонажа " << hp << "hp" << endl;
  27.     }
  28. };
  29.  
  30. class Human: public Character {
  31. public:
  32.     string name;
  33.     Human(int hp): Character(hp) {
  34.         this->name = "Uninitialized";
  35.     }
  36.     Human(string name, int hp): Character(hp) {
  37.         this->name = name;
  38.     }
  39.     virtual void hit(Spell* spl) {
  40.         this->hp -= spl->dhp;
  41.         cout << " ударил человека " << name << " и отнял " << spl->dhp << "hp" << endl;
  42.         cout << "Теперь у человека " << hp << "hp" << endl;
  43.     }
  44. };
  45.  
  46. class Mage: public Human {
  47. public:
  48.     int mp;
  49.     Mage(string name, int hp, int mp): Human(name, hp) {
  50.         this->mp = mp;
  51.     }
  52.     void cast(Spell* spl, Character* target) {
  53.         cout << "Маг " << name;
  54.         target->hit(spl);
  55.     }
  56.     virtual void hit(Spell* spl) {
  57.         this->hp -= spl->dhp;
  58.         this->mp -= spl->dmp;
  59.         cout << " ударил мага " << name << " и отнял " << spl->dhp << "hp и " << spl->dmp << " маны" << endl;
  60.         cout << "Теперь у мага " << hp << "hp и " << mp << " маны" << endl;
  61.     }
  62. };
  63.  
  64. int main() {
  65.     setlocale(0, "");
  66.     Spell* drain = new Spell(16, 4);
  67.     Spell* bolt = new Spell(5, 2);
  68.  
  69.     Human* vanya = new Human("Ваня", 100);
  70.     Character* wolf = new Character(100);
  71.     Human* kolya = new Human("Коля", 100);
  72.     Mage* boris = new Mage("Борис", 100, 10);
  73.     Mage* vlad = new Mage("Влад", 100, 10);
  74.  
  75.     vlad->cast(drain, vanya);
  76.     boris->cast(bolt, vlad);
  77.  
  78.     delete vanya, wolf, kolya, boris, drain, bolt;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement