-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenum.h
More file actions
75 lines (60 loc) · 1.29 KB
/
enum.h
File metadata and controls
75 lines (60 loc) · 1.29 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
#ifndef ENUM_H
#define ENUM_H
//Enums
enum class CellType {
empty,
grass,
sand,
wall,
busyByPlayer,
busyByEnemy,
cellTypeCount
};
enum class DamageType : short {
None = 0,
Fire = 1,
Ice = 2,
Long = 4,
Near = 8
};
enum class Direction {
nope = 0,
up = -1,
down = 1,
left = -1,
right = 1
};
//Overloaded operators special for enums
static DamageType operator | (DamageType l, DamageType r)
{
return static_cast<DamageType>(static_cast<short>(l) |
static_cast<short>(r));
}
static bool operator & (DamageType l, DamageType r)
{
return static_cast<bool>(static_cast<short>(l) &
static_cast<short>(r));
}
static bool operator && (DamageType l, DamageType r)
{
return static_cast<bool>(static_cast<short>(l) &&
static_cast<short>(r));
}
static int operator + (CellType l, int r)
{
return static_cast<int>(static_cast<int>(l) + r);
}
static int operator - (CellType l, int r)
{
return static_cast<int>(static_cast<int>(l) - r);
}
static int operator + (int l, Direction r)
{
return static_cast<int>(static_cast<int>(l) + r);
}
static int operator += (int& l, Direction r)
{
l = static_cast<int>(static_cast<int>(l) + r);
return l;
}
#endif // ENUM_H