-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.cpp
73 lines (54 loc) · 1.25 KB
/
tile.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
#include "tile.h"
Tile::Tile(const std::string& texture, Character* player, const int& col, const int& row)
: texture(texture), player(player), col(col), row(row)
{
}
bool Tile::moveTo(Tile *destTile, Character *who)
{
bool canMove = true;
Tile* actualLeftTile = onLeave(destTile,who);
if(actualLeftTile == nullptr){
canMove = false;
}else{
Tile* actualEnteredTile=destTile->onEnter(actualLeftTile, who);
if(actualEnteredTile == nullptr){
canMove = false;
}else{
actualLeftTile->setPlayer(nullptr);
who->setCurrentTile(actualEnteredTile);
actualEnteredTile->setPlayer(who);
}
}
return canMove;
}
bool Tile::hasCharacter()
{
if(player==nullptr){
return false;
}else{
return true;
}
}
const std::string &Tile::getTexture()
{
if(hasCharacter()){
return player->getTexture();
}
return texture;
}
void Tile::setTexture(const std::string &newTexture)
{
texture = newTexture;
}
int Tile::getRow() const
{
return row;
}
int Tile::getColumn() const
{
return col;
}
void Tile::setPlayer(Character *newPlayer)
{
player = newPlayer;
}