1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
| #pragma once
#include <iostream>
#include <string>
using namespace std;
class GameObject
{
private:
string title;
double mass; //kg
protected:
GameObject() : mass(0.0) {}
GameObject(const GameObject& obj) : title(obj.title), mass(obj.mass) {}
GameObject(const string& _title, double _mass) : title(_title), mass(_mass) {}
virtual ~GameObject() { cout << "Game object deleted" << endl << endl; }
virtual void _print() const { cout << "title: " << title << ", mass: " << mass; }
public:
void print() const
{
cout << typeid(*this).name() << " : (";
_print();
cout << ")" << endl;
}
double get_mass() const
{
return mass;
}
};
class MythicalAnimal : public virtual GameObject
{
private:
double speed;
int strength;
public:
MythicalAnimal() : GameObject() {}
MythicalAnimal(const MythicalAnimal& obj) : GameObject(obj), speed(obj.speed), strength(obj.strength) {}
MythicalAnimal(const string& _title, double _mass, double _speed, int _strength)
: GameObject(_title, _mass), speed(_speed), strength(_strength) {}
~MythicalAnimal() { cout << "Mythical animal deleted" << endl; }
double get_speed() const
{
return speed;
}
int get_strength() const
{
return strength;
}
protected:
void _print() const
{
GameObject::_print();
cout << ", speed: " << speed << ", strength: " << strength;
}
};
class predator : public virtual GameObject
{
protected:
predator() {}
public:
~predator() {}
virtual void fight(const MythicalAnimal& obj) = 0;
};
class HumanoidCharacter : public MythicalAnimal, public predator
{
private:
double speed;
int strength;
public:
HumanoidCharacter() : MythicalAnimal() {}
HumanoidCharacter(const HumanoidCharacter& obj) : MythicalAnimal(obj), speed(obj.speed), strength(obj.strength) {}
HumanoidCharacter(const string& _title, double _mass, double _speed, int _strength)
: MythicalAnimal(_title, _mass, _speed, _strength) {}
~HumanoidCharacter() { cout << "Humanoid character deleted" << endl; }
/*virtual void fight(const MythicalAnimal& obj);
void fight(MythicalAnimal& obj)
{
int k1 = 0, k2 = 0;
if (HumanoidCharacter::get_mass > obj.get_mass) k1++;
else if (HumanoidCharacter::get_mass < obj.get_mass) k2++;
if (HumanoidCharacter::speed > obj.get_speed) k1++;
else if (HumanoidCharacter::speed < obj.get_speed) k2++;
if (HumanoidCharacter::strength > obj.get_strength) k1++;
else if (HumanoidCharacter::strength < obj.get_strength) k2++;
cout << k1 << " : " << k2;
}*/
};
class MagicCharacter : public HumanoidCharacter
{
private:
string power;
int strength;
public:
MagicCharacter() : HumanoidCharacter() {}
MagicCharacter(const MagicCharacter& obj) : HumanoidCharacter(obj), power(obj.power), strength(obj.strength) {}
MagicCharacter(const string& _title, double _mass, double _speed, int _strength, string _power)
: HumanoidCharacter(_title, _mass, _speed, _strength), power(_power) {}
~MagicCharacter() { cout << "Magic character deleted" << endl; }
};
class MagicThing : public GameObject
{
private:
string use;
public:
MagicThing() : GameObject() {}
MagicThing(const MagicThing& obj) : GameObject(obj), use(obj.use) {}
MagicThing(const string& _title, double _mass, string _use)
: GameObject(_title, _mass), use(_use) {}
~MagicThing() { cout << "Magic thing deleted" << endl; }
string get_use() const
{
return use;
}
protected:
void _print() const
{
GameObject::_print();
cout << ", use: " << use;
}
}; |