-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMap.cpp
137 lines (85 loc) · 3.09 KB
/
Map.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* 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 "Map.h"
#include <QPainter>
#include <QPixmap>
namespace SwissalpS { namespace QtNibblers {
Map::Map(QObject *pParent) :
QObject(pParent),
ubTotalColumns(0),
ubTotalRows(0) {
this->aaubRows.clear();
} // construct
Map::Map(const quint8 ubColumns, const quint8 ubRows, QObject *pParent) :
QObject(pParent),
ubTotalColumns(ubColumns),
ubTotalRows(ubRows) {
this->fillAll();
} // construct
Map::~Map() {
this->aaubRows.clear();
} // dealloc
void Map::fillAll(const quint8 ubState) {
QVector<quint8>aubRow;
aubRow.fill(ubState, this->ubTotalColumns);
this->aaubRows.clear();
this->aaubRows.fill(aubRow, this->ubTotalRows);
} // fillAll
QPixmap Map::pixmap(const bool bSimple) const {
Q_UNUSED(bSimple)
// prepare vector of states we react to
quint8 ubState;
QVector<quint8> aCOIs;
for (ubState = L::WallVertical; ubState < 211u; ubState++) aCOIs.append(ubState);
//if (!bSimple) aCOIs += some more
QPixmap oPixmap(this->ubTotalColumns, this->ubTotalRows);
QPainter oP(&oPixmap);
oP.setBackground(Qt::black);
oP.fillRect(oPixmap.rect(), Qt::black);
oP.setPen(Qt::white);
quint8 ubColumns = 0u;
quint8 ubRows = 0u;
for (; ubRows < this->ubTotalRows; ++ubRows) {
for (ubColumns = 0u; ubColumns < this->ubTotalColumns; ++ubColumns) {
ubState = this->aaubRows.at(ubRows).at(ubColumns);
if (aCOIs.contains(ubState)) oP.drawPoint(ubColumns, ubRows);
} // loop columns
} // loop rows
return oPixmap;
} // pixmap
void Map::setTile(const quint8 ubColumn, const quint8 ubRow, quint8 ubState) {
// check limits
int iTotalRows = this->aaubRows.length();
if (0 == iTotalRows) return;
if (ubRow >= iTotalRows) return;
int iTotalColumns = this->aaubRows.first().length();
if (0 == iTotalColumns) return;
if (ubColumn >= iTotalColumns) return;
this->aaubRows[ubRow][ubColumn] = ubState;
} // setTile
quint8 Map::tile(const quint8 ubColumn, const quint8 ubRow) const {
// check limits
int iTotalRows = this->aaubRows.length();
if (0 == iTotalRows) return L::NullTile;
if (ubRow >= iTotalRows) return L::NullTile;
int iTotalColumns = this->aaubRows.first().length();
if (0 == iTotalColumns) return L::NullTile;
if (ubColumn >= iTotalColumns) return L::NullTile;
return this->aaubRows.at(ubRow).at(ubColumn);
} // tile
} } // namespace SwissalpS::QtNibblers