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

Step 4: Put it all together

Now we've got our dealer, and we've got our playing card. All we have to do is finish up some code on the playing card, and deal them suckers out! O and of course, make our beginning and ending scenes.

Preparing the cards to turn:
For the cards, take and instance playingCard and put it on the main stage. Make sure it's low enough to be off screen. Name this instance pCard. Not intentially named after the captain of the Enterprise, but we'll work with it. Place the following code:

on (release) {
	// only animate 2 unique cards at any given time.
if ((_root.cardsInPlay < 2) && (this.theCard._currentframe <= 1))
	// if this is the first card then save picture number
	if (_root.cardsInPlay == 1) {
	 _root.card2Match = this.theCard.cardFace._currentframe;

	// begin animating
	// count attempt
	_root.gameAttempts = "ATTEMPTS: " 
	+ Math.round(_root.attemptCount / 2);

This simple code tells the card, that when it is released to check 2 things
1) if 2 cards are already in play
2) if it is not already animating

If it passes both, then it continues on to check if it's the first card in play or the second. Depending on the answer it sets the card to match.

Now, animate the card with the play directive and we increment the attempt count. Remember? Attempt count is going to be used to calculate the score.
Seems like the cards are ready to turn. Let's do our simple dealing code.

Dealing the cards:
On the main stage, in our actions layer and probably under the functions, lets set the cards to deal:

// create a deck
fullDeck = new Array();
fullDeck = createDeck();
// Total unique cards
totalUniqueCards = 16;
// Total number of cards in play
totalCardsNum = totalUniqueCards * 2;
// deal the cards + duplicates from the deck
deal(totalUniqueCards, fullDeck);
// wait here now.

Simple enough? Thanks functions!!! Now we can play memory, set the number of cards to deal, set the pictures easily and manipulate our cards easily. This game could very easily be built up to do more advanced features.

» 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.