First time here? First time here? Newsletter Signup Newsletter
Search tutorials

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);
	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) {

// 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

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.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.