-
Notifications
You must be signed in to change notification settings - Fork 0
/
Effector.cpp
60 lines (46 loc) · 1010 Bytes
/
Effector.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
#include "Effector.h"
#include "Map.h"
#include <cmath>
using namespace std;
Effector::Effector(Map *mp) {
map = mp;
}
Effector::~Effector() {
}
int Effector::actOnCell(int targetAction, int actionCredit) {
int res = 0;
if (targetAction == 1 && actionCredit >= 1) {
map->pickup();
res = 1;
} else if (targetAction == 2 && actionCredit >= 1) {
map->clean();
res = 1;
} else if (targetAction == 3) {
if (actionCredit >= 1) {
map->pickup();
res += 1;
actionCredit--;
}
if (actionCredit >= 1) {
map->clean();
res += 1;
}
}
return res;
}
void Effector::travel(int destX, int destY) {
int coordX = map->getVacuum().first;
int coordY = map->getVacuum().second;
if (destX != coordX || destY != coordY) {
map->getCell(coordX, coordY)->setVacuum(false);
if (destX > coordX)
coordX++;
else if (destX < coordX)
coordX--;
else if (destY > coordY)
coordY++;
else if (destY < coordY)
coordY--;
map->getCell(coordX, coordY)->setVacuum(true);
}
}