-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCell.cpp
72 lines (60 loc) · 1.29 KB
/
Cell.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
/*
* Cell.cpp
*
* Created on: Feb 11, 2017
* Author: armin
*/
#include "Cell.h"
#include "Entity.h"
#include "Slippers.h"
#include "Teleport.h"
#include "Beetle.h"
#include "util.h"
#include "Food.h"
#include "Trash.h"
Cell::Cell(int row, int col) : row(row), col(col) {
entity = nullptr;
}
Cell::~Cell() {
if(entity != nullptr)
delete entity;
}
void Cell::setEntity(Entity* entity) {
if(this->entity != nullptr) {
CERR("possibility of memory leakage\n");
}
this->entity = entity;
}
void Cell::delEntity() {
if(this->entity == nullptr)
return;
delete(this->entity);
this->entity = nullptr;
}
Entity* Cell::getEntity() {
return this->entity;
}
Beetle* Cell::getBeetle() {
if(this->entity == nullptr)
return nullptr;
return dynamic_cast<Beetle*> (this->entity);
}
Slippers* Cell::getSlipper() {
return dynamic_cast<Slippers*> (this->entity);
}
Food* Cell::getFood() {
return dynamic_cast<Food*> (this->entity);
}
Trash* Cell::getTrash(){
return dynamic_cast<Trash*> (this->entity);
}
Entity* Cell::getItem() {
return this->entity;
}
Teleport* Cell::getTeleport() {
return dynamic_cast<Teleport*> (this->entity);
}
void Cell::setPosition(int row, int col) {
this->row = row;
this->col = col;
}