JavaScript and Frames, Part II: Removing a Card - www.docjavascript.com | WebReference

JavaScript and Frames, Part II: Removing a Card - www.docjavascript.com


JavaScript and Frames, Part II (7)

Removing and Covering A Card

In this page we explain the remaining functions of the scripts, revealNow(), coverNow(), and removeCards(). They all involve a simple assignment of the src property of any frame's first (and single) image. Here is the listing for the revealNow() function:

function revealNow() {
top.frames[tobeRevealedCol].frames[tobeRevealedRow].document.images[0].src
     = pictures[assignAr[tobeRevealedLocation]];
}

As we explained earlier in this column, assignAr[tobeRevealedLocation] is the index into the pictures array of GIF file names. The frame is located by the its row and column positions, tobeRevealedRow, and tobeRevealedColumn, respectively.

The coverNow() function covers the two cards in a similar fashion:

function coverNow() {
  top.frames[tobeRevealedCol].frames[tobeRevealedRow].document.images[0].src
      = cover;
  top.frames[revealedCol].frames[revealedRow].document.images[0].src = cover;
  nowRevealed = false;
  blockClicking = false;
  if (nowPlaying == "left") nowPlaying = "right"
  else nowPlaying = "left";
}

The coverNow() function takes care of other maintenance work. It sets the nowRevealing variable to false, it tuns off the blockClicking to let the players continue the game, and it switches between the right and left players.

Finally, the removeCards() function removes the two cards (in case of a match):

function removeCards() {
 top.frames[tobeRevealedCol].frames[tobeRevealedRow].document.images[0].src
     = blank;
 top.frames[revealedCol].frames[revealedRow].document.images[0].src
     = blank;
 nowRevealed = false;
 blockClicking = false;
}


https://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: April 5, 1999
Revised: April 5, 1999

URL: https://www.webreference.com/js/column37/remove.html