summaryrefslogtreecommitdiff
path: root/src/Model/Game.cpp
blob: c2252ff69f79c412de4cf4c83e3bc2f90b1ba500 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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<StringElement>("2"));
}

bool Game::isOver()
{
	return m_grid->gridIsFull();
}