-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamemodel.h
56 lines (41 loc) · 1.1 KB
/
gamemodel.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
52
53
54
55
56
#ifndef GAMEMODEL_H
#define GAMEMODEL_H
#include <QAbstractListModel>
#include <QModelIndex>
#include <QVariant>
#include <cstdlib>
#include "gametile.h"
class GameModel : public QAbstractListModel
{
Q_OBJECT
public:
enum GameRoles {
ValueRole = Qt::UserRole + 1,
XRole,
YRole
};
enum MoveDirection {
Up,
Right,
Down,
Left
};
explicit GameModel(QObject *parent = 0);
QHash<int,QByteArray> roleNames() const;
int rowCount (const QModelIndex &parent) const;
QVariant data (const QModelIndex &index, int role) const;
/** INTERNAL DATA MANAGEMENT METHODS **/
void swap (int index1, int index2);
void merge (int from, int to);
/** QML INVOKABLE METHODS **/
Q_INVOKABLE void createNew();
Q_INVOKABLE void generate();
Q_INVOKABLE bool doesTileExist (int value);
Q_INVOKABLE void makeMove (MoveDirection dir);
Q_INVOKABLE int indexAtCoord (int x, int y);
Q_INVOKABLE QVariant getTileAtCoord (int x, int y);
signals:
void addScore (int score);
public slots:
};
#endif // GAMEMODEL_H