Game Development Reference
In-Depth Information
The Memory Class
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import gs.TweenMax;
import gs.easing.*;
public class Memory extends Sprite {
re making use of the TweenMax classes here, we
need to be sure to import them for our use. In this example, we
importthemainclass,TweenMax,andtheentireeasingequation
set. We won
Because we
'
s helpful to have them all
available so we can select just the right look and feel.
'
t use every equation, but it
'
protected var _cardList:Vector.
<
MemoryCard
>
;
protected var _selectedCards:Vector.
<
MemoryCard
>
;
public function Memory() {
addEventListener(Event.ADDED_TO_STAGE, addedToStage,
false, 0, true);
}
protected function addedToStage(e:Event):void {
_cardList = new Vector. < MemoryCard > ();
_selectedCards = new Vector. < MemoryCard > (2);
for (var i:int = 0; i < numChildren; i++) {
if (getChildAt(i) is MemoryCard) {
_cardList.push(getChildAt(i) as MemoryCard);
}
}
shuffleCards();
activateCards();
}
When the class is instantiated, it creates a list of all the cards on
the stage and stores them in a vector. It also creates another vector
of length 2 that will store up to two cards that have been clicked.
The game then shuffles and activates the cards, which we will look
at next.
protected function shuffleCards():void {
var shuffledList:Vector.
<
MemoryCard
>
= new Vector.
();
while (_cardList.length
<
MemoryCard
>
0) {
var rand:int = Math.round(Math.random()*(_cardList.
length-1));
>
Search Nedrilad ::




Custom Search