-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathboardmodel.h
42 lines (30 loc) · 899 Bytes
/
boardmodel.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
#ifndef BOARDMODEL_H
#define BOARDMODEL_H
#include <QAbstractListModel>
#include "board.h"
class BoardModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int score READ score NOTIFY scoreChanged)
Q_PROPERTY(bool gameEnded READ gameEnded NOTIFY gameStatusChanged)
Q_PROPERTY(bool win READ win NOTIFY gameStatusChanged)
public:
explicit BoardModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
Q_INVOKABLE void moveUp();
Q_INVOKABLE void moveRight();
Q_INVOKABLE void moveDown();
Q_INVOKABLE void moveLeft();
int score() const;
bool gameEnded();
bool win();
signals:
void scoreChanged();
void gameStatusChanged();
public slots:
void onDataChanged();
private:
Board board_;
};
#endif // BOARDMODEL_H