1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
46
47
48
49
50
51
52
53
54
58
59
60
61
65
66
67
68
69
70
71
72
73
84
85
86
87
88
89
90
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
130
131
137
138
139
140
141
142
143
151
152
156
160
161
162
163
177
178
179
180
181
182
192
193
197
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
272
273
278
279
280
281
282
283
287
288
296
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
341
342
343
344
345
346
347
348
349
351
353
355
357
359
361
363
365
367
369
371
373
374
376
377
378
379
380
381
382
383
384
385
386
389
393
397
401
405
409
413
417
421
425
429
432
433
436
437
438
439
440
441
442
453
454
455
456
457
466
467
468
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
601
602
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
672
676
680
684
685
686
687
688
689
690
/* ... */
#include <gui/game2048_screen/GameBoard.hpp>
#include <BitmapDatabase.hpp>
#include <gui/common/Utils.hpp>
GameBoard::GameBoard() :
currentAnimationState(NO_ANIMATION),
score(0),
moveCompletedAction(0),
gameWonAction(0),
gameLostAction(0),
dragX(0),
dragY(0),
autoPlay(false),
tileMoveEndedCallback(this, &GameBoard::tileMoveEndedHandler)
{
setTouchable(true);
tileOffset = Bitmap(BITMAP_TILE_0002_ID).getWidth() + TILE_SPACING;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
tiles[i][j] = &tilesAlloc[i][j];
tiles[i][j]->image.setAnimationEndedCallback(tileMoveEndedCallback);
add(tiles[i][j]->image);
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
initiateNewGame();
updateBoard();
setWidth(470);
setHeight(480);
}{ ... }
GameBoard::~GameBoard()
{
touchgfx::Application::getInstance()->unregisterTimerWidget(this);
}{ ... }
void GameBoard::handleClickEvent(const ClickEvent& evt)
{
if (currentAnimationState != NO_ANIMATION)
{
return;
}if (currentAnimationState != NO_ANIMATION) { ... }
if (evt.getType() == ClickEvent::RELEASED)
{
int xDragDistance = (dragX < 0) ? -dragX : dragX;
int yDragDistance = (dragY < 0) ? -dragY : dragY;
int maxDragDistance = (yDragDistance < xDragDistance) ? xDragDistance : yDragDistance;
if (maxDragDistance > DRAG_THRESHOLD)
{
if (xDragDistance > yDragDistance)
{
(dragX > 0) ? moveTilesRight(true) : moveTilesLeft(true);
}if (xDragDistance > yDragDistance) { ... }
else
{
(dragY > 0) ? moveTilesDown(true) : moveTilesUp(true);
}else { ... }
}if (maxDragDistance > DRAG_THRESHOLD) { ... }
dragX=0;
dragY=0;
}if (evt.getType() == ClickEvent::RELEASED) { ... }
}{ ... }
void GameBoard::handleDragEvent(const DragEvent& evt)
{
dragX += evt.getDeltaX();
dragY += evt.getDeltaY();
}{ ... }
/* ... */
void GameBoard::updateBoard()
{
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
tiles[i][j]->image.moveTo(20 + j*tileOffset, 25 + i*tileOffset);
updateTile(tiles[i][j]);
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
}{ ... }
void GameBoard::updateTile(Tile* tile)
{
tile->image.setVisible(tile->state != TILE_EMPTY);
tile->image.setBitmaps(getBitmapForTileState(tile->state), getBitmapForTileState(tile->state));
tile->image.invalidate();
}{ ... }
void GameBoard::initiateNewGame()
{
gameStatus = ACTIVE;
score = 0;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
tiles[i][j]->state = TILE_EMPTY;
tiles[i][j]->isPromoted = false;
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
if (hasEmptyTile())
{
getRandomEmptyTile()->state = getStartTileState();
}if (hasEmptyTile()) { ... }
if (hasEmptyTile())
{
getRandomEmptyTile()->state = getStartTileState();
}if (hasEmptyTile()) { ... }
updateBoard();
}{ ... }
bool GameBoard::hasEmptyTile()
{
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
if (tiles[i][j]->state == TILE_EMPTY)
{
return true;
}if (tiles[i][j]->state == TILE_EMPTY) { ... }
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
return false;
}{ ... }
GameBoard::Tile* GameBoard::getRandomEmptyTile()
{
int numberOfEmptyTiles = 0;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
if (tiles[i][j]->state == TILE_EMPTY)
{
numberOfEmptyTiles++;
}if (tiles[i][j]->state == TILE_EMPTY) { ... }
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
if (numberOfEmptyTiles == 0)
{
return 0;
}if (numberOfEmptyTiles == 0) { ... }
else
{
int randomEmptyTile = Utils::randomNumberBetween(0, numberOfEmptyTiles);
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
if (tiles[i][j]->state == TILE_EMPTY)
{
if (randomEmptyTile-- == 0)
{
return tiles[i][j];
}if (randomEmptyTile-- == 0) { ... }
}if (tiles[i][j]->state == TILE_EMPTY) { ... }
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
}else { ... }
return 0;
}{ ... }
bool GameBoard::moveTileTo(int fromX, int fromY, int toX, int toY, bool performMove)
{
if (fromX != toX || fromY != toY)
{
tiles[toY][toX]->state = tiles[fromY][fromX]->state;
tiles[fromY][fromX]->state = TILE_EMPTY;
if (performMove)
{
remove(tiles[fromY][fromX]->image);
add(tiles[fromY][fromX]->image);
tiles[fromY][fromX]->image.startZoomAndMoveAnimation(tiles[toY][toX]->image.getX(), tiles[toY][toX]->image.getY(), tiles[toY][toX]->image.getWidth(), tiles[toY][toX]->image.getHeight(), TILE_MOVE_DURATION, ZoomAnimationImage::FIXED_LEFT_AND_TOP, EasingEquations::cubicEaseIn, EasingEquations::cubicEaseIn);
currentAnimationState = ANIMATE_TILE_MOVEMENT;
}if (performMove) { ... }
return true;
}if (fromX != toX || fromY != toY) { ... }
return false;
}{ ... }
void GameBoard::tileMoveEndedHandler(const ZoomAnimationImage& image)
{
if (currentAnimationState == ANIMATE_TILE_MOVEMENT && getNumberOfAnimatingTiles() == 0)
{
updateBoard();
currentAnimationState = NO_ANIMATION;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
if (tiles[i][j]->isPromoted)
{
int imageWidth = Bitmap(BITMAP_TILE_0002_ID).getWidth();
int imageHeight = Bitmap(BITMAP_TILE_0002_ID).getHeight();
tiles[i][j]->image.setPosition(tiles[i][j]->image.getX() + (imageWidth-50)/2, tiles[i][j]->image.getY() + (imageHeight-50)/2, 50, 50);
tiles[i][j]->image.startZoomAnimation(imageWidth, imageHeight, 6, ZoomAnimationImage::FIXED_CENTER, EasingEquations::backEaseInOut, EasingEquations::backEaseInOut);
tiles[i][j]->isPromoted = false;
currentAnimationState = ANIMATE_PROMOTION;
}if (tiles[i][j]->isPromoted) { ... }
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
if (currentAnimationState == NO_ANIMATION)
{
insertRandomTile();
}if (currentAnimationState == NO_ANIMATION) { ... }
}if (currentAnimationState == ANIMATE_TILE_MOVEMENT && getNumberOfAnimatingTiles() == 0) { ... }
else if (currentAnimationState == ANIMATE_PROMOTION && getNumberOfAnimatingTiles() == 0)
{
insertRandomTile();
}else if (currentAnimationState == ANIMATE_PROMOTION && getNumberOfAnimatingTiles() == 0) { ... }
else if (currentAnimationState == ANIMATE_INSERT_RANDOM_TILE && getNumberOfAnimatingTiles() == 0)
{
currentAnimationState = NO_ANIMATION;
if (moveCompletedAction && moveCompletedAction->isValid())
{
moveCompletedAction->execute(*this);
}if (moveCompletedAction && moveCompletedAction->isValid()) { ... }
if (hasGameBeenWon())
{
gameStatus = WON;
if (gameWonAction && gameWonAction->isValid())
{
gameWonAction->execute(*this);
}if (gameWonAction && gameWonAction->isValid()) { ... }
}if (hasGameBeenWon()) { ... }
else if (hasGameBeenLost())
{
gameStatus = LOST;
if (gameLostAction && gameLostAction->isValid())
{
gameLostAction->execute(*this);
}if (gameLostAction && gameLostAction->isValid()) { ... }
}else if (hasGameBeenLost()) { ... }
}else if (currentAnimationState == ANIMATE_INSERT_RANDOM_TILE && getNumberOfAnimatingTiles() == 0) { ... }
}{ ... }
void GameBoard::insertRandomTile()
{
Tile* newTile = getRandomEmptyTile();
if (newTile)
{
newTile->state = getStartTileState();
updateTile(newTile);
int imageWidth = Bitmap(BITMAP_TILE_0002_ID).getWidth();
int imageHeight = Bitmap(BITMAP_TILE_0002_ID).getHeight();
newTile->image.setPosition(newTile->image.getX() + imageWidth/2, newTile->image.getY() + imageHeight/2, 0, 0);
newTile->image.startZoomAnimation(imageWidth, imageHeight, 8, ZoomAnimationImage::FIXED_CENTER, EasingEquations::cubicEaseInOut, EasingEquations::cubicEaseInOut);
currentAnimationState = ANIMATE_INSERT_RANDOM_TILE;
}if (newTile) { ... }
}{ ... }
int GameBoard::getNumberOfAnimatingTiles()
{
int result = 0;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
if (tiles[i][j]->image.isRunning())
{
result++;
}if (tiles[i][j]->image.isRunning()) { ... }
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
return result;
}{ ... }
Bitmap GameBoard::getBitmapForTileState(TileState tileState)
{
switch (tileState)
{
case GameBoard::TILE_EMPTY:
return Bitmap(BITMAP_TILE_0002_ID);case GameBoard::TILE_EMPTY:
case GameBoard::TILE_0002:
return Bitmap(BITMAP_TILE_0002_ID);case GameBoard::TILE_0002:
case GameBoard::TILE_0004:
return Bitmap(BITMAP_TILE_0004_ID);case GameBoard::TILE_0004:
case GameBoard::TILE_0008:
return Bitmap(BITMAP_TILE_0008_ID);case GameBoard::TILE_0008:
case GameBoard::TILE_0016:
return Bitmap(BITMAP_TILE_0016_ID);case GameBoard::TILE_0016:
case GameBoard::TILE_0032:
return Bitmap(BITMAP_TILE_0032_ID);case GameBoard::TILE_0032:
case GameBoard::TILE_0064:
return Bitmap(BITMAP_TILE_0064_ID);case GameBoard::TILE_0064:
case GameBoard::TILE_0128:
return Bitmap(BITMAP_TILE_0128_ID);case GameBoard::TILE_0128:
case GameBoard::TILE_0256:
return Bitmap(BITMAP_TILE_0256_ID);case GameBoard::TILE_0256:
case GameBoard::TILE_0512:
return Bitmap(BITMAP_TILE_0512_ID);case GameBoard::TILE_0512:
case GameBoard::TILE_1024:
return Bitmap(BITMAP_TILE_1024_ID);case GameBoard::TILE_1024:
case GameBoard::TILE_2048:
return Bitmap(BITMAP_TILE_2048_ID);case GameBoard::TILE_2048:
case GameBoard::NUMBER_OF_TILE_STATES:
default:
return Bitmap(BITMAP_TILE_0002_ID);default
}switch (tileState) { ... }
}{ ... }
void GameBoard::promoteTile(int x, int y)
{
TileState promotedState;
switch (tiles[y][x]->state)
{
case GameBoard::TILE_EMPTY:
promotedState = TILE_0002;
break;case GameBoard::TILE_EMPTY:
case GameBoard::TILE_0002:
promotedState = TILE_0004;
score += 4;
break;case GameBoard::TILE_0002:
case GameBoard::TILE_0004:
promotedState = TILE_0008;
score += 8;
break;case GameBoard::TILE_0004:
case GameBoard::TILE_0008:
promotedState = TILE_0016;
score += 16;
break;case GameBoard::TILE_0008:
case GameBoard::TILE_0016:
promotedState = TILE_0032;
score += 32;
break;case GameBoard::TILE_0016:
case GameBoard::TILE_0032:
promotedState = TILE_0064;
score += 64;
break;case GameBoard::TILE_0032:
case GameBoard::TILE_0064:
promotedState = TILE_0128;
score += 128;
break;case GameBoard::TILE_0064:
case GameBoard::TILE_0128:
promotedState = TILE_0256;
score += 256;
break;case GameBoard::TILE_0128:
case GameBoard::TILE_0256:
promotedState = TILE_0512;
score += 512;
break;case GameBoard::TILE_0256:
case GameBoard::TILE_0512:
promotedState = TILE_1024;
score += 1024;
break;case GameBoard::TILE_0512:
case GameBoard::TILE_1024:
promotedState = TILE_2048;
score += 2048;
break;case GameBoard::TILE_1024:
case GameBoard::TILE_2048:
promotedState = TILE_2048;
break;case GameBoard::TILE_2048:
case GameBoard::NUMBER_OF_TILE_STATES:
default:
promotedState = TILE_0002;
break;default
}switch (tiles[y][x]->state) { ... }
tiles[y][x]->state = promotedState;
tiles[y][x]->isPromoted = true;
}{ ... }
GameBoard::TileState GameBoard::getStartTileState()
{
if (Utils::randomNumberBetween(0, 100) < 75)
{
return GameBoard::TILE_0002;
}if (Utils::randomNumberBetween(0, 100) < 75) { ... }
else
{
return GameBoard::TILE_0004;
}else { ... }
}{ ... }
void GameBoard::rotateBoard()
{
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = i; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
Tile* temp = tiles[i][j];
tiles[i][j] = tiles[j][i];
tiles[j][i] = temp;
}for (int j = i; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES/2; j++)
{
Tile* temp = tiles[i][j];
tiles[i][j] = tiles[i][NUMBER_OF_HORIZONTAL_TILES - j - 1];
tiles[i][NUMBER_OF_HORIZONTAL_TILES - j - 1]= temp;
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES/2; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
}{ ... }
int GameBoard::moveTilesRight(bool performMove)
{
int numberOfTilesMoved = 0;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
int lastActiveTile = NUMBER_OF_HORIZONTAL_TILES - 1;
for (int j = NUMBER_OF_HORIZONTAL_TILES - 2; j >= 0; j--)
{
if (tiles[i][j]->state != TILE_EMPTY)
{
for (int j2 = j+1; j2 <= lastActiveTile; j2++)
{
if (tiles[i][j2]->state == tiles[i][j]->state )
{
numberOfTilesMoved += moveTileTo(j, i, j2, i, performMove);
promoteTile(j2, i);
lastActiveTile = j2 - 1;
break;
}if (tiles[i][j2]->state == tiles[i][j]->state) { ... }
else if (tiles[i][j2]->state != TILE_EMPTY && tiles[i][j2]->state != tiles[i][j]->state)
{
numberOfTilesMoved += moveTileTo(j, i, j2 - 1, i, performMove);
lastActiveTile = j2 - 1;
break;
}else if (tiles[i][j2]->state != TILE_EMPTY && tiles[i][j2]->state != tiles[i][j]->state) { ... }
else if (tiles[i][j2]->state == TILE_EMPTY && j2 == lastActiveTile)
{
numberOfTilesMoved += moveTileTo(j, i, j2, i, performMove);
lastActiveTile = j2;
break;
}else if (tiles[i][j2]->state == TILE_EMPTY && j2 == lastActiveTile) { ... }
}for (int j2 = j+1; j2 <= lastActiveTile; j2++) { ... }
}if (tiles[i][j]->state != TILE_EMPTY) { ... }
}for (int j = NUMBER_OF_HORIZONTAL_TILES - 2; j >= 0; j--) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
return numberOfTilesMoved;
}{ ... }
int GameBoard::moveTilesLeft(bool performMove)
{
rotateBoard();
rotateBoard();
int numberOfTilesMoved = moveTilesRight(performMove);
rotateBoard();
rotateBoard();
return numberOfTilesMoved;
}{ ... }
int GameBoard::moveTilesUp(bool performMove)
{
rotateBoard();
int numberOfTilesMoved = moveTilesRight(performMove);
rotateBoard();
rotateBoard();
rotateBoard();
return numberOfTilesMoved;
}{ ... }
int GameBoard::moveTilesDown(bool performMove)
{
rotateBoard();
rotateBoard();
rotateBoard();
int numberOfTilesMoved = moveTilesRight(performMove);
rotateBoard();
return numberOfTilesMoved;
}{ ... }
bool GameBoard::hasGameBeenWon()
{
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
if (tiles[i][j]->state == TILE_2048)
{
return true;
}if (tiles[i][j]->state == TILE_2048) { ... }
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
return false;
}{ ... }
bool GameBoard::hasGameBeenLost()
{
bool result = true;
takeStateBackup();
result &= (moveTilesRight(false) == 0);
restoreStateBackup();
result &= (moveTilesLeft(false) == 0);
restoreStateBackup();
result &= (moveTilesUp(false) == 0);
restoreStateBackup();
result &= (moveTilesDown(false) == 0);
restoreStateBackup();
return result;
}{ ... }
void GameBoard::takeStateBackup()
{
scoreBackup = score;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
tileStateBackup[i][j] = tiles[i][j]->state;
tilePromotionBackup[i][j] = tiles[i][j]->isPromoted;
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
}{ ... }
void GameBoard::restoreStateBackup()
{
score = scoreBackup;
for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++)
{
for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++)
{
tiles[i][j]->state = tileStateBackup[i][j];
tiles[i][j]->isPromoted = tilePromotionBackup[i][j];
}for (int j = 0; j < NUMBER_OF_HORIZONTAL_TILES; j++) { ... }
}for (int i = 0; i < NUMBER_OF_VERTICAL_TILES; i++) { ... }
}{ ... }
void GameBoard::handleTickEvent()
{
if (autoPlay && currentAnimationState == NO_ANIMATION && gameStatus == ACTIVE)
{
if (autoPlayPause-- == 0)
{
/* ... */
int move = 0;
int maxScore = 0;
int numberOfTilesMoved = 0;
takeStateBackup();
numberOfTilesMoved = moveTilesRight(false);
if (score >= maxScore && numberOfTilesMoved > 0) { move = 0; maxScore = score; }
restoreStateBackup();
numberOfTilesMoved = moveTilesLeft(false);
if (score >= maxScore && numberOfTilesMoved > 0) { move = 1; maxScore = score; }
restoreStateBackup();
numberOfTilesMoved = moveTilesUp(false);
if (score >= maxScore && numberOfTilesMoved > 0) { move = 2; maxScore = score; }
restoreStateBackup();
numberOfTilesMoved = moveTilesDown(false);
if (score >= maxScore && numberOfTilesMoved > 0) { move = 3; maxScore = score; }
restoreStateBackup();
if (move == 0)
{
moveTilesRight(true);
}if (move == 0) { ... }
else if (move == 1)
{
moveTilesLeft(true);
}else if (move == 1) { ... }
else if (move == 2)
{
moveTilesUp(true);
}else if (move == 2) { ... }
else if (move == 3)
{
moveTilesDown(true);
}else if (move == 3) { ... }
autoPlayPause = 14;
}if (autoPlayPause-- == 0) { ... }
}if (autoPlay && currentAnimationState == NO_ANIMATION && gameStatus == ACTIVE) { ... }
}{ ... }
void GameBoard::setAutoPlay(bool newAutoPlay)
{
autoPlay = newAutoPlay;
if (newAutoPlay)
{
autoPlayPause = 0;
touchgfx::Application::getInstance()->registerTimerWidget(this);
}if (newAutoPlay) { ... }
else
{
touchgfx::Application::getInstance()->unregisterTimerWidget(this);
}else { ... }
}{ ... }