forked from doxman/chamber-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.cc
59 lines (53 loc) · 1.25 KB
/
object.cc
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
#include "object.h"
using namespace std;
// Object class
void Object::setLoc(posn p) // private
{
loc = p;
}
Object::Object(char oC): objectChar(oC), loc(nullPosn) {}
char Object::getObjectChar()
{
return objectChar;
}
posn Object::getLoc()
{
return loc;
}
void Object::initLoc(posn p)
{
if (loc.row == nullPosn.row && loc.col == nullPosn.col)
setLoc(p);
}
// Subclasses
Player::Player(): Object(PLAYER), tileChar(FLOOR) {}
char Player::getTileChar()
{
return tileChar;
}
Stairs::Stairs(): Object(STAIRS) {}
Potion::Potion(): Object(POTION) {}
Gold::Gold(): Object(GOLD){}
Enemy::Enemy(): Object(ENEMY) {}
void Enemy::move(int dir)
{
posn current = getLoc();
posn p;
if (dir == NORTH)
p.row = current.row - 1, p.col = current.col;
else if (dir == NORTHWEST)
p.row = current.row - 1, p.col = current.col - 1;
else if (dir == NORTHEAST)
p.row = current.row - 1, p.col = current.col + 1;
else if (dir == WEST)
p.row = current.row, p.col = current.col - 1;
else if (dir == EAST)
p.row = current.row, p.col = current.col + 1;
else if (dir == SOUTHWEST)
p.row = current.row + 1, p.col = current.col - 1;
else if (dir == SOUTHEAST)
p.row = current.row + 1, p.col = current.col + 1;
else
p.row = current.row + 1, p.col = current.col;
setLoc(p);
}