Prev | Current Page 734 | Next

Frank Zammetti

"Practical DWR 2 Projects"

playerFlippedTile1] ==
inMemoria.playerTileValues[inMemoria.playerFlippedTile2]) {
// Match, so do explosion.
inMemoria.playerExplosionFrame = 0;
inMemoria.playerExplosionDir = true;
inMemoria.playerExplosionInterval =
setInterval("inMemoria.cyclePlayerExplosion()", 100);
} else {
// No match, so pause for half a second and unflip them both.
setTimeout("inMemoria.unFlip(inMemoria.playerFlippedTile1, " +
"inMemoria.playerFlippedTile2, 'Player');", 500);
}
}
}
} // End tileClick().
So, it??™s the longest method in this class, but it really isn??™t all that difficult to follow, I think.
As we do so, keep in mind that this method is ???attached??? as the onClick handler to all the tiles
in the player??™s grid. This will be important to keep in mind because it gives you the correct
context of the this keyword.
First, we do a quick rejection: if the playerProcessClicks field isn??™t set to true, we abort
this method by returning immediately from it. This takes care of the player trying to click tiles
before a game is actually in progress, and also when nonmatching tiles are being unflipped or
when matching tiles are being exploded. Next, we take the value of the id attribute of this tile
and split it on the underscore character.


Pages:
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746