author | simon <simon> | 2002-04-30 14:37:40 (UTC) |
---|---|---|
committer | simon <simon> | 2002-04-30 14:37:40 (UTC) |
commit | c63b1853bb26bcd5ae21b73eb21d858a56534914 (patch) (unidiff) | |
tree | 9a0e5351252a80292cf5af0131487ac1742a335d | |
parent | 85b6723c707949f5689bfca6f442d9cbb73f2ee9 (diff) | |
download | opie-c63b1853bb26bcd5ae21b73eb21d858a56534914.zip opie-c63b1853bb26bcd5ae21b73eb21d858a56534914.tar.gz opie-c63b1853bb26bcd5ae21b73eb21d858a56534914.tar.bz2 |
- no default args in method impls
- resolved parameter shadowing
-rw-r--r-- | noncore/games/mindbreaker/mindbreaker.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp index b0e4d88..1a1d05d 100644 --- a/noncore/games/mindbreaker/mindbreaker.cpp +++ b/noncore/games/mindbreaker/mindbreaker.cpp | |||
@@ -1,447 +1,447 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "mindbreaker.h" | 21 | #include "mindbreaker.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | 25 | ||
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qpixmap.h> | 27 | #include <qpixmap.h> |
28 | #include <qpe/qpetoolbar.h> | 28 | #include <qpe/qpetoolbar.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qstyle.h> | 33 | #include <qstyle.h> |
34 | 34 | ||
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | #include <sys/time.h> | 36 | #include <sys/time.h> |
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | 38 | ||
39 | static int pegRTTI = 3393393; | 39 | static int pegRTTI = 3393393; |
40 | 40 | ||
41 | /* helper class, */ | 41 | /* helper class, */ |
42 | class Peg : public QCanvasRectangle | 42 | class Peg : public QCanvasRectangle |
43 | { | 43 | { |
44 | public: | 44 | public: |
45 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); | 45 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); |
46 | int rtti() const {return pegRTTI; } | 46 | int rtti() const {return pegRTTI; } |
47 | void advance(int phase); | 47 | void advance(int phase); |
48 | 48 | ||
49 | bool hit( const QPoint &) const; | 49 | bool hit( const QPoint &) const; |
50 | 50 | ||
51 | /* a placed peg is one that has been set down on the board correctly and | 51 | /* a placed peg is one that has been set down on the board correctly and |
52 | should not be moved, only copied */ | 52 | should not be moved, only copied */ |
53 | bool placed() const; | 53 | bool placed() const; |
54 | void setPlaced(bool); | 54 | void setPlaced(bool); |
55 | 55 | ||
56 | int pegGo() const; | 56 | int pegGo() const; |
57 | int pegPos() const; | 57 | int pegPos() const; |
58 | void setPegPos(int); | 58 | void setPegPos(int); |
59 | 59 | ||
60 | int type() const; | 60 | int type() const; |
61 | 61 | ||
62 | static void buildImages(); | 62 | static void buildImages(); |
63 | static QImage imageForType(int t); | 63 | static QImage imageForType(int t); |
64 | 64 | ||
65 | static int eggLevel; | 65 | static int eggLevel; |
66 | 66 | ||
67 | protected: | 67 | protected: |
68 | void drawShape(QPainter &); | 68 | void drawShape(QPainter &); |
69 | private: | 69 | private: |
70 | static QVector<QImage> normalPegs; | 70 | static QVector<QImage> normalPegs; |
71 | static QVector<QImage> specialPegs; | 71 | static QVector<QImage> specialPegs; |
72 | 72 | ||
73 | bool isplaced; | 73 | bool isplaced; |
74 | int pegtype; | 74 | int pegtype; |
75 | int peg_go; | 75 | int peg_go; |
76 | int peg_pos; | 76 | int peg_pos; |
77 | 77 | ||
78 | int aniStep; | 78 | int aniStep; |
79 | }; | 79 | }; |
80 | 80 | ||
81 | int Peg::eggLevel = 0; | 81 | int Peg::eggLevel = 0; |
82 | QVector<QImage> Peg::normalPegs; | 82 | QVector<QImage> Peg::normalPegs; |
83 | QVector<QImage> Peg::specialPegs; | 83 | QVector<QImage> Peg::specialPegs; |
84 | 84 | ||
85 | void Peg::buildImages() | 85 | void Peg::buildImages() |
86 | { | 86 | { |
87 | 87 | ||
88 | QImage pegs = Resource::loadImage("mindbreaker/pegs"); | 88 | QImage pegs = Resource::loadImage("mindbreaker/pegs"); |
89 | int x = 0; | 89 | int x = 0; |
90 | int y = 0; | 90 | int y = 0; |
91 | int i; | 91 | int i; |
92 | eggLevel = 0; | 92 | eggLevel = 0; |
93 | normalPegs.resize(10); | 93 | normalPegs.resize(10); |
94 | for (i = 0; i < 6; i++) { | 94 | for (i = 0; i < 6; i++) { |
95 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size))); | 95 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size))); |
96 | x += peg_size; | 96 | x += peg_size; |
97 | } | 97 | } |
98 | specialPegs.resize(5); | 98 | specialPegs.resize(5); |
99 | for (i = 0; i < 5; i++) { | 99 | for (i = 0; i < 5; i++) { |
100 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size))); | 100 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size))); |
101 | x += peg_size; | 101 | x += peg_size; |
102 | } | 102 | } |
103 | 103 | ||
104 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 104 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); |
105 | /* copy from master image to functional images */ | 105 | /* copy from master image to functional images */ |
106 | x = 0; | 106 | x = 0; |
107 | y = panel_height; | 107 | y = panel_height; |
108 | normalPegs.insert(8, | 108 | normalPegs.insert(8, |
109 | new QImage(image.copy(x, y, panel_width, panel_height))); | 109 | new QImage(image.copy(x, y, panel_width, panel_height))); |
110 | y += panel_height; | 110 | y += panel_height; |
111 | y += title_height; | 111 | y += title_height; |
112 | normalPegs.insert(9, | 112 | normalPegs.insert(9, |
113 | new QImage(image.copy(x, y, title_width, title_height))); | 113 | new QImage(image.copy(x, y, title_width, title_height))); |
114 | y += title_height; | 114 | y += title_height; |
115 | 115 | ||
116 | x = 6 * peg_size; | 116 | x = 6 * peg_size; |
117 | normalPegs.insert(6, | 117 | normalPegs.insert(6, |
118 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); | 118 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); |
119 | x += answerpeg_size; | 119 | x += answerpeg_size; |
120 | normalPegs.insert(7, | 120 | normalPegs.insert(7, |
121 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); | 121 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); |
122 | } | 122 | } |
123 | 123 | ||
124 | QImage Peg::imageForType(int t) | 124 | QImage Peg::imageForType(int t) |
125 | { | 125 | { |
126 | if (eggLevel > t ) { | 126 | if (eggLevel > t ) { |
127 | if( t < 5) { | 127 | if( t < 5) { |
128 | return *specialPegs[t]; | 128 | return *specialPegs[t]; |
129 | } else { | 129 | } else { |
130 | return *normalPegs[rand() % 6]; | 130 | return *normalPegs[rand() % 6]; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | return *normalPegs[t]; | 133 | return *normalPegs[t]; |
134 | } | 134 | } |
135 | 135 | ||
136 | Peg::Peg(QCanvas *canvas , int t, int g = -1, int p = -1) | 136 | Peg::Peg(QCanvas *canvas , int t, int g, int p) |
137 | : QCanvasRectangle(canvas) | 137 | : QCanvasRectangle(canvas) |
138 | { | 138 | { |
139 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); | 139 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); |
140 | pegtype = t; | 140 | pegtype = t; |
141 | isplaced = FALSE; | 141 | isplaced = FALSE; |
142 | peg_pos = p; | 142 | peg_pos = p; |
143 | peg_go = g; | 143 | peg_go = g; |
144 | aniStep = rand() % 6; | 144 | aniStep = rand() % 6; |
145 | setAnimated(TRUE); | 145 | setAnimated(TRUE); |
146 | } | 146 | } |
147 | 147 | ||
148 | void Peg::advance(int phase) { | 148 | void Peg::advance(int phase) { |
149 | if (phase == 0) | 149 | if (phase == 0) |
150 | aniStep = (++aniStep) % 6; | 150 | aniStep = (++aniStep) % 6; |
151 | else { | 151 | else { |
152 | hide(); | 152 | hide(); |
153 | show(); | 153 | show(); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | void Peg::drawShape(QPainter &p ) | 157 | void Peg::drawShape(QPainter &p ) |
158 | { | 158 | { |
159 | if ((pegtype == 5) && eggLevel > 5) { | 159 | if ((pegtype == 5) && eggLevel > 5) { |
160 | p.drawImage(x(), y(), *normalPegs[aniStep]); | 160 | p.drawImage(x(), y(), *normalPegs[aniStep]); |
161 | } else | 161 | } else |
162 | p.drawImage(x(), y(), imageForType(pegtype)); | 162 | p.drawImage(x(), y(), imageForType(pegtype)); |
163 | } | 163 | } |
164 | 164 | ||
165 | bool Peg::hit( const QPoint &p ) const | 165 | bool Peg::hit( const QPoint &p ) const |
166 | { | 166 | { |
167 | int ix = p.x() - int(x()); | 167 | int ix = p.x() - int(x()); |
168 | int iy = p.y() - int(y()); | 168 | int iy = p.y() - int(y()); |
169 | if (!normalPegs[pegtype]->valid(ix, iy)) | 169 | if (!normalPegs[pegtype]->valid(ix, iy)) |
170 | return FALSE; | 170 | return FALSE; |
171 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); | 171 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); |
172 | return (qAlpha(pixel ) != 0); | 172 | return (qAlpha(pixel ) != 0); |
173 | } | 173 | } |
174 | 174 | ||
175 | inline bool Peg::placed() const | 175 | inline bool Peg::placed() const |
176 | { | 176 | { |
177 | return isplaced; | 177 | return isplaced; |
178 | } | 178 | } |
179 | 179 | ||
180 | inline int Peg::pegGo() const | 180 | inline int Peg::pegGo() const |
181 | { | 181 | { |
182 | return peg_go; | 182 | return peg_go; |
183 | } | 183 | } |
184 | 184 | ||
185 | inline int Peg::pegPos() const | 185 | inline int Peg::pegPos() const |
186 | { | 186 | { |
187 | return peg_pos; | 187 | return peg_pos; |
188 | } | 188 | } |
189 | 189 | ||
190 | inline void Peg::setPegPos(int p) | 190 | inline void Peg::setPegPos(int p) |
191 | { | 191 | { |
192 | peg_pos = p; | 192 | peg_pos = p; |
193 | } | 193 | } |
194 | 194 | ||
195 | inline void Peg::setPlaced(bool p) | 195 | inline void Peg::setPlaced(bool p) |
196 | { | 196 | { |
197 | isplaced = p; | 197 | isplaced = p; |
198 | } | 198 | } |
199 | 199 | ||
200 | inline int Peg::type() const | 200 | inline int Peg::type() const |
201 | { | 201 | { |
202 | return pegtype; | 202 | return pegtype; |
203 | } | 203 | } |
204 | 204 | ||
205 | /* Load the main image, copy from it the pegs, the board, and the answer image | 205 | /* Load the main image, copy from it the pegs, the board, and the answer image |
206 | * and use these to create the tray, answer and board | 206 | * and use these to create the tray, answer and board |
207 | */ | 207 | */ |
208 | MindBreaker::MindBreaker( QWidget *parent=0, const char *name=0, int wFlags=0 ) | 208 | MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) |
209 | : QMainWindow(parent, name, wFlags), | 209 | : QMainWindow(parent, name, wFlags), |
210 | canvas(board_height, board_width) | 210 | canvas(board_height, board_width) |
211 | { | 211 | { |
212 | MindBreakerBoard *m = new MindBreakerBoard(canvas, this); | 212 | MindBreakerBoard *m = new MindBreakerBoard(canvas, this); |
213 | setCentralWidget(m); | 213 | setCentralWidget(m); |
214 | 214 | ||
215 | setToolBarsMovable( FALSE ); | 215 | setToolBarsMovable( FALSE ); |
216 | 216 | ||
217 | QPEToolBar *tb = new QPEToolBar(this); | 217 | QPEToolBar *tb = new QPEToolBar(this); |
218 | tb->setHorizontalStretchable( TRUE ); | 218 | tb->setHorizontalStretchable( TRUE ); |
219 | 219 | ||
220 | QPixmap newicon = Resource::loadPixmap("new"); | 220 | QPixmap newicon = Resource::loadPixmap("new"); |
221 | new QToolButton(newicon, tr("New Game"), 0, | 221 | new QToolButton(newicon, tr("New Game"), 0, |
222 | m, SLOT(clear()), tb, "NewGame"); | 222 | m, SLOT(clear()), tb, "NewGame"); |
223 | 223 | ||
224 | score = new QToolButton(tb); | 224 | score = new QToolButton(tb); |
225 | score->setText(""); | 225 | score->setText(""); |
226 | score->setMaximumHeight(20); | 226 | score->setMaximumHeight(20); |
227 | score->setUsesTextLabel(TRUE); | 227 | score->setUsesTextLabel(TRUE); |
228 | tb->setStretchableWidget(score); | 228 | tb->setStretchableWidget(score); |
229 | 229 | ||
230 | connect(m, SIGNAL(scoreChanged(int, int)), this, SLOT(setScore(int, int))); | 230 | connect(m, SIGNAL(scoreChanged(int, int)), this, SLOT(setScore(int, int))); |
231 | connect(score, SIGNAL(clicked()), m, SLOT(resetScore())); | 231 | connect(score, SIGNAL(clicked()), m, SLOT(resetScore())); |
232 | 232 | ||
233 | int a, b; | 233 | int a, b; |
234 | m->getScore(&a, &b); | 234 | m->getScore(&a, &b); |
235 | setScore(a,b); | 235 | setScore(a,b); |
236 | } | 236 | } |
237 | 237 | ||
238 | void MindBreaker::setScore(int turns, int games) | 238 | void MindBreaker::setScore(int turns, int games) |
239 | { | 239 | { |
240 | double average; | 240 | double average; |
241 | double total_turns = turns; | 241 | double total_turns = turns; |
242 | double total_games = games; | 242 | double total_games = games; |
243 | 243 | ||
244 | if(total_games > 0) | 244 | if(total_games > 0) |
245 | average = total_turns / total_games; | 245 | average = total_turns / total_games; |
246 | else | 246 | else |
247 | average = 0.0; | 247 | average = 0.0; |
248 | 248 | ||
249 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); | 249 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | MindBreakerBoard::MindBreakerBoard( QCanvas &c, QWidget *parent=0, | 253 | MindBreakerBoard::MindBreakerBoard( QCanvas &canv, QWidget *parent, |
254 | const char *name=0, int wFlags=0 ) | 254 | const char *name, int wFlags ) |
255 | : QCanvasView(&c, parent, name, wFlags) | 255 | : QCanvasView(&canv, parent, name, wFlags) |
256 | { | 256 | { |
257 | int i, x, y; | 257 | int i, x, y; |
258 | struct timeval tv; | 258 | struct timeval tv; |
259 | 259 | ||
260 | current_go = 0; | 260 | current_go = 0; |
261 | gettimeofday(&tv, 0); | 261 | gettimeofday(&tv, 0); |
262 | 262 | ||
263 | srand(tv.tv_usec); | 263 | srand(tv.tv_usec); |
264 | 264 | ||
265 | canvas()->setAdvancePeriod(500); | 265 | canvas()->setAdvancePeriod(500); |
266 | 266 | ||
267 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 267 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); |
268 | 268 | ||
269 | /* copy from master image to functional images */ | 269 | /* copy from master image to functional images */ |
270 | x = 0; | 270 | x = 0; |
271 | y = 0; | 271 | y = 0; |
272 | panelImage = image.copy(x,y, panel_width, panel_height); | 272 | panelImage = image.copy(x,y, panel_width, panel_height); |
273 | y += panel_height; | 273 | y += panel_height; |
274 | y += panel_height; | 274 | y += panel_height; |
275 | 275 | ||
276 | titleImage = image.copy(x, y, title_width, title_height); | 276 | titleImage = image.copy(x, y, title_width, title_height); |
277 | 277 | ||
278 | Peg::buildImages(); // must be done BEFORE any pegs are made | 278 | Peg::buildImages(); // must be done BEFORE any pegs are made |
279 | 279 | ||
280 | current_highlight = new Peg(canvas(), 8); | 280 | current_highlight = new Peg(canvas(), 8); |
281 | current_highlight->setPlaced(TRUE); | 281 | current_highlight->setPlaced(TRUE); |
282 | current_highlight->setX(0); | 282 | current_highlight->setX(0); |
283 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); | 283 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); |
284 | current_highlight->setZ(0); | 284 | current_highlight->setZ(0); |
285 | current_highlight->show(); | 285 | current_highlight->show(); |
286 | 286 | ||
287 | 287 | ||
288 | /* set up the game */ | 288 | /* set up the game */ |
289 | Config c("MindBreaker", Config::User); | 289 | Config c("MindBreaker", Config::User); |
290 | c.setGroup("Board"); | 290 | c.setGroup("Board"); |
291 | game_over = FALSE; | 291 | game_over = FALSE; |
292 | if (c.readNumEntry("Answer0") < 0) { | 292 | if (c.readNumEntry("Answer0") < 0) { |
293 | for (i = 0; i < 4; i++) { | 293 | for (i = 0; i < 4; i++) { |
294 | answer[i] = rand() % 6; | 294 | answer[i] = rand() % 6; |
295 | current_guess[i] = 6; | 295 | current_guess[i] = 6; |
296 | } | 296 | } |
297 | total_turns = 0; | 297 | total_turns = 0; |
298 | total_games = 0; | 298 | total_games = 0; |
299 | } else { | 299 | } else { |
300 | int j; | 300 | int j; |
301 | c.setGroup("Score"); | 301 | c.setGroup("Score"); |
302 | total_turns = c.readNumEntry("Turns"); | 302 | total_turns = c.readNumEntry("Turns"); |
303 | total_games = c.readNumEntry("Games"); | 303 | total_games = c.readNumEntry("Games"); |
304 | if(total_turns < 0) | 304 | if(total_turns < 0) |
305 | total_turns = 0; | 305 | total_turns = 0; |
306 | if(total_games < 0) | 306 | if(total_games < 0) |
307 | total_games = 0; | 307 | total_games = 0; |
308 | 308 | ||
309 | 309 | ||
310 | checkScores(); | 310 | checkScores(); |
311 | c.setGroup("Board"); | 311 | c.setGroup("Board"); |
312 | for(i = 0; i < 4; i++) | 312 | for(i = 0; i < 4; i++) |
313 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); | 313 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); |
314 | /* read, and parse past guesses */ | 314 | /* read, and parse past guesses */ |
315 | current_go = 0; | 315 | current_go = 0; |
316 | for(j=0; j < 9; j++) { | 316 | for(j=0; j < 9; j++) { |
317 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); | 317 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); |
318 | if (current_guess[0] < 0) | 318 | if (current_guess[0] < 0) |
319 | break; | 319 | break; |
320 | placeGuessPeg(0, current_guess[0]); | 320 | placeGuessPeg(0, current_guess[0]); |
321 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); | 321 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); |
322 | placeGuessPeg(1, current_guess[1]); | 322 | placeGuessPeg(1, current_guess[1]); |
323 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); | 323 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); |
324 | placeGuessPeg(2, current_guess[2]); | 324 | placeGuessPeg(2, current_guess[2]); |
325 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); | 325 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); |
326 | placeGuessPeg(3, current_guess[3]); | 326 | placeGuessPeg(3, current_guess[3]); |
327 | checkGuess(); | 327 | checkGuess(); |
328 | } | 328 | } |
329 | for(i = 0; i < 4; i++) { | 329 | for(i = 0; i < 4; i++) { |
330 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); | 330 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); |
331 | if (current_guess[i] != 6) | 331 | if (current_guess[i] != 6) |
332 | placeGuessPeg(i, current_guess[i]); | 332 | placeGuessPeg(i, current_guess[i]); |
333 | } | 333 | } |
334 | } | 334 | } |
335 | 335 | ||
336 | /* draw initial screen */ | 336 | /* draw initial screen */ |
337 | drawBackground(); | 337 | drawBackground(); |
338 | canvas()->update(); | 338 | canvas()->update(); |
339 | } | 339 | } |
340 | 340 | ||
341 | MindBreakerBoard::~MindBreakerBoard() | 341 | MindBreakerBoard::~MindBreakerBoard() |
342 | { | 342 | { |
343 | int i, j; | 343 | int i, j; |
344 | if (game_over) { | 344 | if (game_over) { |
345 | current_go = 0; | 345 | current_go = 0; |
346 | /* clear the answer, clear the guess */ | 346 | /* clear the answer, clear the guess */ |
347 | for (i = 0; i < 4; i++) { | 347 | for (i = 0; i < 4; i++) { |
348 | answer[i] = rand() % 6; | 348 | answer[i] = rand() % 6; |
349 | current_guess[i] = 6; | 349 | current_guess[i] = 6; |
350 | } | 350 | } |
351 | } | 351 | } |
352 | 352 | ||
353 | Config c("MindBreaker", Config::User); | 353 | Config c("MindBreaker", Config::User); |
354 | c.setGroup("Board"); | 354 | c.setGroup("Board"); |
355 | c.clearGroup(); | 355 | c.clearGroup(); |
356 | /* write the board */ | 356 | /* write the board */ |
357 | for (i = 0; i < current_go; i++) { | 357 | for (i = 0; i < current_go; i++) { |
358 | for(j = 0; j < 4; j++) | 358 | for(j = 0; j < 4; j++) |
359 | c.writeEntry(tr("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); | 359 | c.writeEntry(tr("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); |
360 | } | 360 | } |
361 | for(j = 0; j < 4; j++) | 361 | for(j = 0; j < 4; j++) |
362 | c.writeEntry(tr("CurrentGo%1").arg(j), current_guess[j]); | 362 | c.writeEntry(tr("CurrentGo%1").arg(j), current_guess[j]); |
363 | for(j = 0; j < 4; j++) | 363 | for(j = 0; j < 4; j++) |
364 | c.writeEntry(tr("Answer%1").arg(j), answer[j]); | 364 | c.writeEntry(tr("Answer%1").arg(j), answer[j]); |
365 | 365 | ||
366 | c.setGroup("Score"); | 366 | c.setGroup("Score"); |
367 | /* write the score */ | 367 | /* write the score */ |
368 | 368 | ||
369 | c.writeEntry("Turns", total_turns); | 369 | c.writeEntry("Turns", total_turns); |
370 | c.writeEntry("Games", total_games); | 370 | c.writeEntry("Games", total_games); |
371 | } | 371 | } |
372 | 372 | ||
373 | void MindBreakerBoard::getScore(int *a, int *b) | 373 | void MindBreakerBoard::getScore(int *a, int *b) |
374 | { | 374 | { |
375 | *a = total_turns; | 375 | *a = total_turns; |
376 | *b = total_games; | 376 | *b = total_games; |
377 | return; | 377 | return; |
378 | } | 378 | } |
379 | 379 | ||
380 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) | 380 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) |
381 | { | 381 | { |
382 | int x = first_peg_x_diff + (pos * peg_spacing); | 382 | int x = first_peg_x_diff + (pos * peg_spacing); |
383 | int y = board_height - ((current_go + 1) * panel_height) | 383 | int y = board_height - ((current_go + 1) * panel_height) |
384 | + first_peg_y_diff; | 384 | + first_peg_y_diff; |
385 | 385 | ||
386 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); | 386 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); |
387 | peg->setPegPos(pos); | 387 | peg->setPegPos(pos); |
388 | peg->setPlaced(TRUE); | 388 | peg->setPlaced(TRUE); |
389 | peg->setX(x); | 389 | peg->setX(x); |
390 | peg->setY(y); | 390 | peg->setY(y); |
391 | peg->setZ(2); | 391 | peg->setZ(2); |
392 | peg->show(); | 392 | peg->show(); |
393 | } | 393 | } |
394 | 394 | ||
395 | void MindBreakerBoard::drawBackground() | 395 | void MindBreakerBoard::drawBackground() |
396 | { | 396 | { |
397 | int i, j, x, y, x_gap, y_gap; | 397 | int i, j, x, y, x_gap, y_gap; |
398 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); | 398 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); |
399 | 399 | ||
400 | QPainter painter(&background); | 400 | QPainter painter(&background); |
401 | 401 | ||
402 | painter.fillRect(0, 0, canvas()->width(), canvas()->height(), QColor(0,0,0)); | 402 | painter.fillRect(0, 0, canvas()->width(), canvas()->height(), QColor(0,0,0)); |
403 | /* very first thing is to draw the bins, as everything else needs | 403 | /* very first thing is to draw the bins, as everything else needs |
404 | * to be drawn over them */ | 404 | * to be drawn over them */ |
405 | 405 | ||
406 | QPen pen(QColor(85, 45, 27), 4); | 406 | QPen pen(QColor(85, 45, 27), 4); |
407 | painter.setPen(pen); | 407 | painter.setPen(pen); |
408 | x_gap = canvas()->width() - (panel_width + (2 * bin_margin)); | 408 | x_gap = canvas()->width() - (panel_width + (2 * bin_margin)); |
409 | //x_gap += peg_size >> 1; | 409 | //x_gap += peg_size >> 1; |
410 | if (x_gap < 1) | 410 | if (x_gap < 1) |
411 | x_gap = 1; | 411 | x_gap = 1; |
412 | 412 | ||
413 | y_gap = board_height / 6; | 413 | y_gap = board_height / 6; |
414 | y_gap -= (2 * bin_margin); | 414 | y_gap -= (2 * bin_margin); |
415 | //y_gap += peg_size >> 1; | 415 | //y_gap += peg_size >> 1; |
416 | if (y_gap < 1) | 416 | if (y_gap < 1) |
417 | y_gap = 1; | 417 | y_gap = 1; |
418 | x = panel_width + bin_margin - (peg_size >> 1); | 418 | x = panel_width + bin_margin - (peg_size >> 1); |
419 | y = bin_margin - (peg_size >> 1) + 2; | 419 | y = bin_margin - (peg_size >> 1) + 2; |
420 | 420 | ||
421 | for (i = 0; i < 6; i++) { | 421 | for (i = 0; i < 6; i++) { |
422 | for (j = 0; j < 10; j++) { | 422 | for (j = 0; j < 10; j++) { |
423 | int rx = x + (rand() % x_gap); | 423 | int rx = x + (rand() % x_gap); |
424 | int ry = y + (rand() % y_gap); | 424 | int ry = y + (rand() % y_gap); |
425 | painter.drawImage(rx,ry, Peg::imageForType(i)); | 425 | painter.drawImage(rx,ry, Peg::imageForType(i)); |
426 | } | 426 | } |
427 | y += board_height / 6; | 427 | y += board_height / 6; |
428 | } | 428 | } |
429 | /* now draw the surrounding boxes */ | 429 | /* now draw the surrounding boxes */ |
430 | x_gap = canvas()->width() - panel_width; | 430 | x_gap = canvas()->width() - panel_width; |
431 | if (x_gap < 1) x_gap = 1; | 431 | if (x_gap < 1) x_gap = 1; |
432 | y_gap = board_height / 6; | 432 | y_gap = board_height / 6; |
433 | x = panel_width; | 433 | x = panel_width; |
434 | y = 1; | 434 | y = 1; |
435 | 435 | ||
436 | for (i = 0; i < 6; i++) { | 436 | for (i = 0; i < 6; i++) { |
437 | painter.drawRect(x, y, x_gap, y_gap); | 437 | painter.drawRect(x, y, x_gap, y_gap); |
438 | y += y_gap; | 438 | y += y_gap; |
439 | } | 439 | } |
440 | 440 | ||
441 | x = 0; | 441 | x = 0; |
442 | y = 0; | 442 | y = 0; |
443 | 443 | ||
444 | painter.drawImage(x,y, titleImage); | 444 | painter.drawImage(x,y, titleImage); |
445 | y = title_height; | 445 | y = title_height; |
446 | /* now nine gues panels */ | 446 | /* now nine gues panels */ |
447 | for (i = 0; i < 9; i ++) { | 447 | for (i = 0; i < 9; i ++) { |