summaryrefslogtreecommitdiff
path: root/src/Model/Game.cpp
diff options
context:
space:
mode:
authorkrilius <ulrich.lejoyeux@gmail.com>2015-04-29 22:28:29 +0400
committerkrilius <ulrich.lejoyeux@gmail.com>2015-04-29 22:28:29 +0400
commita3b805ee7b96d1d693c4108f0104650cfd60b565 (patch)
tree0fe6451222c135e0cadcc3011829a4f8ef02dc6d /src/Model/Game.cpp
parente241abc9df586cce683d6ae89e1d02c13084a10f (diff)
first step of the model
Diffstat (limited to 'src/Model/Game.cpp')
-rw-r--r--src/Model/Game.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Model/Game.cpp b/src/Model/Game.cpp
index e69de29..1e24b11 100644
--- a/src/Model/Game.cpp
+++ b/src/Model/Game.cpp
@@ -0,0 +1,54 @@
+#include "Game.hpp"
+
+Game::Game()
+{
+ m_grid = new Grid(4);
+}
+
+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()
+{
+ m_grid->show();
+ std::cout << std::endl;
+}
+
+void Game::pop()
+{
+ bool cellChosen = false;
+
+ int i;
+ int j;
+
+ while(!cellChosen)
+ {
+ i = rand() % 4;
+ j = rand() % 4;
+
+ if (m_grid->isEmpty(i,j))
+ cellChosen = true;
+ }
+
+ m_grid->setCell(i, j, new Cell("2"));
+}
+
+bool Game::isOver()
+{
+ return m_grid->gridIsFull();
+} \ No newline at end of file