diff --git a/.gitignore b/.gitignore index 766f778..5609314 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ CMakeCache.txt *.app 2P11 clear.sh +*.vim diff --git a/src/Controllers/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp index 4be0375..4ee4965 100644 --- a/src/Controllers/ConsoleController/ConsoleController.cpp +++ b/src/Controllers/ConsoleController/ConsoleController.cpp @@ -24,8 +24,9 @@ void ConsoleController::play() m_game->showGrid(); //Start game - while (!m_game->isOver()) + while (1) { + std::cout << m_game->isOver(); //Get key press keyPress=this->waitArrowKeyPress(); diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index cb4bc21..3371fda 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -34,18 +34,18 @@ template class Cell //Test if the cell is empty bool isEmpty() { - return true; + return this->m_Element->isEmpty(); } - T getElement(){ + T* getElement(){ return this->m_Element; } bool equals(Cell *cell){ - /*if(cell->getElement() == this->m_Element){ + if(m_Element->equals(cell->getElement())){ return true; - }*/ - return true; + } + return false; } //Return the element value @@ -67,7 +67,7 @@ template class Cell template bool operator==(Cell a, Cell b){ - return true; + return a.equals(&b); } #endif diff --git a/src/Model/Elements/StringElement.cpp b/src/Model/Elements/StringElement.cpp index fbf57c1..a197c22 100644 --- a/src/Model/Elements/StringElement.cpp +++ b/src/Model/Elements/StringElement.cpp @@ -33,15 +33,10 @@ bool StringElement::isEmpty(){ return false; } -bool StringElement::equals(StringElement const& element) const{ - if(this->m_value.compare(element.m_value) == 0){ +bool StringElement::equals(StringElement *element){ + if(this->m_value.compare(element->m_value) == 0){ return true; } - return true; + return false; } - -bool operator==(StringElement const& a, StringElement const& b){ - return a.equals(b); -} - diff --git a/src/Model/Elements/StringElement.hpp b/src/Model/Elements/StringElement.hpp index 16946a8..55c5473 100644 --- a/src/Model/Elements/StringElement.hpp +++ b/src/Model/Elements/StringElement.hpp @@ -21,7 +21,7 @@ class StringElement void setValue(std::string value); bool isEmpty(); - bool equals(StringElement const& element) const; + bool equals(StringElement *element); std::string description(); }; diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index c2252ff..3054990 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -10,18 +10,7 @@ Game::~Game() delete m_grid; } -void Game::play() -{ - while(!m_grid->gridIsFull()) - { - m_grid->show(); - pop(); - std::cout << std::endl; - } - - m_grid->show(); -} void Game::showGrid() { @@ -50,5 +39,12 @@ void Game::pop() bool Game::isOver() { - return m_grid->gridIsFull(); + if(m_grid->gridIsFull()){ + for(int i=0;i<4;i++){ + std::cout << m_grid->getCell(0,i)->description(); + } + + } + + return true; } diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index bbdcfcc..0666191 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -15,13 +15,12 @@ class Game { private: - Grid * m_grid; + Grid *m_grid; public: Game(); ~Game(); - void play(); void pop(); void showGrid(); bool isOver(); diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 103b95f..b6ef8c4 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -58,18 +58,17 @@ bool Grid::isEmpty(int i, int j) bool Grid::gridIsFull() { - bool isFull = true; - for (int i = 0; i < m_size && isFull; i++) + for (int i = 0; i < m_size ; i++) { - for (int j = 0; j < m_size && isFull; j++) + for (int j = 0; j < m_size ; j++) { if (m_table[i][j]->isEmpty()) - isFull = false; + return false; } } - return isFull; + return true; } void Grid::setCell(int i, int j, Cell *cell) @@ -81,5 +80,14 @@ void Grid::setCell(int i, int j, Cell *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(); +} diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index a291cc8..b7c1f9f 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -27,7 +27,10 @@ class Grid bool isEmpty(int i, int j); bool gridIsFull(); - void setCell(int i, int j, Cell * cell); + int getNRows(); + int getNCols(); + void setCell(int i, int j, Cell *cell); + Cell* getCell(short i, short j); }; diff --git a/src/main.cpp b/src/main.cpp index 217fe81..cfb0c7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,15 +19,15 @@ int main() { - Cell cell1("loic"); - Cell cell2("loic"); + Cell *cell1 = new Cell(""); + Cell *cell2 = new Cell("i"); - if(cell1==cell2){ - std::cout << "Egale" << std::endl; + if(cell2->isEmpty()){ + std::cout << "Empty" << std::endl; } else{ - std::cout << "Différent" << std::endl; + std::cout << "Not empty" << std::endl; } //Init random