-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.cpp
More file actions
60 lines (45 loc) · 964 Bytes
/
Cell.cpp
File metadata and controls
60 lines (45 loc) · 964 Bytes
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
// Cell.cpp -- ALP PISKIN & ANKIT KOTWAL
#include "Cell.h"
#include <vector>
#include <cstdlib>
using std::vector;
Cell::Cell(unsigned x, unsigned y, Grid* grid) {
organism = NULL;
this->x = x;
this->y = y;
this->grid = grid;
}
Organism* Cell::getOrganism() {
return organism;
}
void Cell::setOrganism(Organism* org) {
if (org != NULL) {
org->setCell(this);
}
organism = org;
}
Cell::~Cell() {
}
unsigned Cell::getX(){return x;}
unsigned Cell::getY(){return y;}
Grid* Cell::getGrid(){return grid;}
vector<Cell*> Cell::getAdjacent(){
std::vector<Cell*> cell;
int left = x - 1;
int right = x + 1;
int up = y - 1;
int down = y + 1;
if(left > -1){
cell.push_back(grid->getData()[left][y]);
}
if(right < (int)grid->getWidth()){
cell.push_back(grid->getData()[right][y]);
}
if(down < (int)grid->getHeight()){
cell.push_back(grid->getData()[x][down]);
}
if(up > -1){
cell.push_back(grid->getData()[x][up]);
}
return cell;
}