-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTilesGame.cpp
48 lines (43 loc) · 1.03 KB
/
TilesGame.cpp
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
#include "TilesGame.h"
#include <QVector>
#include "tile.h"
#include <QDebug>
TilesGame::TilesGame(int gameBoardSize)
{
this->gameBoardSize = gameBoardSize;
this->tiles = new QVector<Tile*>();
int value = 0;
for(int y = this->gameBoardSize; y > 0 ; y--){
for(int x = this->gameBoardSize; x > 0; x--){
value = y*this->gameBoardSize-(this->gameBoardSize-x);
tiles->prepend(new Tile(x-1,y-1, value, false));
}
}
}
void TilesGame::move(Tile* tile)
{
if(moveTile(tile)){
emit gameBoardChanged(tiles);
}
if(gameEnded()){
emit winner();
}
}
void TilesGame::start()
{
emit gameBoardChanged(this->tiles);
}
TilesGame::~TilesGame()
{
delete tiles;
}
Tile *TilesGame::findTile(int x, int y)
{
Tile* element;
for(int i = 0; i < this->tiles->size(); i++){
element = this->tiles->at(i);
if(element->getX() == x && element->getY() == y)
return element;
}
return NULL;
}