package {
import flash.display.*;
import flash.events.*;
import flash.ui.*;

public class Memory extends MovieClip
{
private var score, life:Number;
private var doLoseLife, gotoWin, gotoLose:Boolean;
private var firstCard, secondCard:Card;
private var cardValues, cards:Array;

public function Memory()
{

}

//All Start Functions
public function startMenu()
{
stop();
btnStartGame.addEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.addEventListener(MouseEvent.CLICK, gotoHowToPlay);
}

public function startHowToPlay()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}

public function startWin()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}

public function startLose()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}

public function startGame()
{
score = 0;
life = 10;
doLoseLife = false;
gotoWin = false;
gotoLose = false;
firstCard = null;
secondCard = null;
cards = new Array();

setupGame();

//Shuffle
cardValues = new Array(“card1″,”card1″,”card2″,”card2″,”c ard3″,”card3″,”card4″,”card4″,
“card5″,”card5″,”card6″,”card6″,”card7″, ”card7″);
for (var i=0; i<100; i++)
{
var swap1 = Math.floor(Math.random()*14);
var swap2 = Math.floor(Math.random()*14);

var tempValue = cardValues[swap1];
cardValues[swap1] = cardValues[swap2];
cardValues[swap2] = tempValue;
}

//Deal
for (var i=0; i<14; i++)
{
cards[i].hiddenValue = cardValues[i];
cards[i].addEventListener(MouseEvent.CLICK, flipCard);
}

addEventListener(Event.ENTER_FRAME,update);

stage.focus = this;
}

public function startLevel2()
{
life = 10;
doLoseLife = false;
gotoWin = false;
gotoLose = false;
firstCard = null;
secondCard = null;
cards = new Array();

setupGame();

//Shuffle
cardValues = new Array("card1","card1","card2","card2","card3","car d3","card4","card4",
"card5","card5","card6","card6","card7","card7","c ard8","card8");
for (var i=0; i<100; i++)
{
var swap1 = Math.floor(Math.random()*14);
var swap2 = Math.floor(Math.random()*14);

var tempValue = cardValues[swap1];
cardValues[swap1] = cardValues[swap2];
cardValues[swap2] = tempValue;
}

//Deal
for (var i=0; i<16; i++)
{
cards[i].hiddenValue = cardValues[i];
cards[i].addEventListener(MouseEvent.CLICK, flipCard);
}

addEventListener(Event.ENTER_FRAME,update);

stage.focus = this;
}

private function setupGame()
{
//Check the classes of the movieclips and push them into the
//appropriate arrays
for (var i=0; i= 70)
{
gotoAndStop(“level2″)
}
}
else if (currentLabel == “level2″)
{
if (score >= 150)
{
gotoWin = true;
}
}

if (life <= 0)
{
gotoLose = true;
}
}

private function handleDraw()
{
//Handle display
txtScoreP1.text = String(score);
txtLife.text = String(life);
}

private function triggerGoToWin()
{
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("win");
}

private function triggerGoToLose()
{
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("lose");
}

//Misc Functions
private function resetGame()
{
for (var i in cards)
cards[i].gotoAndStop("back");
}

}//end class
}//end package