author | zecke <zecke> | 2004-10-15 01:48:45 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-10-15 01:48:45 (UTC) |
commit | fefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0 (patch) (unidiff) | |
tree | a59a3bd9b5434657ee014dd6bbf7fbb50f5994d0 /noncore/games/zsame/StoneField.cpp | |
parent | 85ab1a8cc3935538cc1f33fef7c94ba31accb53e (diff) | |
download | opie-fefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0.zip opie-fefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0.tar.gz opie-fefeafe35f8dac30f4baab9e3bff8e2ffbd1afd0.tar.bz2 |
Fix #1450 to clear the 'bonus' for removing every stone in the game
Diffstat (limited to 'noncore/games/zsame/StoneField.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/zsame/StoneField.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/games/zsame/StoneField.cpp b/noncore/games/zsame/StoneField.cpp index 49d8eca..56e9dc5 100644 --- a/noncore/games/zsame/StoneField.cpp +++ b/noncore/games/zsame/StoneField.cpp | |||
@@ -259,132 +259,136 @@ StoneField::remove(int x,int y,bool force) { | |||
259 | if (field[map(col, row)].color) { | 259 | if (field[map(col, row)].color) { |
260 | empty = false; | 260 | empty = false; |
261 | break; | 261 | break; |
262 | } | 262 | } |
263 | if (!empty) { | 263 | if (!empty) { |
264 | col++; | 264 | col++; |
265 | continue; | 265 | continue; |
266 | } | 266 | } |
267 | int nextfullcol = col + 1; | 267 | int nextfullcol = col + 1; |
268 | while (nextfullcol < sizex && | 268 | while (nextfullcol < sizex && |
269 | !field[map(nextfullcol, sizey - 1)].color) | 269 | !field[map(nextfullcol, sizey - 1)].color) |
270 | nextfullcol++; | 270 | nextfullcol++; |
271 | 271 | ||
272 | if (nextfullcol > sizex - 1) | 272 | if (nextfullcol > sizex - 1) |
273 | break; // we're ready | 273 | break; // we're ready |
274 | 274 | ||
275 | for (int row=0; row < sizey; row++) { | 275 | for (int row=0; row < sizey; row++) { |
276 | int source = map(nextfullcol, row); | 276 | int source = map(nextfullcol, row); |
277 | int dest = map(col, row); | 277 | int dest = map(col, row); |
278 | field[dest].color=field[source].color; | 278 | field[dest].color=field[source].color; |
279 | field[dest].changed=true; | 279 | field[dest].changed=true; |
280 | field[source].color=0; | 280 | field[source].color=0; |
281 | field[source].changed=true; | 281 | field[source].changed=true; |
282 | } | 282 | } |
283 | } | 283 | } |
284 | 284 | ||
285 | // add a bonus, if field is empty | 285 | // add a bonus, if field is empty |
286 | if (!field[map(0, sizey-1)].color) { | 286 | if (!field[map(0, sizey-1)].color) { |
287 | score+=1000; | 287 | score+=1000; |
288 | m_gotBonus= true; | 288 | m_gotBonus= true; |
289 | } | 289 | } |
290 | 290 | ||
291 | // gameover is undefined | 291 | // gameover is undefined |
292 | gameover=-1; | 292 | gameover=-1; |
293 | return removed; | 293 | return removed; |
294 | } | 294 | } |
295 | 295 | ||
296 | bool StoneField::undoPossible() const { | 296 | bool StoneField::undoPossible() const { |
297 | return !(!undolist||undolist->isEmpty()); | 297 | return !(!undolist||undolist->isEmpty()); |
298 | } | 298 | } |
299 | 299 | ||
300 | int | 300 | int |
301 | StoneField::undo(int count) { | 301 | StoneField::undo(int count) { |
302 | if (!undoPossible()) | 302 | if (!undoPossible()) |
303 | return 0; | 303 | return 0; |
304 | if (count <= 0) | 304 | if (count <= 0) |
305 | return 0; | 305 | return 0; |
306 | int undocount=1; | 306 | int undocount=1; |
307 | StoneFieldState *state=0; | 307 | StoneFieldState *state=0; |
308 | undolist->setAutoDelete(true); | 308 | undolist->setAutoDelete(true); |
309 | while (--count>0) { | 309 | while (--count>0) { |
310 | if (undolist->count()==1) break; | 310 | if (undolist->count()==1) break; |
311 | undolist->removeLast(); | 311 | undolist->removeLast(); |
312 | undocount++; | 312 | undocount++; |
313 | } | 313 | } |
314 | state=undolist->getLast(); | 314 | state=undolist->getLast(); |
315 | // Q_ASSERT(state); | 315 | // Q_ASSERT(state); |
316 | state->restore(*this); | 316 | state->restore(*this); |
317 | undolist->removeLast(); | 317 | undolist->removeLast(); |
318 | return undocount; | 318 | return undocount; |
319 | } | 319 | } |
320 | 320 | ||
321 | bool | 321 | bool |
322 | StoneField::isGameover() const { | 322 | StoneField::isGameover() const { |
323 | register int i=maxstone-1;; | 323 | register int i=maxstone-1;; |
324 | register unsigned char color; | 324 | register unsigned char color; |
325 | 325 | ||
326 | if (gameover>=0) return (bool)gameover; | 326 | if (gameover>=0) return (bool)gameover; |
327 | // kdDebug() << "-->gameover" << endl; | 327 | // kdDebug() << "-->gameover" << endl; |
328 | 328 | ||
329 | while (i>=0) { | 329 | while (i>=0) { |
330 | // kdDebug() << i << " " << field[i].color << endl; | 330 | // kdDebug() << i << " " << field[i].color << endl; |
331 | // ignore empty fields | 331 | // ignore empty fields |
332 | while ( i>=0 && field[i].color==0 ) i--; | 332 | while ( i>=0 && field[i].color==0 ) i--; |
333 | // Wenn Stein gefunden, | 333 | // Wenn Stein gefunden, |
334 | // dann die Nachbarn auf gleiche Farbe pruefen. | 334 | // dann die Nachbarn auf gleiche Farbe pruefen. |
335 | while ( i>=0 && (color=field[i].color) ) { | 335 | while ( i>=0 && (color=field[i].color) ) { |
336 | // check left | 336 | // check left |
337 | if ( (i%sizex)!=0 && field[i-1].color==color) | 337 | if ( (i%sizex)!=0 && field[i-1].color==color) |
338 | goto check_gameover; | 338 | goto check_gameover; |
339 | // check upward | 339 | // check upward |
340 | if ( i>=sizex && field[i-sizex].color==color) | 340 | if ( i>=sizex && field[i-sizex].color==color) |
341 | goto check_gameover; | 341 | goto check_gameover; |
342 | i--; | 342 | i--; |
343 | } | 343 | } |
344 | } | 344 | } |
345 | check_gameover: | 345 | check_gameover: |
346 | gameover=(i<0); | 346 | gameover=(i<0); |
347 | // kdDebug() << "<--gameover" << endl; | 347 | // kdDebug() << "<--gameover" << endl; |
348 | return (bool)gameover; | 348 | return (bool)gameover; |
349 | } | 349 | } |
350 | 350 | ||
351 | bool StoneField::gotBonus() const { | 351 | bool StoneField::gotBonus() const { |
352 | return m_gotBonus; | 352 | return m_gotBonus; |
353 | } | 353 | } |
354 | 354 | ||
355 | void StoneField::clearBonus() { | ||
356 | m_gotBonus = false; | ||
357 | } | ||
358 | |||
355 | int | 359 | int |
356 | StoneField::getBoard() const { | 360 | StoneField::getBoard() const { |
357 | return board; | 361 | return board; |
358 | } | 362 | } |
359 | 363 | ||
360 | int | 364 | int |
361 | StoneField::getScore() const { | 365 | StoneField::getScore() const { |
362 | return score; | 366 | return score; |
363 | } | 367 | } |
364 | 368 | ||
365 | int | 369 | int |
366 | StoneField::getColors() const { | 370 | StoneField::getColors() const { |
367 | return colors; | 371 | return colors; |
368 | } | 372 | } |
369 | 373 | ||
370 | int | 374 | int |
371 | StoneField::getMarked() const { | 375 | StoneField::getMarked() const { |
372 | return marked; | 376 | return marked; |
373 | } | 377 | } |
374 | 378 | ||
375 | int | 379 | int |
376 | StoneField::getFieldSize() const { | 380 | StoneField::getFieldSize() const { |
377 | return maxstone; | 381 | return maxstone; |
378 | } | 382 | } |
379 | 383 | ||
380 | struct Stone * | 384 | struct Stone * |
381 | StoneField::getField() const { | 385 | StoneField::getField() const { |
382 | return field; | 386 | return field; |
383 | } | 387 | } |
384 | 388 | ||
385 | 389 | ||
386 | 390 | ||
387 | 391 | ||
388 | 392 | ||
389 | 393 | ||
390 | 394 | ||