Graphics Reference
In-Depth Information
MemoryGame Breakdown
I
m going to skip past explaining the imports for the MemoryGame
class, and I
'
ll just quickly go over the variables that are declared
at the top. The first variables are a couple of publicly available
constants that will be used later to help the engine determine the
pattern in which to layout the cards. The ones I
'
ve included are
GRID_LAYOUT (to place the cards in a grid pattern) and CUSTOM_LAYOUT
(used when you want to pass in your own set of coordinates for
each card). The rest of the variables are private, and while I tried to
make their names self-explanatory, let
'
'
s still take a quick look at
them in Table 13.1.
Now, let
s move on to the MemoryGame constructor. The
constructor calls for three parameters ( cards , cardBack ,and spread )
with two of them being optional (see Table 13.2 for more details).
Once inside the constructor, we
'
ll assign the length of the cards Array
to a new variable called cardsLen .Justthesameasbefore,we
'
'
re
assigning it to a variable, so the virtual machine doesn
thavetogo
and get the length of the array each and every time it goes through the
upcoming for loop.
Up next is a nested for loop that creates duplicates of all the
cards in the cards Array. The whole reason I set it up this way was
in case I wanted to create some new kind of game where you had to
match more than two identical cards. By changing the 2 in the outer
for loop ( for(var d:int=0; d < 2; d++) ) to a variable, you could set it
'
Table 13.1 The Private Variables of the
MemoryGame Class
Variable
Use
_cardsToCompare (Array)
Holds the two cards that are being compared for a match
_memoryCards (DeckArray)
The deck of cards
_numberOfCards (uint)
How many cards are in the deck
_cardPadding (int)
The number of pixels between each card that is placed on the stage
_matchesComplete (int)
How many cards the player has matched
_tempCard (Class)
The raw Class representation of the front of each individual card
_frontBmd (BitmapData)
The BitmapData for the front of each individual card
_frontSkin (Bitmap)
The Bitmap representation of the front of each individual card
_tempCardBack (Class)
The raw Class representation of the back of each individual card
_backBmd (BitmapData)
The BitmapData for the back of each individual card
_backSkin (Bitmap)
The Bitmap representation of the back of each individual card
_allowClick (Boolean)
Determines whether or not the user should be able to click on a card
Search WWH ::




Custom Search