-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.cpp
More file actions
57 lines (48 loc) · 959 Bytes
/
Cell.cpp
File metadata and controls
57 lines (48 loc) · 959 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
#include "Cell.h"
Cell::Cell(int r, int c)
{
dir = DOWN; //the first direction that will be tried after this location
row = r;
col = c;
}
Cell::~Cell()
{}
int Cell::getRow()
{
return row;
}
int Cell::getCol()
{
return col;
}
Direction Cell::getDir()
{
return dir;
}
Cell* Cell::nextCell()
{
Cell* cell = NULL;
if (dir == DOWN) //down was a dead end, move right next
{
cell = new Cell(row + 1, col);
dir = RIGHT;
}
else if (dir == RIGHT) //move up
{
cell = new Cell(row, col + 1);
dir = UP;
}
else if (dir == UP) //move left
{
cell = new Cell(row - 1, col);
dir = LEFT;
}
//all 4 directions have been tried
//if we come back here for another direction, this cell is invalid and must be discarded
else if (dir == LEFT)
{
cell = new Cell(row, col - 1);
dir = DEAD_END;
}
return cell; //returns NULL if all options have been attempted
}