- There are 6 images used. There are 6 pairs of each template, making (6 x 6 = 36) cards to be flipped. These are arranged in a 6 x 6 grid.
- Each element in the
cards
array will use a randomly determined image. AWhile
loop nested within aFor
loop incrementally assigns all elements in thecards
array till alltemplate
properties are no longerundefined
. isMatched
,isFlipping
andisOpened
are allfalse
.
- The
flipCard()
method is called when the user clicks on a card.
- the card's
isFlipping
property is set totrue
ifisMatched
isfalse
. - if
isOpened
istrue
, the card is closed.isFlipping
andisOpened
is set tofalse
. - if
isOpened
isfalse
, the card is opened.isFlipping
is set tofalse
andisOpened
is set totrue
.- if there is another card whose
isOpened
property istrue
, compare the two cards. If theirtemplate
properties have the same value, they match. SetisMatched
to true. - if they do not match, close both cards.
- if there is another card whose
- Whether opening or closing cards, the flipping animation is introduced to provide a slight delay so that the user can see the card images.
- If
seconds
(which decrements every second) reaches 0 and there are elements incards
whoseisMatched
property isfalse
, the game ends in failure. - If there are no elements in
cards
whoseisMatched
property isfalse
, the game ends in success regardless of the value ofseconds
.