#include "Grid.hpp" //Constructor Grid::Grid(int size) { //Create Vector m_size = size; m_table = std::vector*> >(size); //Init all of line and cell for(int i = 0 ; i < size ; i++) { m_table[i] = std::vector*>(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() { for (int i = 0; i < m_size ; i++) { for (int j = 0; j < m_size ; j++) { if (m_table[i][j]->isEmpty()) return false; } } return true; } 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; } } Cell* Grid::getCell(short i, short j){ return m_table[i][j]; } int Grid::getNRows(){ return m_table[0].size(); } int Grid::getNCols(){ return m_table.size(); }