author | mickeyl <mickeyl> | 2003-01-23 13:32:28 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-01-23 13:32:28 (UTC) |
commit | 5100d4dc5012d5ff65bf1afc814e0552fe2d98fa (patch) (unidiff) | |
tree | af63cda30bb372a080f9533c2bf5e5e882264298 | |
parent | c50f0f454936d5552bd05e55ac6934d2e63d1743 (diff) | |
download | opie-5100d4dc5012d5ff65bf1afc814e0552fe2d98fa.zip opie-5100d4dc5012d5ff65bf1afc814e0552fe2d98fa.tar.gz opie-5100d4dc5012d5ff65bf1afc814e0552fe2d98fa.tar.bz2 |
g++ 3.2 fix... repeat after me: "I won't hide method parameters"
-rw-r--r-- | noncore/games/chess/chess.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/noncore/games/chess/chess.cpp b/noncore/games/chess/chess.cpp index 96a838a..29c96bb 100644 --- a/noncore/games/chess/chess.cpp +++ b/noncore/games/chess/chess.cpp | |||
@@ -1,119 +1,121 @@ | |||
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 | 21 | ||
22 | // human is not offered a promotion yet | 22 | // human is not offered a promotion yet |
23 | 23 | ||
24 | #include <stdlib.h> | ||
25 | |||
24 | #include <qcanvas.h> | 26 | #include <qcanvas.h> |
25 | #include <qmainwindow.h> | 27 | #include <qmainwindow.h> |
26 | #include <qlist.h> | 28 | #include <qlist.h> |
27 | #include <qimage.h> | 29 | #include <qimage.h> |
28 | #include <qpainter.h> | 30 | #include <qpainter.h> |
29 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
30 | #include <qregexp.h> | 32 | #include <qregexp.h> |
31 | 33 | ||
32 | #include <qpe/config.h> | 34 | #include <qpe/config.h> |
33 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
34 | 36 | ||
35 | #include "chess.h" | 37 | #include "chess.h" |
36 | 38 | ||
37 | #define CHESS_DEBUG | 39 | #define CHESS_DEBUG |
38 | 40 | ||
39 | int pieceSize = 40; | 41 | int pieceSize = 40; |
40 | static QVector < QImage > imgList; | 42 | static QVector < QImage > imgList; |
41 | int timeMoves, timeTime; | 43 | int timeMoves, timeTime; |
42 | 44 | ||
43 | int BoardView::convertToRank(int r) | 45 | int BoardView::convertToRank(int r) |
44 | { | 46 | { |
45 | r = r / pieceSize; | 47 | r = r / pieceSize; |
46 | if (humanSide == sideWhite) | 48 | if (humanSide == sideWhite) |
47 | r = 8 - r; | 49 | r = 8 - r; |
48 | else | 50 | else |
49 | r++; | 51 | r++; |
50 | return r; | 52 | return r; |
51 | } | 53 | } |
52 | 54 | ||
53 | char BoardView::convertToFile(int f) | 55 | char BoardView::convertToFile(int f) |
54 | { | 56 | { |
55 | f = f / pieceSize; | 57 | f = f / pieceSize; |
56 | if (humanSide == sideWhite) | 58 | if (humanSide == sideWhite) |
57 | return f + 'a'; | 59 | return f + 'a'; |
58 | else | 60 | else |
59 | return 'h' - f; | 61 | return 'h' - f; |
60 | } | 62 | } |
61 | 63 | ||
62 | int BoardView::convertFromFile(char f) | 64 | int BoardView::convertFromFile(char f) |
63 | { | 65 | { |
64 | if (humanSide == sideWhite) | 66 | if (humanSide == sideWhite) |
65 | f = f - 'a'; | 67 | f = f - 'a'; |
66 | else | 68 | else |
67 | f = 'h' - f; | 69 | f = 'h' - f; |
68 | return f * pieceSize; | 70 | return f * pieceSize; |
69 | } | 71 | } |
70 | 72 | ||
71 | int BoardView::convertFromRank(int r) | 73 | int BoardView::convertFromRank(int r) |
72 | { | 74 | { |
73 | if (humanSide == sideWhite) | 75 | if (humanSide == sideWhite) |
74 | r = 8 - r; | 76 | r = 8 - r; |
75 | else | 77 | else |
76 | r--; | 78 | r--; |
77 | return r * pieceSize; | 79 | return r * pieceSize; |
78 | } | 80 | } |
79 | 81 | ||
80 | // Pieces | 82 | // Pieces |
81 | Piece::Piece(QCanvas * canvas, int t):QCanvasRectangle(canvas) | 83 | Piece::Piece(QCanvas * canvas, int t):QCanvasRectangle(canvas) |
82 | { | 84 | { |
83 | type = t; | 85 | type = t; |
84 | setSize(pieceSize, pieceSize); | 86 | setSize(pieceSize, pieceSize); |
85 | show(); | 87 | show(); |
86 | } | 88 | } |
87 | 89 | ||
88 | Piece *BoardView::newPiece(int t, char f, int r) | 90 | Piece *BoardView::newPiece(int t, char f, int r) |
89 | { | 91 | { |
90 | Piece *tmpPiece = new Piece(canvas(), t); | 92 | Piece *tmpPiece = new Piece(canvas(), t); |
91 | tmpPiece->move(convertFromFile(f), convertFromRank(r)); | 93 | tmpPiece->move(convertFromFile(f), convertFromRank(r)); |
92 | list.append(tmpPiece); | 94 | list.append(tmpPiece); |
93 | return tmpPiece; | 95 | return tmpPiece; |
94 | } | 96 | } |
95 | 97 | ||
96 | void BoardView::deletePiece(Piece * p) | 98 | void BoardView::deletePiece(Piece * p) |
97 | { | 99 | { |
98 | list.remove(p); | 100 | list.remove(p); |
99 | canvas()->update(); | 101 | canvas()->update(); |
100 | } | 102 | } |
101 | 103 | ||
102 | void Piece::drawShape(QPainter & p) | 104 | void Piece::drawShape(QPainter & p) |
103 | { | 105 | { |
104 | p.drawImage(int (x()), int (y()), *(imgList[type])); | 106 | p.drawImage(int (x()), int (y()), *(imgList[type])); |
105 | } | 107 | } |
106 | 108 | ||
107 | void BoardView::buildImages(QImage theme) | 109 | void BoardView::buildImages(QImage theme) |
108 | { | 110 | { |
109 | imgList.resize(12); | 111 | imgList.resize(12); |
110 | int x; | 112 | int x; |
111 | int y = 0; | 113 | int y = 0; |
112 | 114 | ||
113 | for (int j = 0; j < 2; j++) { | 115 | for (int j = 0; j < 2; j++) { |
114 | x = 0; | 116 | x = 0; |
115 | for (int i = 0; i < 6; i++) { | 117 | for (int i = 0; i < 6; i++) { |
116 | imgList.insert(i + (j * 6), | 118 | imgList.insert(i + (j * 6), |
117 | new QImage(theme. | 119 | new QImage(theme. |
118 | copy(x, y, pieceSize, pieceSize))); | 120 | copy(x, y, pieceSize, pieceSize))); |
119 | x += pieceSize; | 121 | x += pieceSize; |
@@ -245,114 +247,114 @@ void BoardView::setTheme(QString filename) | |||
245 | 247 | ||
246 | // sets the bg to the default background image for the current theme | 248 | // sets the bg to the default background image for the current theme |
247 | // also resposible for drawing the "active" marker | 249 | // also resposible for drawing the "active" marker |
248 | void BoardView::drawBackgroundImage(QPoint activeSquare) | 250 | void BoardView::drawBackgroundImage(QPoint activeSquare) |
249 | { | 251 | { |
250 | bg = QPixmap(8 * pieceSize, 8 * pieceSize); | 252 | bg = QPixmap(8 * pieceSize, 8 * pieceSize); |
251 | QPainter p(&bg); | 253 | QPainter p(&bg); |
252 | bool col = FALSE; | 254 | bool col = FALSE; |
253 | for (int i = 0; i < 8; i++) { | 255 | for (int i = 0; i < 8; i++) { |
254 | for (int j = 0; j < 8; j++) { | 256 | for (int j = 0; j < 8; j++) { |
255 | QPoint point(i * pieceSize, j * pieceSize); | 257 | QPoint point(i * pieceSize, j * pieceSize); |
256 | if (col) { | 258 | if (col) { |
257 | if (point.x() == activeSquare.x() | 259 | if (point.x() == activeSquare.x() |
258 | && point.y() == activeSquare.y()) | 260 | && point.y() == activeSquare.y()) |
259 | p.drawImage(point, activeBlackSquare); | 261 | p.drawImage(point, activeBlackSquare); |
260 | else | 262 | else |
261 | p.drawImage(point, blackSquare); | 263 | p.drawImage(point, blackSquare); |
262 | col = FALSE; | 264 | col = FALSE; |
263 | } else { | 265 | } else { |
264 | if (point.x() == activeSquare.x() | 266 | if (point.x() == activeSquare.x() |
265 | && point.y() == activeSquare.y()) | 267 | && point.y() == activeSquare.y()) |
266 | p.drawImage(point, activeWhiteSquare); | 268 | p.drawImage(point, activeWhiteSquare); |
267 | else | 269 | else |
268 | p.drawImage(point, whiteSquare); | 270 | p.drawImage(point, whiteSquare); |
269 | col = TRUE; | 271 | col = TRUE; |
270 | } | 272 | } |
271 | } | 273 | } |
272 | col = !col; | 274 | col = !col; |
273 | } | 275 | } |
274 | canvas()->setBackgroundPixmap(bg); | 276 | canvas()->setBackgroundPixmap(bg); |
275 | canvas()->update(); | 277 | canvas()->update(); |
276 | } | 278 | } |
277 | 279 | ||
278 | 280 | ||
279 | // Board view widget | 281 | // Board view widget |
280 | void BoardView::contentsMousePressEvent(QMouseEvent * e) | 282 | void BoardView::contentsMousePressEvent(QMouseEvent * e) |
281 | { | 283 | { |
282 | QCanvasItemList cList = canvas()->collisions(e->pos()); | 284 | QCanvasItemList cList = canvas()->collisions(e->pos()); |
283 | if (activeSide == humanSide && playingGame) { | 285 | if (activeSide == humanSide && playingGame) { |
284 | if (!activePiece) { | 286 | if (!activePiece) { |
285 | if (cList.count()) { | 287 | if (cList.count()) { |
286 | activePiece = (Piece *) (*(cList.at(0))); | 288 | activePiece = (Piece *) (*(cList.at(0))); |
287 | drawBackgroundImage(QPoint | 289 | drawBackgroundImage(QPoint |
288 | (activePiece->x(), activePiece->y())); | 290 | (activePiece->x(), activePiece->y())); |
289 | } | 291 | } |
290 | } else { | 292 | } else { |
291 | if (!(activePiece == (Piece *) (*(cList.at(0))))) { | 293 | if (!(activePiece == (Piece *) (*(cList.at(0))))) { |
292 | char fromFile = convertToFile(activePiece->x()); | 294 | char fromFile = convertToFile(activePiece->x()); |
293 | int fromRank = convertToRank(activePiece->y()); | 295 | int fromRank = convertToRank(activePiece->y()); |
294 | char toFile = convertToFile(e->pos().x()); | 296 | char toFile = convertToFile(e->pos().x()); |
295 | int toRank = convertToRank(e->pos().y()); | 297 | int toRank = convertToRank(e->pos().y()); |
296 | QString moveS; | 298 | QString moveS; |
297 | moveS.append(fromFile); | 299 | moveS.append(fromFile); |
298 | moveS.append(moveS.number(fromRank)); | 300 | moveS.append(moveS.number(fromRank)); |
299 | moveS.append(toFile); | 301 | moveS.append(toFile); |
300 | moveS.append(moveS.number(toRank)); | 302 | moveS.append(moveS.number(toRank)); |
301 | if ((activePiece->type == wPawn | 303 | if ((activePiece->type == wPawn |
302 | && fromRank == 7 && toRank == 8) | 304 | && fromRank == 7 && toRank == 8) |
303 | || (activePiece->type == bPawn | 305 | || (activePiece->type == bPawn |
304 | && fromRank == 2 && toRank == 1)) { | 306 | && fromRank == 2 && toRank == 1)) { |
305 | // offer a promotion | 307 | // offer a promotion |
306 | emit(showMessage | 308 | emit(showMessage |
307 | ("you are meant to be offered a promotion here")); | 309 | ("you are meant to be offered a promotion here")); |
308 | char promoteTo = wQueen;// doesnt matter for now | 310 | char promoteTo = wQueen;// doesnt matter for now |
309 | moveS.append(promoteTo); | 311 | moveS.append(promoteTo); |
310 | moveS.append("\n"); | 312 | moveS.append("\n"); |
311 | crafty->writeToStdin(moveS.latin1()); | 313 | crafty->writeToStdin(moveS.latin1()); |
312 | } | 314 | } |
313 | } | 315 | } |
314 | activePiece = 0; | 316 | activePiece = 0; |
315 | drawBackgroundImage(QPoint(-1, -1)); | 317 | drawBackgroundImage(QPoint(-1, -1)); |
316 | } | 318 | } |
317 | } | 319 | } |
318 | 320 | ||
319 | else { | 321 | else { |
320 | emitErrorMessage(); | 322 | emitErrorMessage(); |
321 | } | 323 | } |
322 | } | 324 | } |
323 | 325 | ||
324 | void BoardView::swapSides() | 326 | void BoardView::swapSides() |
325 | { | 327 | { |
326 | if (activeSide == humanSide && playingGame) { | 328 | if (activeSide == humanSide && playingGame) { |
327 | humanSide = !humanSide; | 329 | humanSide = !humanSide; |
328 | crafty->writeToStdin("savepos\ngo\n"); | 330 | crafty->writeToStdin("savepos\ngo\n"); |
329 | } else | 331 | } else |
330 | emitErrorMessage(); | 332 | emitErrorMessage(); |
331 | } | 333 | } |
332 | 334 | ||
333 | BoardView::BoardView(QCanvas *c, QWidget *w, const char *name) | 335 | BoardView::BoardView(QCanvas *c, QWidget *w, const char *name) |
334 | : QCanvasView(c, w, name) { | 336 | : QCanvasView(c, w, name) { |
335 | humanSide = sideWhite; | 337 | humanSide = sideWhite; |
336 | activeSide = sideWhite; | 338 | activeSide = sideWhite; |
337 | playingGame = TRUE; | 339 | playingGame = TRUE; |
338 | activePiece = 0; | 340 | activePiece = 0; |
339 | list.setAutoDelete(TRUE); | 341 | list.setAutoDelete(TRUE); |
340 | setCanvas(new QCanvas()); | 342 | setCanvas(new QCanvas()); |
341 | Config c("Chess", Config::User); | 343 | Config conf("Chess", Config::User); |
342 | c.setGroup("Theme"); | 344 | conf.setGroup("Theme"); |
343 | QString theme = c.readEntry("imagefile", "simple-28"); | 345 | QString theme = conf.readEntry("imagefile", "simple-28"); |
344 | setTheme(theme); | 346 | setTheme(theme); |
345 | crafty = new CraftyProcess(this); | 347 | crafty = new CraftyProcess(this); |
346 | crafty->addArgument("crafty"); | 348 | crafty->addArgument("crafty"); |
347 | if (!crafty->start()) { | 349 | if (!crafty->start()) { |
348 | QMessageBox::critical(0, | 350 | QMessageBox::critical(0, |
349 | tr("Could not find crafty chess engine"), | 351 | tr("Could not find crafty chess engine"), |
350 | tr("Quit")); | 352 | tr("Quit")); |
351 | exit(-1); | 353 | exit(-1); |
352 | } | 354 | } |
353 | 355 | ||
354 | connect(crafty, SIGNAL(readyReadStdout()), this, SLOT(readStdout())); | 356 | connect(crafty, SIGNAL(readyReadStdout()), this, SLOT(readStdout())); |
355 | connect(crafty, SIGNAL(processExited()), this, SLOT(craftyDied())); | 357 | connect(crafty, SIGNAL(processExited()), this, SLOT(craftyDied())); |
356 | // crafty->writeToStdin("xboard\nics\nkibitz=2\n"); | 358 | // crafty->writeToStdin("xboard\nics\nkibitz=2\n"); |
357 | newGame(); | 359 | newGame(); |
358 | } | 360 | } |