First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
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);
	//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.74 Votes: 39
(10 being the highest)
» Author
I'm the admin for BEF
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.