summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-04 13:08:45 +0200
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-04 13:08:45 +0200
commit1bebaf0f924c83bfb5a91bafefcb69d98e3b8b05 (patch)
tree7b950d1bc755aa648bb3e8777e4fc6bc684bd001
parent3384204edca8720958b7d20c72956037b03238ae (diff)
Prefer extends Game to grid than encapsulation
-rw-r--r--src/Model/Game.cpp36
-rw-r--r--src/Model/Game.hpp10
-rw-r--r--src/Model/Grid.hpp3
3 files changed, 25 insertions, 24 deletions
diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp
index e2ac799..9c67184 100644
--- a/src/Model/Game.cpp
+++ b/src/Model/Game.cpp
@@ -4,7 +4,7 @@
//==================== Constructor and Destructor ====================
//Constructor
-Game::Game() : m_grid(), m_score(0), m_nbMove(0){
+Game::Game() : Grid(), m_nbMove(0), m_score(0){
}
//Destructor
@@ -21,21 +21,21 @@ bool Game::swipe(kbdh::Direction direction){
switch(direction){
case kbdh::Left:
- moveDone=m_grid.swipeLeft();
+ moveDone=swipeLeft();
break;
case kbdh::Right:
- moveDone=m_grid.swipeRight();
+ moveDone=swipeRight();
break;
case kbdh::Up:
- moveDone=m_grid.swipeUp();
+ moveDone=swipeUp();
break;
case kbdh::Down:
- moveDone=m_grid.swipeDown();
+ moveDone=swipeDown();
break;
}
if(moveDone){
- m_score+=m_grid.getLastMoveScore();
+ m_score+=m_lastMoveScore;
m_nbMove++;
this->popRandomNumber();
}
@@ -46,17 +46,17 @@ bool Game::swipe(kbdh::Direction direction){
//Cout the grid
void Game::coutGrid(){
- std::cout << m_grid.description();
+ std::cout << this->description();
}
//Return true if the game is lost. False else.
-bool Game::isOver(){
- return m_grid.isOver();
-}
+//bool Game::isOver(){
+ //return m_grid.isOver();
+//}
//Pop a random number on the grid
void Game::popRandomNumber(){
- std::tuple<int, int> coord(m_grid.getRandomEmptyCellCoord());
+ std::tuple<int, int> coord(Grid::getRandomEmptyCellCoord());
int percent=rand() % 100;
@@ -70,7 +70,7 @@ void Game::popRandomNumber(){
}
- m_grid.setCell(coord, number);
+ Grid::setCell(coord, number);
}
//==================== Getters and Setter ====================
@@ -84,11 +84,11 @@ int Game::getNbMove(){
return m_nbMove;
}
-std::vector<std::vector<int> > Game::getGrid(){
- return m_grid.getGrid();
-}
+//std::vector<std::vector<int> > Game::getGrid(){
+ //return m_grid.getGrid();
+//}
-int Game::maxStrLenInGrid(){
- return m_grid.maxStrLenInGrid();
-}
+//int Game::maxStrLenInGrid(){
+ //return m_grid.maxStrLenInGrid();
+//}
diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp
index e5d19e5..77be7d7 100644
--- a/src/Model/Game.hpp
+++ b/src/Model/Game.hpp
@@ -13,11 +13,11 @@
#include "Grid.hpp"
#include <tuple>
-class Game
+class Game : public Grid
{
private:
//Members
- Grid m_grid;
+ //Grid m_grid;
int m_score;
int m_nbMove;
@@ -30,13 +30,13 @@ class Game
bool swipe(kbdh::Direction direction);
void coutGrid();
void popRandomNumber();
- bool isOver();
+ //bool isOver();
//Getters and Setters
int getScore();
int getNbMove();
- int maxStrLenInGrid();
- std::vector<std::vector<int> > getGrid();
+ //int maxStrLenInGrid();
+ //std::vector<std::vector<int> > getGrid();
};
#endif
diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp
index 604a6ff..22416b0 100644
--- a/src/Model/Grid.hpp
+++ b/src/Model/Grid.hpp
@@ -16,8 +16,9 @@ class Grid
{
private:
//Members
- int m_size;
+ protected:
std::vector<std::vector<int> > m_grid;
+ int m_size;
int m_lastMoveScore;
//Private methods