-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.cc
70 lines (54 loc) · 1.28 KB
/
cell.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
60
61
62
63
64
65
66
67
68
69
70
#include <vector>
#include <memory>
#include "npc.h"
#include "cell.h"
#include "pc.h"
#include "sprite.h"
#include <iostream>
using namespace std;
// This is the implementation for the Cell class, see cell.h for documentation
Cell::Cell(CellType type, unsigned int y, unsigned int x) : type{type}, attacked{false}, y{y}, x{x}, sprite{nullptr} {}
void Cell::notify(Cell &a_cell) {
if(sprite != nullptr && a_cell.sprite!=nullptr &&
a_cell.sprite->isPC() && sprite->isNPC() && (dynamic_pointer_cast<NPC>(sprite))->isHostile()){
(dynamic_pointer_cast<NPC>(sprite))->hit(*dynamic_pointer_cast<PC>(a_cell.sprite));
attacked = true;
}
}
bool Cell::hasAttacked() {
bool temp = attacked;
attacked = false;
return temp;
}
void Cell::notifyAll() {
for(auto observer: observers){
observer->notify(*this);
}
}
void Cell::attach(Cell &observer) {
observers.emplace_back(&observer);
}
vector<Cell*> Cell::getObservers(){
return observers;
}
void Cell::clear(){
observers.clear();
}
CellType Cell::getType() const {
return type;
}
void Cell::setType(CellType type) {
this->type = type;
}
bool Cell::isEmpty() const {
return (sprite == nullptr);
}
unsigned int Cell::getCol() const {
return x;
}
unsigned int Cell::getRow() const {
return y;
}
Cell::~Cell() {
observers.clear();
}