-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bonus.cpp
120 lines (74 loc) · 2.65 KB
/
Bonus.cpp
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
/*
* 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/>.
*/
#include "Bonus.h"
#include <QTimer>
namespace SwissalpS { namespace QtNibblers {
Bonus::Bonus(QVector<SurfaceCell *> apCells, const bool bFake, QObject *pParent) :
QObject(pParent),
bExpired(false),
bFake(bFake),
ubStateBase(0xFCu),
uiTicks(0u),
apCells(apCells) {
if (apCells.length()) this->setStateBase(apCells.first()->getState());
} // construct
Bonus::~Bonus() {
this->disconnect();
this->apCells.clear();
this->bExpired = true;
this->ubStateBase = 0xFCu;
this->uiTicks = 0u;
} // dealloc
bool Bonus::contains(const QPoint oPoint) const {
for (int i = 0; i < this->apCells.length(); ++i) {
if (oPoint == this->apCells.at(i)->getPos()) return true;
} // loop
return false;
} // contains(QPoint)
void Bonus::defreezeCells() {
this->bExpired = true;
this->uiTicks = 0u;
if (4 != this->apCells.length()) {
this->onDebugMessage("Error with cell count in Bonus::defreezeCells");
return;
} // if length insufficient
// I've checked these, they are not the cause for bonus not leaveing
SurfaceCell *pCell = this->apCells.first();
if (pCell->getState() == this->ubStateBase) pCell->defrostState();
pCell = this->apCells.at(1);
if (pCell->getState() == this->ubStateBase + 1u) pCell->defrostState();
pCell = this->apCells.at(2);
if (pCell->getState() == this->ubStateBase + 2u) pCell->defrostState();
pCell = this->apCells.last();
if (pCell->getState() == this->ubStateBase + 3u) pCell->defrostState();
} // defreezeCells
void Bonus::setStateBase(const quint8 &ubState) {
this->ubStateBase = ubState;
} // setStateBase
void Bonus::onGotEaten() {
this->defreezeCells();
Q_EMIT this->gotEaten();
} // onGotEaten
void Bonus::onTick() {
if (this->hasTimedOut()) return;
this->uiTicks--;
if (!this->hasTimedOut()) return;
this->defreezeCells();
Q_EMIT this->timedOut(this);
} // onTick
} } // namespace SwissalpS::QtNibblers