diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-05-03 09:57:31 +0200 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-05-03 09:57:31 +0200 |
| commit | 4cc6c6596b614fce392040b85a182dbf50d0b044 (patch) | |
| tree | ec6932c060e8a9ebc54be380832db47fb2c6c735 /src/Model | |
| parent | af7f2fc8700df64f245caf7b864e777831867c3f (diff) | |
Organize all the code
Diffstat (limited to 'src/Model')
| -rw-r--r-- | src/Model/Game.cpp | 12 | ||||
| -rw-r--r-- | src/Model/Game.hpp | 5 | ||||
| -rw-r--r-- | src/Model/Grid.hpp | 38 |
3 files changed, 35 insertions, 20 deletions
diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index d75fa32..284d82b 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -1,15 +1,19 @@ #include "Game.hpp" +//==================== Constructor and Destructor ==================== +//Constructor Game::Game() : m_grid(), m_score(0), m_nbMove(0){ } +//Destructor Game::~Game(){ } +//==================== Helpers ==================== - +//Swipe action bool Game::swipe(kbdh::Direction direction){ bool moveDone; @@ -40,14 +44,17 @@ bool Game::swipe(kbdh::Direction direction){ } +//Cout the grid void Game::coutGrid(){ std::cout << m_grid.description(); } +//Return true if the game is lost. False else. 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()); @@ -65,11 +72,14 @@ void Game::popRandomNumber(){ m_grid.setCell(coord, number); } +//==================== Getters and Setter ==================== +//Retrieve the Score int Game::getScore(){ return m_score; } +//Retrieve the number of moves int Game::getNbMove(){ return m_nbMove; } diff --git a/src/Model/Game.hpp b/src/Model/Game.hpp index bb8b995..0b2ee4d 100644 --- a/src/Model/Game.hpp +++ b/src/Model/Game.hpp @@ -16,18 +16,23 @@ class Game { private: + //Members Grid m_grid; int m_score; int m_nbMove; + public: + //Constructor and Destructor Game(); ~Game(); + //Helpers bool swipe(kbdh::Direction direction); void coutGrid(); void popRandomNumber(); bool isOver(); + //Getters and Setters int getScore(); int getNbMove(); }; diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index 4ed5c10..51168a9 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -15,45 +15,45 @@ class Grid { private: + //Members int m_size; std::vector<std::vector<int> > m_grid; - int m_lastMoveScore; + //Private methods int maxStrLenInGrid(); public: + //Constructor and Destructor Grid(); ~Grid(); - std::string description(); - bool isEmpty(int i, int j); - std::tuple<int, int> getRandomEmptyCellCoord(); - - bool setCell(std::tuple<int, int> coord, int value); - bool setCell(int i, int j, int value); - - std::vector<int> swipeLine(std::vector<int> line); + //Defragment and merge methods std::vector<int> rightDefragment(std::vector<int> line); std::vector<int> leftDefragment(std::vector<int> line); std::vector<int> rightMerge(std::vector<int> line); std::vector<int> leftMerge(std::vector<int> line); - std::vector<int> getCol(int col); - - bool isFull(); - bool isOver(); - - void setCol(int col, std::vector<int> colVect); - std::vector<int> reverseLine(std::vector<int> line); - bool compareLines(std::vector<int> line1, std::vector<int> line2); - - //Moves + //Swipe methods bool swipeRight(); bool swipeLeft(); bool swipeUp(); bool swipeDown(); + //Helpers + bool isFull(); + bool isOver(); + bool isEmpty(int i, int j); + std::tuple<int, int> getRandomEmptyCellCoord(); + bool compareLines(std::vector<int> line1, std::vector<int> line2); + std::vector<int> reverseLine(std::vector<int> line); + std::string description(); + + //Getters and Setters + bool setCell(std::tuple<int, int> coord, int value); + bool setCell(int i, int j, int value); + std::vector<int> getCol(int col); + void setCol(int col, std::vector<int> colVect); int getLastMoveScore(); }; |
