-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreature.cpp
More file actions
86 lines (63 loc) · 1.34 KB
/
Creature.cpp
File metadata and controls
86 lines (63 loc) · 1.34 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
75
76
77
78
79
80
81
82
83
84
85
86
#include "Creature.h"
int Creature::getDirection(const Board& board)
{
switch (key) {
case UP: // up
coord.decreaseY();
return UP;
case DOWN: //down
coord.increaseY();
return DOWN;
case LEFT: //left
coord.decreaseX();
return LEFT;
case RIGHT: //right
coord.increaseX();
return RIGHT;
default:
return UNDEFINED;
}
}
bool Creature::checkObstacle(const Board& board, int dir)
{
if (board.getMatGame(coord.getY(), coord.getX()) == '#')//check object doesnt cover the walls
{
if (dir == UP)
coord.increaseY();//y++
else if (dir == DOWN)
coord.decreaseY();//y--
else if (dir == LEFT)
coord.increaseX();//x++
else if (dir == RIGHT)
coord.decreaseX();//x--
return true;
}
return false;
}
void Creature::updateStepsFile(std::ofstream& stepsFile, string objectName, int _key)
{
string step = keyToName(_key);
if (!step.empty())
{
if (objectName == "Ghost")
stepsFile << step << " ";
else
stepsFile << objectName << " " << step << " ";
}
}
string Creature::keyToName(int _key) {
switch (_key)
{
case Creature::UP:
return "UP";
case Creature::DOWN:
return "DOWN";
case Creature::LEFT:
return "LEFT";
case Creature::RIGHT:
return "RIGHT";
default:
return "";
break;
}
}