-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSurfaceGame.h
176 lines (139 loc) · 5.55 KB
/
SurfaceGame.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
/*
* QtSssSNibblers: SwissalpS Nibbles written with Qt-Framework
* Copyright (C) 2018-2019 Luke J. Zimmermann aka SwissalpS <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SURFACEGAME_H
#define SURFACEGAME_H
#include <QFrame>
#include <QKeyEvent>
#include <QTimer>
#include "AppSettings.h"
#include "DialogLoad.h"
#include "FrameStartCountdown.h"
#include "Map.h"
#include "MapGame.h"
#include "ScoreBoard.h"
#include "SurfaceCell.h"
#include "Worm.h"
namespace Ui {
class SurfaceGame;
} // namespace Ui
namespace SwissalpS { namespace QtNibblers {
class SurfaceGame : public QFrame {
Q_OBJECT
private:
Ui::SurfaceGame *pUi;
QTimer *pTimerResize;
quint8 ubResizeCount;
private slots:
void on_buttonPP_toggled(bool bChecked);
void on_buttonSR_clicked();
protected:
bool bLevelDone;
bool bLevelLoading;
bool bProtectPP;
QList<QList<SurfaceCell *> > aopRows;
QVector<ScoreBoard *> apScoreBoards;
QVector<Worm *> apWorms;
QVector<QHash<QKeySequence, L::Heading>> ahKeys;
AppSettings *pAS;
DialogLoad *pDialogLoad;
FrameStartCountdown *pStartCountDownFrame;
qint8 ibWormMouse;
quint8 ubCurrentLevel;
mutable int iLastHeight;
void changeEvent(QEvent *pEvent) override;
virtual void clearSurface();
virtual void clearSurfaceOf(const quint8 ubState);
virtual void clearSurfaceOf(const QVector<quint8>aStates);
virtual void clearSurfaceOfWorm(const quint8 ubWormColourIndex);
virtual void clearSurfaceOfWorms();
virtual Map *currentMap();
virtual void focusInEvent(QFocusEvent *pEvent) override;
virtual void focusOutEvent(QFocusEvent *pEvent) override;
virtual SurfaceCell* getCell(const QPoint oPoint);
virtual SurfaceCell* getCell(const quint8 ubColumn, const quint8 ubRow);
virtual void keyPressEvent(QKeyEvent *pEvent) override;
virtual void mousePressEvent(QMouseEvent *pEvent) override;
virtual void pauseIfRunning();
virtual void resetButtons();
virtual void resizeEvent(QResizeEvent *pEvent) override;
virtual void setCellState(const QPoint oPoint, const quint8 ubState,
const bool bUpdate = true);
virtual void setCellState(SurfaceCell *pCell, const quint8 ubState,
const bool bUpdate = true);
virtual void setCellState(const quint8 ubColumn, const quint8 ubRow,
const quint8 ubState, const bool bUpdate = true);
virtual void showStartCountDownFrame(const QString sMessage, const QString sButton = QString());
virtual void updateFrameStartCountdown();
protected slots:
virtual void countdownTick();
virtual void dialogLoadFinished(const int iResult);
virtual void initKeys();
virtual void initCells();
inline virtual void onSCDFdone() { this->on_buttonPP_toggled(true); }
virtual void resizeDelayDone();
public:
explicit SurfaceGame(QWidget *pParent = nullptr);
~SurfaceGame() override;
virtual void init();
virtual QSize sizeHint() const override;
signals:
void bonusPlaced(QVector<SurfaceCell *> apCells, const bool bFake) const;
void debugMessage(const QString &sMessage) const;
void levelIsLoaded() const;
void nextLevel() const;
void pauseResumeToggled() const;
void resetGame(const bool bInvalidateWorms) const;
void startNewGame(const quint8 ubLevel) const;
void statusMessage(const QString &sMessage) const;
void tileChanged(const QPoint oPoint, const quint8 ubState) const;
void trailChanged(const int iValue) const;
void turnWorm(const quint8 ubWorm, const L::Heading eDirection) const;
public slots:
virtual void onAdvanceWormTo(Worm *pWorm, const QPoint oPoint);
virtual void onBonusPlaced(const QVector<QPoint> aoPoints,
const quint8 ubBonus, const bool bFake);
inline void onDebugMessage(const QString &sMessage) const {
Q_EMIT this->debugMessage("SG:" + sMessage); }
inline void onCellChanged(const QPoint oPoint, const quint8 ubState) const {
if (!this->bLevelLoading) Q_EMIT this->tileChanged(oPoint, ubState); }
virtual void onColoursChanged(const QVector<quint8> aubColours);
virtual void onDoGameOver(const QString &sRanking);
virtual void onDoLevelDone();
virtual void onDoLevelIsMissingSpawnPoints(const quint8 ubMissing);
virtual void onDoLevelLoadError();
virtual void onDoLevelStartCountdown();
virtual void onLoadLevel(MapGame *pMap, const quint8 ubLevel);
virtual void onMainTabChanged(const int iIndex);
virtual void onMouseLeft();
virtual void onMouseRight();
virtual void onPlayerKeyChanged(const quint8 ubWorm,
const QKeySequence &oKeySequence,
const L::Heading eHeading);
virtual void onPlayerRelativeChanged(const quint8 ubWorm, const bool bRelative);
inline virtual void onPlayerUseMouseChanged() { this->initKeys(); }
virtual void onQuitting();
virtual void onSpawnWorm(Worm *pWorm);
inline virtual void onTrailChanged(const int iValue) {
Q_EMIT this->trailChanged(iValue); }
virtual void onWormAteBonus(Worm *pWorm);
virtual void onWormCrashed(Worm *pWorm);
virtual void onWormCreated(Worm *pWorm);
virtual void onWormsInvalidated();
}; // SurfaceGame
} } // namespace SwissalpS::QtNibblers
#endif // SURFACEGAME_H