-
Notifications
You must be signed in to change notification settings - Fork 1
/
gamescene.h
179 lines (127 loc) · 4.02 KB
/
gamescene.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef GAMESCENE_H
#define GAMESCENE_H
#include <QDebug>
#include <QGraphicsScene>
#include <QGLWidget>
#include <QDesktopWidget>
#include <QSet>
#include <QTime>
#include <QCloseEvent>
#include <QDir>
#include "defines.h"
#include "gameitem.h"
#include "scene_if.h"
class BaseItem;
class MenuWidget;
class ConfirmDialog;
class GameTool;
class ToolSet;
class GameBonus;
class GameScene : public QGraphicsScene, virtual public IScene
{
Q_OBJECT
friend class GameWidget;
public:
enum MoveState { MS_IDLE, MS_SELECTED, MS_MOVING, MS_RETURN };
GameScene(QWidget *parent);
virtual ~GameScene();
void initGame();
bool initLevel(int level);
void initTheme();
inline const QPoint cursorPosition() const { return cursorPos.toPoint(); }
inline MenuWidget* gameMenu() const { return menu; }
// internals
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void keyPressEvent (QKeyEvent *keyEvent );
// timers
void disableTimersButAdvance();
void disableTimers();
void enableTimers();
void wait(int ms);
bool confirmExit();
public slots:
void pauseGame();
void continueGame();
void stopGame();
protected slots:
void nextCycle();
void checkMouseActions();
void executeMovement();
bool checkItemMovement();
void hintAvailableMoves();
void countTime();
void countBonusTime();
void bonusTimeLeft();
void levelWon();
void levelFailed();
void initProfile();
void initGraphics();
void on_menuNew();
void on_menuContinue();
void on_menuExit();
void on_menuPauseBack();
void on_menuRestartLevel();
void on_menuAbandonGame();
void on_menuThemeChanged();
void on_menuGameStart();
void on_menuLevelPack();
protected:
virtual void drawBackground(QPainter *painter, const QRectF &);
void updateCounters(QPainter &p);
void drawHint(QPainter &p);
void drawLevelStartup(QPainter &p);
void drawHUDonBackground();
void drawConcretesOnBackground();
enum STAT_CODE { STAT_LEVEL_WON, STAT_LEVEL_FAIL, STAT_GAME_WON };
void showStatictics(STAT_CODE code);
void drawStatInfo(QPainter &p);
void checkStatMouseActions(const QPoint &pos);
bool loadLevel(int index);
bool loadScene(const QByteArray &ba);
void selectActiveItems(int items);
bool fillEmptyFreeRows();
GameItem* generateGameItem(const QSet<int> &skip = QSet<int>());
void refillItems(int deep);
bool checkAvailableMoves();
bool checkAvailItemsInRow(struct PlaceAvailInfo *pl, int row, int from, int to);
bool checkAvailItemsInColumn(struct PlaceAvailInfo *pl, int col, int from, int to);
bool checkRemoveItems();
bool checkRemoveItemsInRow(int row, int from, int to, bool remove=true);
bool checkRemoveItemsInColumn(int col, int from, int to, bool remove=true);
void removeItemsColumn(int row, int col, int cnt);
void removeItemsRow(int row, int col, int cnt);
void removeScheduledItems();
bool checkFallItems();
void scheduleItemMove(int row1, int col1, int row2, int col2);
void unsetCurrentItem();
void advanceAndWait(int cycles);
void advanceTempItems();
void runNextLevel();
void exitToMainMenu();
void disableInput() { inputDisabled = true; }
void enableInput() { inputDisabled = false; }
QString getSchemePath() const;
void loadRandomBackground();
volatile bool myLock;
volatile bool paintState;
volatile bool inputDisabled;
GameItem *currentItem;
int currentRow, currentCol;
int targetRow, targetCol;
QPointF lastClickPos, cursorPos;
MoveState moveState;
QPoint availFrom, availTo;
bool hintMove;
qreal hintOpacity, hintDelta;
QTimer *advanceTimer, *timeTimer, *bonusTimer, *hintTimer;
int frameCount;
MenuWidget *menu;
ConfirmDialog *dconfirm;
struct StatInfo *stat;
bool stat_active;
bool level_start;
int ls_x, ls_y;
};
//#define DATA(r,c) data[(r)*cols+(c)]
#endif // GAMESCENE_H