blob: 305499089218c4cddb2f3f5f7906946711aa174a (
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
|
#include "Game.hpp"
Game::Game()
{
m_grid = new Grid(4);
}
Game::~Game()
{
delete m_grid;
}
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()
{
if(m_grid->gridIsFull()){
for(int i=0;i<4;i++){
std::cout << m_grid->getCell(0,i)->description();
}
}
return true;
}
|