blob: cc9cdb17be254961b0476cced78a5f6c35369370 (
plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
|
#include "Grid.hpp"
//Constructor
Grid::Grid(int size)
{
//Create Vector
m_size = size;
m_table = std::vector<std::vector<Cell*> >(size);
//Init all of line and cell
for(int i = 0 ; i < size ; i++)
{
m_table[i] = std::vector<Cell*>(size);
for (int j = 0 ; j < size ; j++)
{
Cell * cell = new Cell();
m_table[i][j] = cell;
}
}
}
//Destructor
Grid::~Grid()
{
for(int i = 0 ; i < m_size ; i++)
{
for(int j = 0 ; j < m_size ; j++)
delete m_table[i][j];
}
}
void Grid::show()
{
std::cout << "_________________" << std::endl;
std::cout << std::endl;
for(int i = 0 ; i < m_size ; i++)
{
std::cout << "|";
for(int j = 0 ; j < m_size ; j++)
{
std::cout << " " << m_table[i][j]->description() << " |";
}
std::cout << std::endl;
if (i != m_size -1)
std::cout << std::endl;
}
std::cout << "_________________" << std::endl;
}
bool Grid::isEmpty(int i, int j)
{
if (i >= 0 && i < m_size && j >= 0 && j < m_size)
return m_table[i][j]->isEmpty();
return false;
}
bool Grid::gridIsFull()
{
bool isFull = true;
for (int i = 0; i < m_size && isFull; i++)
{
for (int j = 0; j < m_size && isFull; j++)
{
if (m_table[i][j]->isEmpty())
isFull = false;
}
}
return isFull;
}
void Grid::setCell(int i, int j, Cell *cell)
{
if (i >= 0 && i < m_size && j >= 0 && j < m_size)
{
delete m_table[i][j];
m_table[i][j] = cell;
}
}
|