author | zecke <zecke> | 2004-02-06 10:33:09 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-06 10:33:09 (UTC) |
commit | 46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25 (patch) (unidiff) | |
tree | ab868f654bd296d693b74c43e166a8403aa9ede4 | |
parent | 5b2b3a4147742e7053539d3c58a2a552eb830815 (diff) | |
download | opie-46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25.zip opie-46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25.tar.gz opie-46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25.tar.bz2 |
Update from Qtopia1.7 (borders on the items)
make it quicklaunchable
-rw-r--r-- | noncore/games/fifteen/fifteen.cpp | 83 | ||||
-rw-r--r-- | noncore/games/fifteen/fifteen.h | 12 | ||||
-rw-r--r-- | noncore/games/fifteen/fifteen.pro | 4 | ||||
-rw-r--r-- | noncore/games/fifteen/main.cpp | 20 |
4 files changed, 70 insertions, 49 deletions
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp index 2e4ed94..b4e0308 100644 --- a/noncore/games/fifteen/fifteen.cpp +++ b/noncore/games/fifteen/fifteen.cpp | |||
@@ -1,341 +1,368 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the 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 "fifteen.h" | 21 | #include "fifteen.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qtopia/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qtopia/config.h> |
25 | 25 | ||
26 | #include <qvbox.h> | 26 | #include <qvbox.h> |
27 | #include <qaction.h> | 27 | #include <qaction.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
31 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <qpe/qpetoolbar.h> | 32 | #include <qtoolbar.h> |
33 | #include <qmenubar.h> | 33 | #include <qmenubar.h> |
34 | #include <qstringlist.h> | 34 | #include <qstringlist.h> |
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | #include <qtoolbutton.h> | ||
36 | 37 | ||
37 | #include <stdlib.h> | 38 | #include <stdlib.h> |
38 | #include <time.h> | 39 | #include <time.h> |
39 | 40 | ||
40 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name) | 41 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl) |
41 | : QMainWindow( parent, name ) | 42 | : QMainWindow( parent, name, fl ) |
42 | { | 43 | { |
43 | // random seed | 44 | // random seed |
44 | srand(time(0)); | 45 | srand(time(0)); |
45 | 46 | setCaption( tr("Fifteen Pieces") ); | |
46 | setToolBarsMovable( FALSE ); | ||
47 | QVBox *vbox = new QVBox( this ); | ||
48 | PiecesTable *table = new PiecesTable( vbox ); | ||
49 | setCentralWidget(vbox); | ||
50 | 47 | ||
51 | QToolBar *toolbar = new QToolBar(this); | 48 | QToolBar *toolbar = new QToolBar(this); |
52 | toolbar->setHorizontalStretchable( TRUE ); | 49 | toolbar->setHorizontalStretchable( FALSE ); |
53 | addToolBar(toolbar); | ||
54 | |||
55 | QMenuBar *menubar = new QMenuBar( toolbar ); | 50 | QMenuBar *menubar = new QMenuBar( toolbar ); |
56 | menubar->setMargin(0); | 51 | menubar->setMargin(0); |
57 | |||
58 | QPopupMenu *game = new QPopupMenu( this ); | 52 | QPopupMenu *game = new QPopupMenu( this ); |
59 | 53 | ||
60 | QWidget *spacer = new QWidget( toolbar ); | 54 | QWidget *spacer = new QWidget( toolbar ); |
61 | spacer->setBackgroundMode( PaletteButton ); | 55 | spacer->setBackgroundMode( PaletteButton ); |
62 | toolbar->setStretchableWidget( spacer ); | 56 | toolbar->setStretchableWidget( spacer ); |
63 | 57 | ||
58 | |||
59 | setToolBarsMovable( FALSE ); | ||
60 | QVBox *vbox = new QVBox( this ); | ||
61 | PiecesTable *table = new PiecesTable( vbox ); | ||
62 | setCentralWidget(vbox); | ||
63 | |||
64 | |||
65 | |||
64 | QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), | 66 | QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), |
65 | QString::null, 0, this, 0 ); | 67 | QString::null, 0, this, 0 ); |
66 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); | 68 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); |
67 | a->addTo( game ); | 69 | a->addTo( game ); |
68 | a->addTo( toolbar ); | 70 | a->addTo( toolbar ); |
69 | 71 | ||
70 | a = new QAction( tr( "Solve" ), Resource::loadPixmap( "repeat" ), | 72 | /* This is pointless and confusing. |
73 | a = new QAction( tr( "Solve" ), Resource::loadIconSet( "repeat" ), | ||
71 | QString::null, 0, this, 0 ); | 74 | QString::null, 0, this, 0 ); |
72 | connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); | 75 | connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); |
73 | a->addTo( game ); | 76 | a->addTo( game ); |
74 | a->addTo( toolbar ); | 77 | a->addTo( toolbar ); |
75 | 78 | */ | |
76 | menubar->insertItem( tr( "Game" ), game ); | 79 | menubar->insertItem( tr( "Game" ), game ); |
77 | } | 80 | } |
78 | 81 | ||
79 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) | 82 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) |
80 | : QTableView(parent, name), _menu(0), _randomized(false) | 83 | : QTableView(parent, name), _menu(0), _randomized(false) |
81 | { | 84 | { |
82 | // setup table view | 85 | // setup table view |
83 | setFrameStyle(StyledPanel | Sunken); | 86 | setFrameStyle(StyledPanel | Sunken); |
84 | setBackgroundMode(NoBackground); | 87 | setBackgroundMode(NoBackground); |
85 | setMouseTracking(true); | 88 | setMouseTracking(true); |
86 | 89 | ||
87 | setNumRows(4); | 90 | setNumRows(4); |
88 | setNumCols(4); | 91 | setNumCols(4); |
89 | 92 | ||
90 | // init arrays | 93 | // init arrays |
91 | initMap(); | 94 | initMap(); |
92 | readConfig(); | 95 | readConfig(); |
93 | initColors(); | 96 | initColors(); |
94 | 97 | ||
95 | // set font | 98 | // set font |
96 | QFont f = font(); | 99 | QFont f = font(); |
97 | f.setPixelSize(18); | 100 | f.setPixelSize(18); |
98 | f.setBold( TRUE ); | 101 | f.setBold( TRUE ); |
99 | setFont(f); | 102 | setFont(f); |
100 | } | 103 | } |
101 | 104 | ||
102 | PiecesTable::~PiecesTable() | 105 | PiecesTable::~PiecesTable() |
103 | { | 106 | { |
104 | writeConfig(); | 107 | writeConfig(); |
105 | } | 108 | } |
106 | 109 | ||
107 | void PiecesTable::writeConfig() | 110 | void PiecesTable::writeConfig() |
108 | { | 111 | { |
109 | Config cfg("Fifteen"); | 112 | Config cfg("Fifteen"); |
110 | cfg.setGroup("Game"); | 113 | cfg.setGroup("Game"); |
111 | QStringList map; | 114 | QStringList map; |
112 | for (unsigned int i = 0; i < 16; i++) | 115 | for (int i = 0; i < 16; i++) |
113 | map.append( QString::number( _map[i] ) ); | 116 | map.append( QString::number( _map[i] ) ); |
114 | cfg.writeEntry("Map", map, '-'); | 117 | cfg.writeEntry("Map", map, '-'); |
115 | cfg.writeEntry("Randomized", _randomized ); | 118 | cfg.writeEntry("Randomized", _randomized ); |
116 | } | 119 | } |
117 | 120 | ||
118 | void PiecesTable::readConfig() | 121 | void PiecesTable::readConfig() |
119 | { | 122 | { |
120 | Config cfg("Fifteen"); | 123 | Config cfg("Fifteen"); |
121 | cfg.setGroup("Game"); | 124 | cfg.setGroup("Game"); |
122 | QStringList map = cfg.readListEntry("Map", '-'); | 125 | QStringList map = cfg.readListEntry("Map", '-'); |
123 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); | 126 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); |
124 | unsigned int i = 0; | 127 | int i = 0; |
125 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { | 128 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { |
126 | _map[i] = (*it).toInt(); | 129 | _map[i] = (*it).toInt(); |
127 | i++; | 130 | i++; |
128 | if ( i > 15 ) break; | 131 | if ( i > 15 ) break; |
129 | } | 132 | } |
130 | } | 133 | } |
131 | 134 | ||
132 | void PiecesTable::paintCell(QPainter *p, int row, int col) | 135 | void PiecesTable::paintCell(QPainter *p, int row, int col) |
133 | { | 136 | { |
134 | int w = cellWidth(); | 137 | int w = cellWidth(); |
135 | int h = cellHeight(); | 138 | int h = cellHeight(); |
136 | int x2 = w - 1; | 139 | int x2 = w - 1; |
137 | int y2 = h - 1; | 140 | int y2 = h - 1; |
138 | 141 | ||
139 | int number = _map[col + row * numCols()] + 1; | 142 | int number = _map[col + row * numCols()] + 1; |
140 | 143 | ||
141 | // draw cell background | 144 | // draw cell background |
142 | if(number == 16) | 145 | if(number == 16) |
143 | p->setBrush(colorGroup().background()); | 146 | p->setBrush(colorGroup().background()); |
144 | else | 147 | else |
145 | p->setBrush(_colors[number-1]); | 148 | p->setBrush(_colors[number-1]); |
146 | p->setPen(NoPen); | 149 | p->setPen(NoPen); |
147 | p->drawRect(0, 0, w, h); | 150 | p->drawRect(0, 0, w, h); |
148 | 151 | ||
152 | if (number == 16) return; | ||
153 | |||
149 | // draw borders | 154 | // draw borders |
150 | if (height() > 40) { | 155 | if (height() > 40) { |
151 | p->setPen(colorGroup().text()); | 156 | p->setBrush(_colors[number-1].light(130)); |
152 | if(col < numCols()-1) | 157 | p->drawPolygon(light_border); |
153 | p->drawLine(x2, 0, x2, y2); // right border line | ||
154 | 158 | ||
155 | if(row < numRows()-1) | 159 | p->setBrush(_colors[number-1].dark(130)); |
156 | p->drawLine(0, y2, x2, y2); // bottom boder line | 160 | p->drawPolygon(dark_border); |
157 | } | 161 | } |
158 | 162 | ||
159 | // draw number | 163 | // draw number |
160 | if (number == 16) return; | ||
161 | p->setPen(black); | 164 | p->setPen(black); |
162 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number)); | 165 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number)); |
163 | } | 166 | } |
164 | 167 | ||
165 | void PiecesTable::resizeEvent(QResizeEvent *e) | 168 | void PiecesTable::resizeEvent(QResizeEvent *e) |
166 | { | 169 | { |
167 | QTableView::resizeEvent(e); | 170 | QTableView::resizeEvent(e); |
168 | 171 | ||
169 | setCellWidth(contentsRect().width()/ numRows()); | 172 | setCellWidth(contentsRect().width()/ numRows()); |
170 | setCellHeight(contentsRect().height() / numCols()); | 173 | setCellHeight(contentsRect().height() / numCols()); |
174 | |||
175 | // | ||
176 | // Calculate 3d-effect borders | ||
177 | // | ||
178 | intcell_w = cellWidth(); | ||
179 | intcell_h = cellHeight(); | ||
180 | int x_offset = cell_w - int(cell_w * 0.9);// 10% should be enough | ||
181 | inty_offset = cell_h - int(cell_h * 0.9); | ||
182 | |||
183 | light_border.setPoints(6, | ||
184 | 0, 0, | ||
185 | cell_w, 0, | ||
186 | cell_w - x_offset, y_offset, | ||
187 | x_offset, y_offset, | ||
188 | x_offset, cell_h - y_offset, | ||
189 | 0, cell_h); | ||
190 | |||
191 | dark_border.setPoints(6, | ||
192 | cell_w, 0, | ||
193 | cell_w, cell_h, | ||
194 | 0, cell_h, | ||
195 | x_offset, cell_h - y_offset, | ||
196 | cell_w - x_offset, cell_h - y_offset, | ||
197 | cell_w - x_offset, y_offset); | ||
171 | } | 198 | } |
172 | 199 | ||
173 | void PiecesTable::initColors() | 200 | void PiecesTable::initColors() |
174 | { | 201 | { |
175 | _colors.resize(numRows() * numCols()); | 202 | _colors.resize(numRows() * numCols()); |
176 | for (int r = 0; r < numRows(); r++) | 203 | for (int r = 0; r < numRows(); r++) |
177 | for (int c = 0; c < numCols(); c++) | 204 | for (int c = 0; c < numCols(); c++) |
178 | _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150); | 205 | _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150); |
179 | } | 206 | } |
180 | 207 | ||
181 | void PiecesTable::initMap() | 208 | void PiecesTable::initMap() |
182 | { | 209 | { |
183 | _map.resize(16); | 210 | _map.resize(16); |
184 | for (unsigned int i = 0; i < 16; i++) | 211 | for ( int i = 0; i < 16; i++) |
185 | _map[i] = i; | 212 | _map[i] = i; |
186 | 213 | ||
187 | _randomized = false; | 214 | _randomized = false; |
188 | } | 215 | } |
189 | 216 | ||
190 | void PiecesTable::randomizeMap() | 217 | void PiecesTable::randomizeMap() |
191 | { | 218 | { |
192 | initMap(); | 219 | initMap(); |
193 | _randomized = true; | 220 | _randomized = true; |
194 | // find the free position | 221 | // find the free position |
195 | int pos = _map.find(15); | 222 | int pos = _map.find(15); |
196 | 223 | ||
197 | int move = 0; | 224 | int move = 0; |
198 | while ( move < 333 ) { | 225 | while ( move < 333 ) { |
199 | 226 | ||
200 | int frow = pos / numCols(); | 227 | int frow = pos / numCols(); |
201 | int fcol = pos - frow * numCols(); | 228 | int fcol = pos - frow * numCols(); |
202 | 229 | ||
203 | // find click position | 230 | // find click position |
204 | int row = rand()%4; | 231 | int row = rand()%4; |
205 | int col = rand()%4; | 232 | int col = rand()%4; |
206 | 233 | ||
207 | // sanity check | 234 | // sanity check |
208 | if ( row < 0 || row >= numRows() ) continue; | 235 | if ( row < 0 || row >= numRows() ) continue; |
209 | if ( col < 0 || col >= numCols() ) continue; | 236 | if ( col < 0 || col >= numCols() ) continue; |
210 | if ( row != frow && col != fcol ) continue; | 237 | if ( row != frow && col != fcol ) continue; |
211 | 238 | ||
212 | move++; | 239 | move++; |
213 | 240 | ||
214 | // rows match -> shift pieces | 241 | // rows match -> shift pieces |
215 | if(row == frow) { | 242 | if(row == frow) { |
216 | 243 | ||
217 | if (col < fcol) { | 244 | if (col < fcol) { |
218 | for(int c = fcol; c > col; c--) { | 245 | for(int c = fcol; c > col; c--) { |
219 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; | 246 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; |
220 | } | 247 | } |
221 | } | 248 | } |
222 | else if (col > fcol) { | 249 | else if (col > fcol) { |
223 | for(int c = fcol; c < col; c++) { | 250 | for(int c = fcol; c < col; c++) { |
224 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; | 251 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; |
225 | } | 252 | } |
226 | } | 253 | } |
227 | } | 254 | } |
228 | // cols match -> shift pieces | 255 | // cols match -> shift pieces |
229 | else if (col == fcol) { | 256 | else if (col == fcol) { |
230 | 257 | ||
231 | if (row < frow) { | 258 | if (row < frow) { |
232 | for(int r = frow; r > row; r--) { | 259 | for(int r = frow; r > row; r--) { |
233 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; | 260 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; |
234 | } | 261 | } |
235 | } | 262 | } |
236 | else if (row > frow) { | 263 | else if (row > frow) { |
237 | for(int r = frow; r < row; r++) { | 264 | for(int r = frow; r < row; r++) { |
238 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; | 265 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; |
239 | } | 266 | } |
240 | } | 267 | } |
241 | } | 268 | } |
242 | // move free cell to click position | 269 | // move free cell to click position |
243 | _map[pos=(col + row * numCols())] = 15; | 270 | _map[pos=(col + row * numCols())] = 15; |
244 | repaint(); | ||
245 | } | 271 | } |
272 | repaint(); | ||
246 | } | 273 | } |
247 | 274 | ||
248 | void PiecesTable::checkwin() | 275 | void PiecesTable::checkwin() |
249 | { | 276 | { |
250 | if(!_randomized) return; | 277 | if(!_randomized) return; |
251 | 278 | ||
252 | int i; | 279 | int i; |
253 | for (i = 0; i < 16; i++) | 280 | for (i = 0; i < 16; i++) |
254 | if(i != _map[i]) | 281 | if(i != _map[i]) |
255 | break; | 282 | break; |
256 | 283 | ||
257 | if (i == 16) { | 284 | if (i == 16) { |
258 | QMessageBox::information(this, tr("Fifteen Pieces"), | 285 | QMessageBox::information(this, tr("Fifteen Pieces"), |
259 | tr("Congratulations!\nYou win the game!")); | 286 | tr("Congratulations!\nYou win the game!")); |
260 | _randomized = FALSE; | 287 | _randomized = FALSE; |
261 | } | 288 | } |
262 | 289 | ||
263 | } | 290 | } |
264 | 291 | ||
265 | void PiecesTable::slotRandomize() | 292 | void PiecesTable::slotRandomize() |
266 | { | 293 | { |
267 | randomizeMap(); | 294 | randomizeMap(); |
268 | } | 295 | } |
269 | 296 | ||
270 | void PiecesTable::slotReset() | 297 | void PiecesTable::slotReset() |
271 | { | 298 | { |
272 | initMap(); | 299 | initMap(); |
273 | repaint(); | 300 | repaint(); |
274 | } | 301 | } |
275 | 302 | ||
276 | void PiecesTable::mousePressEvent(QMouseEvent* e) | 303 | void PiecesTable::mousePressEvent(QMouseEvent* e) |
277 | { | 304 | { |
278 | QTableView::mousePressEvent(e); | 305 | QTableView::mousePressEvent(e); |
279 | 306 | ||
280 | if (e->button() == RightButton) { | 307 | if (e->button() == RightButton) { |
281 | 308 | ||
282 | // setup RMB pupup menu | 309 | // setup RMB pupup menu |
283 | if(!_menu) { | 310 | if(!_menu) { |
284 | _menu = new QPopupMenu(this); | 311 | _menu = new QPopupMenu(this); |
285 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); | 312 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); |
286 | _menu->insertItem(tr("&Reset Pieces"), mReset); | 313 | _menu->insertItem(tr("&Reset Pieces"), mReset); |
287 | _menu->adjustSize(); | 314 | _menu->adjustSize(); |
288 | } | 315 | } |
289 | 316 | ||
290 | // execute RMB popup and check result | 317 | // execute RMB popup and check result |
291 | switch(_menu->exec(mapToGlobal(e->pos()))) { | 318 | switch(_menu->exec(mapToGlobal(e->pos()))) { |
292 | case mRandomize: | 319 | case mRandomize: |
293 | randomizeMap(); | 320 | randomizeMap(); |
294 | break; | 321 | break; |
295 | case mReset: | 322 | case mReset: |
296 | initMap(); | 323 | initMap(); |
297 | repaint(); | 324 | repaint(); |
298 | break; | 325 | break; |
299 | default: | 326 | default: |
300 | break; | 327 | break; |
301 | } | 328 | } |
302 | } | 329 | } |
303 | else { | 330 | else { |
304 | // GAME LOGIC | 331 | // GAME LOGIC |
305 | 332 | ||
306 | // find the free position | 333 | // find the free position |
307 | int pos = _map.find(15); | 334 | int pos = _map.find(15); |
308 | if(pos < 0) return; | 335 | if(pos < 0) return; |
309 | 336 | ||
310 | int frow = pos / numCols(); | 337 | int frow = pos / numCols(); |
311 | int fcol = pos - frow * numCols(); | 338 | int fcol = pos - frow * numCols(); |
312 | 339 | ||
313 | // find click position | 340 | // find click position |
314 | int row = findRow(e->y()); | 341 | int row = findRow(e->y()); |
315 | int col = findCol(e->x()); | 342 | int col = findCol(e->x()); |
316 | 343 | ||
317 | // sanity check | 344 | // sanity check |
318 | if (row < 0 || row >= numRows()) return; | 345 | if (row < 0 || row >= numRows()) return; |
319 | if (col < 0 || col >= numCols()) return; | 346 | if (col < 0 || col >= numCols()) return; |
320 | if ( row != frow && col != fcol ) return; | 347 | if ( row != frow && col != fcol ) return; |
321 | 348 | ||
322 | // valid move? | 349 | // valid move? |
323 | if(row != frow && col != fcol) return; | 350 | if(row != frow && col != fcol) return; |
324 | 351 | ||
325 | // rows match -> shift pieces | 352 | // rows match -> shift pieces |
326 | if(row == frow) { | 353 | if(row == frow) { |
327 | 354 | ||
328 | if (col < fcol) { | 355 | if (col < fcol) { |
329 | for(int c = fcol; c > col; c--) { | 356 | for(int c = fcol; c > col; c--) { |
330 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; | 357 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; |
331 | updateCell(row, c, false); | 358 | updateCell(row, c, false); |
332 | } | 359 | } |
333 | } | 360 | } |
334 | else if (col > fcol) { | 361 | else if (col > fcol) { |
335 | for(int c = fcol; c < col; c++) { | 362 | for(int c = fcol; c < col; c++) { |
336 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; | 363 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; |
337 | updateCell(row, c, false); | 364 | updateCell(row, c, false); |
338 | } | 365 | } |
339 | } | 366 | } |
340 | } | 367 | } |
341 | // cols match -> shift pieces | 368 | // cols match -> shift pieces |
diff --git a/noncore/games/fifteen/fifteen.h b/noncore/games/fifteen/fifteen.h index 703a8a7..58eb756 100644 --- a/noncore/games/fifteen/fifteen.h +++ b/noncore/games/fifteen/fifteen.h | |||
@@ -1,83 +1,89 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the 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 | #ifndef __fifteenapplet_h__ | 21 | #ifndef __fifteenapplet_h__ |
22 | #define __fifteenapplet_h__ | 22 | #define __fifteenapplet_h__ |
23 | 23 | ||
24 | #include <qmainwindow.h> | 24 | #include <qmainwindow.h> |
25 | #include <qtableview.h> | 25 | #include <qtableview.h> |
26 | #include <qarray.h> | 26 | #include <qarray.h> |
27 | #include <qpointarray.h> | ||
27 | 28 | ||
28 | class QPopupMenu; | 29 | class QPopupMenu; |
29 | 30 | ||
30 | class PiecesTable : public QTableView | 31 | class PiecesTable : public QTableView |
31 | { | 32 | { |
32 | Q_OBJECT | 33 | Q_OBJECT |
33 | 34 | ||
34 | public: | 35 | public: |
35 | PiecesTable(QWidget* parent = 0, const char* name = 0); | 36 | PiecesTable(QWidget* parent = 0, const char* name = 0); |
36 | ~PiecesTable(); | 37 | ~PiecesTable(); |
37 | 38 | ||
38 | protected slots: | 39 | protected slots: |
39 | void slotRandomize(); | 40 | void slotRandomize(); |
40 | void slotReset(); | 41 | void slotReset(); |
41 | 42 | ||
42 | protected: | 43 | protected: |
43 | void resizeEvent(QResizeEvent*); | 44 | void resizeEvent(QResizeEvent*); |
44 | void mousePressEvent(QMouseEvent*); | 45 | void mousePressEvent(QMouseEvent*); |
45 | 46 | ||
46 | void paintCell(QPainter *, int row, int col); | 47 | void paintCell(QPainter *, int row, int col); |
47 | 48 | ||
48 | void initMap(); | 49 | void initMap(); |
49 | void initColors(); | 50 | void initColors(); |
50 | void randomizeMap(); | 51 | void randomizeMap(); |
51 | void checkwin(); | 52 | void checkwin(); |
52 | void readConfig(); | 53 | void readConfig(); |
53 | void writeConfig(); | 54 | void writeConfig(); |
54 | 55 | ||
55 | private: | 56 | private: |
56 | QArray<int> _map; | 57 | QArray<int> _map; |
57 | QArray<QColor> _colors; | 58 | QArray<QColor> _colors; |
58 | QPopupMenu *_menu; | 59 | QPopupMenu *_menu; |
59 | bool _randomized; | 60 | bool _randomized; |
61 | QPointArraylight_border; | ||
62 | QPointArraydark_border; | ||
60 | 63 | ||
61 | enum MenuOp { mRandomize = 1, mReset = 2 }; | 64 | enum MenuOp { mRandomize = 1, mReset = 2 }; |
62 | }; | 65 | }; |
63 | 66 | ||
64 | class FifteenWidget : public QWidget | 67 | class FifteenWidget : public QWidget |
65 | { | 68 | { |
66 | Q_OBJECT | 69 | Q_OBJECT |
67 | 70 | ||
68 | public: | 71 | public: |
69 | FifteenWidget(QWidget *parent = 0, const char *name = 0); | 72 | FifteenWidget(QWidget *parent = 0, const char *name = 0); |
70 | 73 | ||
71 | private: | 74 | private: |
72 | PiecesTable *_table; | 75 | PiecesTable *_table; |
73 | }; | 76 | }; |
74 | 77 | ||
75 | class FifteenMainWindow : public QMainWindow | 78 | class FifteenMainWindow : public QMainWindow |
76 | { | 79 | { |
77 | Q_OBJECT | 80 | Q_OBJECT |
78 | 81 | ||
79 | public: | 82 | public: |
80 | FifteenMainWindow(QWidget *parent=0, const char* name=0); | 83 | static QString appName() { |
84 | return QString::fromLatin1("fifteen"); | ||
85 | } | ||
86 | FifteenMainWindow(QWidget *parent=0, const char* name=0, WFlags fl=0); | ||
81 | }; | 87 | }; |
82 | 88 | ||
83 | #endif | 89 | #endif |
diff --git a/noncore/games/fifteen/fifteen.pro b/noncore/games/fifteen/fifteen.pro index 43d336d..14ea3c9 100644 --- a/noncore/games/fifteen/fifteen.pro +++ b/noncore/games/fifteen/fifteen.pro | |||
@@ -1,12 +1,10 @@ | |||
1 | DESTDIR = $(OPIEDIR)/bin | 1 | CONFIG = qt warn_on release quick-app |
2 | TEMPLATE= app | ||
3 | CONFIG = qt warn_on release | ||
4 | HEADERS = fifteen.h | 2 | HEADERS = fifteen.h |
5 | SOURCES = fifteen.cpp \ | 3 | SOURCES = fifteen.cpp \ |
6 | main.cpp | 4 | main.cpp |
7 | INCLUDEPATH += $(OPIEDIR)/include | 5 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH+= $(OPIEDIR)/include | 6 | DEPENDPATH+= $(OPIEDIR)/include |
9 | LIBS += -lqpe | 7 | LIBS += -lqpe |
10 | TARGET = fifteen | 8 | TARGET = fifteen |
11 | 9 | ||
12 | include ( $(OPIEDIR)/include.pro ) | 10 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/games/fifteen/main.cpp b/noncore/games/fifteen/main.cpp index 4838a36..74a7368 100644 --- a/noncore/games/fifteen/main.cpp +++ b/noncore/games/fifteen/main.cpp | |||
@@ -1,33 +1,23 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2004 Holger Freyther. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Opie 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 | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | 16 | **********************************************************************/ |
20 | 17 | ||
21 | #include "fifteen.h" | 18 | #include "fifteen.h" |
22 | 19 | ||
23 | #include <qpe/qpeapplication.h> | 20 | #include <opie/oapplicationfactory.h> |
21 | |||
22 | OPIE_EXPORT_APP( OApplicationFactory<FifteenMainWindow> ) | ||
24 | 23 | ||
25 | int main( int argc, char ** argv) | ||
26 | { | ||
27 | QPEApplication app( argc, argv ); | ||
28 | |||
29 | FifteenMainWindow mw; | ||
30 | mw.setCaption( FifteenMainWindow::tr("Fifteen Pieces") ); | ||
31 | app.showMainWidget( &mw ); | ||
32 | return app.exec(); | ||
33 | } | ||