Step 5 - Scores and Goodbye
You will need to create a frame on the the main stage and name it "Ender". This frame will be jumped to when the last card is matched. I suggest placing it on a completely new scene. You would probably want to calculate your score. I do so by multiplying the numer of attempts by the number of seconds elapsed. You've been saving the number of attempts in a global variable _root.attemptCount, but how can you figure how many seconds have elapsed???
Well, what I did was make a simple timer on the main game. This consists of a movieclip, with a dynamic textbox inside. I named the textbox "gameTime".
Then in the movieclip actions I placed this code:
onClipEvent(load) { staticPrefix = "TIMER: "; startTime = getTimer(); staticSuffix = " seconds"; } onClipEvent(enterFrame) { curTime = getTimer(); elapsed = curTime - startTime; _root.secondsElapsed = Math.floor(elapsed / 1000); //trace(secondsElapsed); this.gameTime = staticPrefix + _root.secondsElapsed + staticSuffix; }
This is basic timing code. On the movieclip's load, it gets how many milliseconds the game has been running with getTimer(). Then every frame after that (enterFrame), it calculates time elapsed with curTime - startTime. This of course returns milliseconds, which means we need to divide by 1k to get back to normal seconds.
The code sets _root.secondsElapsed for us, so now we can use that to calculate the score :)
I've placed 2 text boxes, one named summary and the other named finalScore.
I also do a quick check to make sure someone didn't right mouse click and choose play, to bypass the game and get a perfect score. The code in the frame is such.
// make sure someone didn't cheat with right mouse click if (_root.totalCardsNum != 0) { gotoAndPlay("beginning"); } // get peices seconds = _root.secondsElapsed; numAttempts = Math.floor(_root.attemptCount / 2) // now print scoring sumText = "You took " + seconds + " seconds to complete this game.\nYou did so in " + numAttempts + " attempts.\n\nYour final score is: " _root.summary = sumText; _root.finalScore = seconds * numAttempts; // stop stage stop();
CONGRATULATIONS! You now have all the peices to make your very own memory game. Feel free to play the finished version of the game here: http://www.BleachEatingFreaks.com/flash/games/memory/
And if you'd like to support us with a donation or purchase BEF playing cards, please visit here: http://www.bleacheatingfreaks.com/bleachwear/cards/
» Level Intermediate |
Added: 2005-04-06 Rating: 4.43 Votes: 44 |
» Author |
I'm the admin for BEF |
» Download |
Download the files used in this tutorial. |
Download (115 kb) |
» Forums |
More help? Search our boards for quick answers! |