-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.hpp
More file actions
114 lines (106 loc) · 4.12 KB
/
Object.hpp
File metadata and controls
114 lines (106 loc) · 4.12 KB
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
#ifndef OBJECT_HPP
#define OBJECT_HPP
#include <iostream>
#include <cstddef>
struct Coordinates{
size_t axis_x;
size_t axis_y;
Coordinates(){}
Coordinates(size_t arg_x, size_t arg_y) : axis_x(arg_x), axis_y(arg_y){}
Coordinates(Coordinates const &crd){
axis_x = crd.axis_x;
axis_y = crd.axis_y;
}
Coordinates (Coordinates&& crd) : axis_x(std::move(crd.axis_x))
, axis_y(std::move(crd.axis_y)){}
Coordinates &operator=(const Coordinates &crd){
if (this != &crd) {
axis_x = crd.axis_x;
axis_y = crd.axis_y;
}
return *this;
}
Coordinates& operator=(Coordinates&& crd){
axis_x = std::move(crd.axis_x);
axis_y = std::move(crd.axis_y);
return *this;
}
};
class Object {
private:
Coordinates coords;
int hit_points;
size_t position; // of Object in List
public:
Object(){
/*std::cout << "\tx = " << coords.axis_x << std::endl
<< "\ty = " << coords.axis_y << std::endl
<< "\thp = " << hit_points << std::endl
<< "\033[1;32m Object() \033[0m" << std::endl << std::endl;*/
}
Object(size_t arg_x, size_t arg_y, int hp = 100, size_t pos = 0)
: coords(arg_x, arg_y), hit_points(hp), position(pos){
std::cout << "\tx = " << coords.axis_x << std::endl
<< "\ty = " << coords.axis_y << std::endl
<< "\thp = " << hit_points << std::endl
<< "\033[1;32m Object(size_t, size_t, int) \033[0m" << std::endl << std::endl;
}
~Object(){
std::cout << "\tx = " << coords.axis_x << std::endl
<< "\ty = " << coords.axis_y << std::endl
<< "\thp = " << hit_points << std::endl
<< "\033[1;31m ~Object() \033[0m" << std::endl << std::endl;
}
Object(Object const &obj){
coords = obj.get_coords();
hit_points = obj.get_hp();
position = obj.get_position();
std::cout << "\tx = " << coords.axis_x << std::endl
<< "\ty = " << coords.axis_y << std::endl
<< "\thp = " << hit_points << std::endl
<< "\033[1;32m Object(Object const &) \033[0m" << std::endl << std::endl;
}
Object(Object&& obj) : coords(std::move(obj.get_coords())),
hit_points(std::move(obj.get_hp())), position(std::move(obj.get_position())) {
std::cout << "\tx = " << coords.axis_x << std::endl
<< "\ty = " << coords.axis_y << std::endl
<< "\thp = " << hit_points << std::endl
<< "\033[1;32m Object(Object &&) \033[0m" << std::endl << std::endl;
}
Object &operator= (Object&& obj){
coords = std::move(obj.get_coords());
hit_points = std::move(obj.get_hp());
position = std::move(obj.get_position());
return *this;
}
Object &operator= (Object &obj){
if(this != &obj)
{
coords = obj.get_coords();
hit_points = obj.get_hp();
position = obj.get_position();
}
return *this;
}
bool operator== (Object const &obj){
return (obj.coords.axis_x == coords.axis_x && obj.coords.axis_y == coords.axis_y);
}
void get_Damag(size_t const &dmg);
int &get_hp() { return hit_points; }
const int &get_hp()const { return hit_points; }
Coordinates &get_coords() { return coords; }
const Coordinates &get_coords() const { return coords; }
size_t &get_position() { return position; }
const size_t &get_position() const { return position; }
Object* check_Coords(Coordinates const &);
};
Object* Object::check_Coords(Coordinates const &crds){
if(coords.axis_x == crds.axis_x && coords.axis_y == crds.axis_y)
return this;
else
return nullptr;
};
void Object::get_Damag(size_t const &dmg){
get_hp() -= dmg;
}
#endif //OBJECT