summaryrefslogtreecommitdiff
path: root/src/Model/Game.cpp
blob: 1e24b11a4776ec54c1cb0b9e14dc6f2c8b4bf62f (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("2"));
}

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