/
object.h
92 lines (73 loc) · 2.17 KB
/
object.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef OBJECT_H
#define OBJECT_H
#include <algorithm>
#include "constants.h"
#include "color.h"
class Object
{
public:
Object();
// making destructor virtual tells compiler to call most derived class' destructor when we
// delete pointer to Object. That way we can be sure that all resources are freed correctly.
// Even though we don't actually derive anything from this class, we need specifier in order to
// ensure compiler it's okay to do deletes
virtual ~Object() {};
protected:
Color color; //object's color
unsigned int size; //diameter in special pixels (1/60 of real pixel)
int orientation; //orientation (in degrees)
Intersection intersection; //type of intersection
bool movable; //is object movable
std::pair<int, int> coords; //object's coordinates, first - x, second - y;
public:
// Getters
virtual bool isMovable() = 0;
Color getColor()
{
return color;
}
unsigned int getSize()
{
return size;
}
unsigned int getOrientation()
{
return orientation;
}
Intersection getIntersection()
{
return intersection;
}
std::pair<int, int> getCoords()
{
return coords;
}
// Setters
void setSize(int size)
{
this->size = size;
}
void setOrientation(int orientation)
{
// orientation % 360 strips unnecessary rounds from the angle, but leaves the sign in place
// (e.g. negative number stays negative). Thus we add 360 to convert negative number into
// positive one, and then once again take modulo to put result back into [0..360] range
this->orientation = (360 + (orientation % 360)) % 360;
}
void setColor(Color color)
{
this->color = color;
}
void setCoords(int x, int y)
{
coords = std::pair<int, int>(x, y);
}
void setIntersection(Intersection intersection)
{
this->intersection = intersection;
}
};
#endif // OBJECT_H
/* Limit line length to 100 characters; highlight 99th column
* vim: set textwidth=100 colorcolumn=-1:
*/