This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CellProperty.cpp
146 lines (123 loc) · 3.35 KB
/
CellProperty.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "CellProperty.hh"
CellProperty::CellProperty(const bool walkable, const bool swimmable, const bool flyable, const bool event, const bool monster) noexcept
: _walkable(walkable), _swimmable(swimmable), _flyable(flyable), _event(event), _monster(monster)
{
}
CellProperty::CellProperty(const CellType cell) noexcept
{
switch (cell) {
case CellType::GrassCell:
CellProperty(true, false, true, false, false);
break;
case CellType::WaterCell:
CellProperty(false, true, true, false, false);
break;
case CellType::RockCell:
CellProperty(false, false, true, false, false);
break;
case CellType::MountainCell:
default:
CellProperty(false, false, false, false, false);
break;
}
}
bool CellProperty::operator==(CellProperty property) const noexcept
{
return this->isEqual(property);
}
bool CellProperty::operator!=(CellProperty property) const noexcept
{
return !this->isEqual(property);
}
bool CellProperty::isEqual(const CellProperty property) const noexcept
{
return (this->isWalkable() == property.isWalkable()) &&
(this->isSwimmable() == property.isSwimmable()) &&
(this->isFlyable() == property.isFlyable()) &&
(this->isEvent() == property.isEvent()) &&
(this->isMonster() == property.isMonster());
}
bool CellProperty::isWalkable(void) const noexcept
{
return _walkable;
}
void CellProperty::setWalkable(void) noexcept
{
this->_walkable = true;
}
void CellProperty::setNotWalkable(void) noexcept
{
this->_walkable = false;
}
bool CellProperty::isSwimmable(void) const noexcept
{
return this->_swimmable;
}
void CellProperty::setSwimmable(void) noexcept
{
this->_swimmable = true;
}
void CellProperty::setNotSwimmable(void) noexcept
{
this->_swimmable = false;
}
bool CellProperty::isFlyable(void) const noexcept
{
return this->_flyable;
}
void CellProperty::setFlyable(void) noexcept
{
this->_flyable = true;
}
void CellProperty::setNotFlyable(void) noexcept
{
this->_flyable = false;
}
bool CellProperty::isEvent(void) const noexcept
{
return this->_event;
}
void CellProperty::setEvent(void) noexcept
{
this->_event = true;
}
void CellProperty::setNotEvent(void) noexcept
{
this->_event = false;
}
bool CellProperty::isMonster(void) const noexcept
{
return _monster;
}
void CellProperty::setMonster(void) noexcept
{
this->_monster = true;
}
void CellProperty::setNotMonster(void) noexcept
{
this->_monster = false;
}
CellProperty getCellFlags(const CellType cell) noexcept
{
switch (cell) {
case CellType::GrassCell:
return CellProperty(true, false, true, false, false);
case CellType::WaterCell:
return CellProperty(false, true, true, false, false);
case CellType::RockCell:
return CellProperty(false, false, true, false, false);
case CellType::MountainCell:
return CellProperty(false, false, false, false, false);
default:
return CellProperty(false, false, false, false, false);
}
}
bool hasFlag(CellType cell, CellProperty property) noexcept
{
CellProperty cellProperty(getCellFlags(cell));
return (cellProperty.isWalkable() == property.isWalkable()) ||
(cellProperty.isSwimmable() == property.isSwimmable()) ||
(cellProperty.isFlyable() == property.isFlyable()) ||
(cellProperty.isEvent() == property.isEvent()) ||
(cellProperty.isMonster() == property.isMonster());
}