diff options
Diffstat (limited to 'src/Model/Game.cpp')
| -rw-r--r-- | src/Model/Game.cpp | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp index 6039bc9..284d82b 100644 --- a/src/Model/Game.cpp +++ b/src/Model/Game.cpp @@ -1,49 +1,85 @@ #include "Game.hpp" +//==================== Constructor and Destructor ==================== -Game::Game() : m_grid(){ +//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; + switch(direction){ case kbdh::Left: - m_grid.swipeLeft(); + moveDone=m_grid.swipeLeft(); break; case kbdh::Right: - m_grid.swipeRight(); + moveDone=m_grid.swipeRight(); break; case kbdh::Up: - m_grid.swipeUp(); + moveDone=m_grid.swipeUp(); break; case kbdh::Down: - m_grid.swipeDown(); + moveDone=m_grid.swipeDown(); break; } - return true; + if(moveDone){ + m_score+=m_grid.getLastMoveScore(); + m_nbMove++; + this->popRandomNumber(); + } + + return moveDone; } +//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()); - int number=2; + int percent=rand() % 100; + + int number; + + if(percent <= 10){ + number=4; + } + else{ + number=2; + } + 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; +} |
