summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-02 11:06:54 +0200
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-02 11:06:54 +0200
commit6b8a144bd192de206e11a171841ec6161d11b6aa (patch)
tree0e0d17f8571750233c4b3008b45e2284d2b03f15
parent01b25accba1a5329e220aa647255d2c2b284c16e (diff)
Correct bugs
-rw-r--r--.gitignore1
-rw-r--r--src/Controllers/ConsoleController/ConsoleController.cpp3
-rw-r--r--src/Model/Cell.hpp12
-rw-r--r--src/Model/Elements/StringElement.cpp11
-rw-r--r--src/Model/Elements/StringElement.hpp2
-rw-r--r--src/Model/Game.cpp20
-rw-r--r--src/Model/Game.hpp3
-rw-r--r--src/Model/Grid.cpp18
-rw-r--r--src/Model/Grid.hpp5
-rw-r--r--src/main.cpp10
10 files changed, 44 insertions, 41 deletions
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 T> 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<T> *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 T> class Cell
template<class T>
bool operator==(Cell<T> a, Cell<T> 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;
-}
-
-bool operator==(StringElement const& a, StringElement const& b){
- return a.equals(b);
+ return false;
}
-
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<StringElement> *cell)
@@ -81,5 +80,14 @@ void Grid::setCell(int i, int j, Cell<StringElement> *cell)
}
}
+Cell<StringElement>* 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<StringElement> * cell);
+ int getNRows();
+ int getNCols();
+ void setCell(int i, int j, Cell<StringElement> *cell);
+ Cell<StringElement>* 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<StringElement> cell1("loic");
- Cell<StringElement> cell2("loic");
+ Cell<StringElement> *cell1 = new Cell<StringElement>("");
+ Cell<StringElement> *cell2 = new Cell<StringElement>("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