Código :
fscommand("fullscreen",true); var dim = 100; //Alpha of pieces when clicked aPieces = new Array(); //Array of pieces aMoveList = new Array(); //Array of moves made var ID; var count = 0; //Number of moves made var first; var soSound0 = new Sound(this); //Creates a new Sound soSound0.attachSound("simonSound1.mp3"); //Attaches simonSound1.mp3 to that sound var soSound1 = new Sound(this); soSound1.attachSound("simonSound2.mp3"); var soSound2 = new Sound(this); soSound2.attachSound("simonSound3.mp3"); var soSound3 = new Sound(this); soSound3.attachSound("simonSound4.mp3"); var step = 0; muestra.stop(); for (var i = 1; i < 5; i++) //Adds the four movie clip quadrants to aPieces { aPieces.push(this["m" + i]); this["m" + i].value = i - 1; } function buildPieces() { for (var i = 0; i < aPieces.length; i++) { aPieces[i].onPress = function() //When the piece is pressed it dims { this._alpha = dim; }; aPieces[i].onRollOut = function() //When you roll your mouse off of the piece it undims { this._alpha = 20; }; aPieces[i].onRelease = function() //When you release your mouse { this._alpha = 100; //Set transparency to 100% _root["soSound" + this.value].start(0); //Play the piece sound if (aMoveList[step] != this.value) //If the piece you pressed does not equal the piece you were supposed to press { failure(); //failure method return; } step++; //Add one to the amount of steps to do if (step == aMoveList.length) { nextLevel(); //Go to the next level } }; } } function failure() { tMainText.text = "Game Over."; killPieces(); muestra.stop(); mStart._alpha = 100; //Set start button transparency back to 100% aMoveList = new Array(); //Delete array of moves mStart.onRelease = function() //Recreate the start button { startGame(); } } function killPieces() { for (var i = 0; i < aPieces.length; i++) //Deletes all the functions of the pieces so you cant interact with them { delete aPieces[i].onPress; delete aPieces[i].onRollOut; delete aPieces[i].onRelease; } } function lightUp(num) { clearInterval(ID); count--; if (count == 0) //If no more pieces are left to light up, wait for user to input sequence { userTurn(); return; } if (count == 1) //If the last piece in the list has just been lit up, pick a random light to light up { num = Math.floor(Math.random() * 4); } else //Set num to the next light to light up { num = aMoveList[aMoveList.length + 1 - count]; } light(num); //Light up the light } function userTurn() { step = 0; //Sets the step to 0 buildPieces(); //Lets user interact with pieces } function light(num) { dimIt(num); //dims the num piece ID = setInterval(pause, 1000, num); //Light up the piece for half of a second } function pause(num) { clearInterval(ID); unDim(num); ID = setInterval(lightUp, 100, num); //Creates a 50ms pause between lighting up pieces } function dimIt(num) { if (count == 1) { aMoveList.push(num); } _root["soSound" + num].start(0); //Plays the sound when lighting a piece up aPieces[num]._alpha = 100; } function unDim(num) { aPieces[num]._alpha = 20; } function startGame() { first = Math.floor(Math.random() * 4) //Picks first piece tMainText.text = ""; //Sets the text field to display nothing for (var i = 0; i < aPieces.length; i++) { aPieces[i]._alpha = 20; //Sets all the pieces to 100% transparency } mStart._alpha = 0; //Sets the start button to invisible delete mStart.onRelease; //Deletes the start button onRelease function muestra.play(); buildPieces(); count = 1; light(first); //Lights first piece } function nextLevel() { killPieces(); //Disables interacting with pieces for (var i = 0; i < aPieces.length; i++) { aPieces[i]._alpha = 20; //Sets all pieces to 100% transparency } count = aMoveList.length + 1; var timer = getTimer(); this.onEnterFrame = function() { if (timer < getTimer() - 1500) //Wait 1 second before starting sequence display after input { delete this.onEnterFrame; light(first); } }; } mStart.onRelease = function() { startGame(); };