forked from smay1613/15-puzzleQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameboard.h
51 lines (37 loc) · 1.25 KB
/
gameboard.h
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
#pragma once
#include <vector>
#include <QAbstractListModel>
class GameBoard : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int hiddenElementValue READ hiddenElementValue CONSTANT)
Q_PROPERTY(int dimension READ dimension CONSTANT)
public:
static constexpr size_t DEFAULT_DIMENSION {4};
GameBoard(QObject *parent = nullptr, size_t board_dimension = DEFAULT_DIMENSION);
struct Tile {
size_t value {};
Tile& operator= (const size_t new_value){
value = new_value;
return *this;
}
bool operator==(const size_t other) {
return other == value;
}
};
void shuffle();
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
size_t dimension() const;
size_t hiddenElementValue() const;
Q_INVOKABLE bool move (int index);
using Position = std::pair<size_t, size_t>;
private:
std::vector<Tile> m_raw_board;
const size_t m_dimension;
const size_t m_boardsize;
const size_t m_hiddenElementValue;
bool isBoardValid() const;
bool isPositionValid(const size_t position) const;
Position getRowCol(size_t index) const;
};