-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponent.h
73 lines (56 loc) · 1.52 KB
/
Component.h
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
//
// Created by bear on 2021-10-01.
//
/*
Programmer Evaluation – Step 2 of 3
Given a 2D Entity where each has a Rectangle2D bounding box and optional Components:
• Add a Rectangle2D bounding box member to the Entity.
• Add a collection of Components to the Entity. An Entity may have any number of
Components. Assume there will be more than the three example Components below.
• Write the implementation to make Entity copyable.
• Feel free to modify the existing code as desired.
*/
#ifndef UNTITLED_COMPONENT_H
#define UNTITLED_COMPONENT_H
#include <iostream>
class Component {
public:
virtual ~Component() = default;
virtual char ComponentType() const{}
bool operator==(const Component &otherComponent) const {
return this->ComponentType() == otherComponent.ComponentType();
}
struct HashFunction {
size_t operator()(const Component &component) const {
return std::hash<int>()(component.ComponentType());
}
};
};
class HealthComponent : public Component {
private:
int m_health = 0;
public:
char ComponentType() const {
return 'H';
}
~HealthComponent(){}
};
class AttackComponent : public Component {
private:
unsigned int m_attackPower = 0;
public:
char ComponentType() const {
return 'A';
}
~AttackComponent(){}
};
class MovementComponent : public Component {
private:
float m_speed = 0;
public:
char ComponentType() const {
return 'M';
}
~MovementComponent(){}
};
#endif //UNTITLED_COMPONENT_H