-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameController.h
56 lines (44 loc) · 1.31 KB
/
GameController.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 INC_2048_GAMECONTROLLER_H
#define INC_2048_GAMECONTROLLER_H
#include <QAbstractListModel>
#include <QObject>
#include <qqml.h>
#include "2048.h"
#include "BoardModel.h"
class GameController: public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(quint32 score READ getScore NOTIFY scoreChanged)
Q_PROPERTY(BoardModel* board READ getBoard CONSTANT)
Q_PROPERTY(bool inGame READ isInGame WRITE setInGame NOTIFY inGameChanged)
Q_PROPERTY(quint8 gameSize READ getGameSize WRITE setGameSize NOTIFY gameSizeChanged)
public:
static const int MAX_GAME_SIZE = 8;
static const int MIN_GAME_SIZE = 2;
enum class Direction {
up, down, right, left
};
Q_ENUM(Direction)
explicit GameController(QObject* parent = nullptr);
quint32 getScore() const;
BoardModel* getBoard();
bool isInGame() const;
void setInGame(bool);
quint8 getGameSize() const;
void setGameSize(quint8);
Q_INVOKABLE void move(GameController::Direction towards);
Q_INVOKABLE void reset();
Q_INVOKABLE bool canMove();
Q_INVOKABLE void deleteTileAt(quint8 index);
static game2048::Direction directionToGameDirection(GameController::Direction);
signals:
void scoreChanged();
void inGameChanged();
void gameSizeChanged();
private:
BoardModel board;
game2048::Game game{4};
bool inGame = true;
};
#endif //INC_2048_GAMECONTROLLER_H