author | zecke <zecke> | 2004-02-06 12:14:56 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-06 12:14:56 (UTC) |
commit | 0c74629e8f5c12a9b5a282b817f884fa10dee491 (patch) (unidiff) | |
tree | 3294663b92023f8d24d68a01022e011a3c94002d /noncore/games/minesweep/minefield.cpp | |
parent | 46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25 (diff) | |
download | opie-0c74629e8f5c12a9b5a282b817f884fa10dee491.zip opie-0c74629e8f5c12a9b5a282b817f884fa10dee491.tar.gz opie-0c74629e8f5c12a9b5a282b817f884fa10dee491.tar.bz2 |
Merge from the 1.0.x release
Diffstat (limited to 'noncore/games/minesweep/minefield.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/minesweep/minefield.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/games/minesweep/minefield.cpp b/noncore/games/minesweep/minefield.cpp index eca1a36..04cfb97 100644 --- a/noncore/games/minesweep/minefield.cpp +++ b/noncore/games/minesweep/minefield.cpp | |||
@@ -308,97 +308,97 @@ MineField::~MineField() | |||
308 | if ( mines ) | 308 | if ( mines ) |
309 | { | 309 | { |
310 | for ( i = 0; i < numCols*numRows; i++ ) | 310 | for ( i = 0; i < numCols*numRows; i++ ) |
311 | { | 311 | { |
312 | delete mines[i]; | 312 | delete mines[i]; |
313 | } | 313 | } |
314 | delete[] mines; | 314 | delete[] mines; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | 317 | ||
318 | void MineField::setState( State st ) | 318 | void MineField::setState( State st ) |
319 | { | 319 | { |
320 | stat = st; | 320 | stat = st; |
321 | } | 321 | } |
322 | 322 | ||
323 | void MineField::setup( int level ) | 323 | void MineField::setup( int level ) |
324 | { | 324 | { |
325 | lev = level; | 325 | lev = level; |
326 | setState( Waiting ); | 326 | setState( Waiting ); |
327 | //viewport()->setUpdatesEnabled( FALSE ); | 327 | //viewport()->setUpdatesEnabled( FALSE ); |
328 | 328 | ||
329 | int i; | 329 | int i; |
330 | if ( mines ) | 330 | if ( mines ) |
331 | { | 331 | { |
332 | for ( i = 0; i < numCols*numRows; i++ ) | 332 | for ( i = 0; i < numCols*numRows; i++ ) |
333 | { | 333 | { |
334 | delete mines[i]; | 334 | delete mines[i]; |
335 | } | 335 | } |
336 | delete[] mines; | 336 | delete[] mines; |
337 | } | 337 | } |
338 | 338 | ||
339 | switch( lev ) { | 339 | switch( lev ) { |
340 | case 1: | 340 | case 1: |
341 | numRows = 9 ; | 341 | numRows = 9 ; |
342 | numCols = 9 ; | 342 | numCols = 9 ; |
343 | minecount = 12; | 343 | minecount = 12; |
344 | break; | 344 | break; |
345 | case 2: | 345 | case 2: |
346 | numRows = 16; | 346 | numRows = 16; |
347 | numCols = 16; | 347 | numCols = 16; |
348 | minecount = 45; | 348 | minecount = 45; |
349 | break; | 349 | break; |
350 | case 3: | 350 | case 3: |
351 | numCols = 18; | 351 | numCols = 18; |
352 | numRows = 18; | 352 | numRows = 18; |
353 | minecount = 66 ; | 353 | minecount = 66 ; |
354 | break; | 354 | break; |
355 | } | 355 | } |
356 | mines = new (Mine*)[numRows*numCols]; | 356 | mines = new Mine*[numRows*numCols]; |
357 | for ( i = 0; i < numCols*numRows; i++ ) | 357 | for ( i = 0; i < numCols*numRows; i++ ) |
358 | mines[i] = new Mine( this ); | 358 | mines[i] = new Mine( this ); |
359 | 359 | ||
360 | 360 | ||
361 | nonminecount = numRows*numCols - minecount; | 361 | nonminecount = numRows*numCols - minecount; |
362 | mineguess = minecount; | 362 | mineguess = minecount; |
363 | emit mineCount( mineguess ); | 363 | emit mineCount( mineguess ); |
364 | Mine::paletteChange(); | 364 | Mine::paletteChange(); |
365 | 365 | ||
366 | if ( availableRect.isValid() ) | 366 | if ( availableRect.isValid() ) |
367 | setCellSize(findCellSize()); | 367 | setCellSize(findCellSize()); |
368 | // viewport()->setUpdatesEnabled( TRUE ); | 368 | // viewport()->setUpdatesEnabled( TRUE ); |
369 | //viewport()->repaint( TRUE ); | 369 | //viewport()->repaint( TRUE ); |
370 | updateContents( 0, 0, numCols*cellSize, numRows*cellSize ); | 370 | updateContents( 0, 0, numCols*cellSize, numRows*cellSize ); |
371 | updateGeometry(); | 371 | updateGeometry(); |
372 | } | 372 | } |
373 | 373 | ||
374 | void MineField::drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ) | 374 | void MineField::drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ) |
375 | { | 375 | { |
376 | int c1 = clipx / cellSize; | 376 | int c1 = clipx / cellSize; |
377 | int c2 = ( clipx + clipw - 1 ) / cellSize; | 377 | int c2 = ( clipx + clipw - 1 ) / cellSize; |
378 | int r1 = clipy / cellSize; | 378 | int r1 = clipy / cellSize; |
379 | int r2 = ( clipy + cliph - 1 ) / cellSize; | 379 | int r2 = ( clipy + cliph - 1 ) / cellSize; |
380 | 380 | ||
381 | for ( int c = c1; c <= c2 ; c++ ) { | 381 | for ( int c = c1; c <= c2 ; c++ ) { |
382 | for ( int r = r1; r <= r2 ; r++ ) { | 382 | for ( int r = r1; r <= r2 ; r++ ) { |
383 | int x = c * cellSize; | 383 | int x = c * cellSize; |
384 | int y = r * cellSize; | 384 | int y = r * cellSize; |
385 | Mine *m = mine( r, c ); | 385 | Mine *m = mine( r, c ); |
386 | if ( m ) | 386 | if ( m ) |
387 | m->paint( p, colorGroup(), QRect(x, y, cellSize, cellSize ) ); | 387 | m->paint( p, colorGroup(), QRect(x, y, cellSize, cellSize ) ); |
388 | } | 388 | } |
389 | } | 389 | } |
390 | } | 390 | } |
391 | 391 | ||
392 | 392 | ||
393 | // Chicken and egg problem: We need to know how big the parent is | 393 | // Chicken and egg problem: We need to know how big the parent is |
394 | // before we can decide how big to make the table. | 394 | // before we can decide how big to make the table. |
395 | 395 | ||
396 | void MineField::setAvailableRect( const QRect &r ) | 396 | void MineField::setAvailableRect( const QRect &r ) |
397 | { | 397 | { |
398 | availableRect = r; | 398 | availableRect = r; |
399 | int newCellSize = findCellSize(); | 399 | int newCellSize = findCellSize(); |
400 | if ( newCellSize != cellSize ) { | 400 | if ( newCellSize != cellSize ) { |
401 | viewport()->setUpdatesEnabled( FALSE ); | 401 | viewport()->setUpdatesEnabled( FALSE ); |
402 | setCellSize( newCellSize ); | 402 | setCellSize( newCellSize ); |
403 | viewport()->setUpdatesEnabled( TRUE ); | 403 | viewport()->setUpdatesEnabled( TRUE ); |
404 | viewport()->repaint( TRUE ); | 404 | viewport()->repaint( TRUE ); |