Prev | Current Page 733 | Next

Frank Zammetti

"Practical DWR 2 Projects"

tileClick = function() {
// Abort if player clicks are blocked (during explosions and unflipping).
if (!inMemoria.playerProcessClicks) { return; }
// Get index of clicked tile.
var tileIndex = this.id.split("_")[1];
// No tile is currently flipped...
if (inMemoria.playerFlippedTile1 == null) {
// Set image based on tile value.
this.src =
inMemoria.tileImages[inMemoria.playerTileValues[tileIndex]].src;
// Record currently flipped.
inMemoria.playerFlippedTile1 = tileIndex;
// OK, a tile is already flipped, so...
} else {
// Is the tile already flipped the one that was clicked?
if (inMemoria.playerFlippedTile1 == tileIndex) {
CHAPTER 8 n DWR FOR FUN AND PROFIT (A DWR GAME!) 435
// Yes it was...unflip this, and any other flipped tile.
inMemoria.unFlip(inMemoria.playerFlippedTile1,
inMemoria.playerFlippedTile2, "Player");
} else {
// Nope, two tiles are now effectively flipped. First, show this one
// as flipped too and block any further player clicks for now.
inMemoria.playerProcessClicks = false;
inMemoria.playerFlippedTile2 = tileIndex;
this.src =
inMemoria.tileImages[inMemoria.playerTileValues[tileIndex]].src;
// Now, check for a match.
if (inMemoria.playerTileValues[inMemoria.


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