First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
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
	//*** NOT INDENTED FOR WEBPAGE PURPOSES ***
	if (_root.cardsInPlay == 1) {
	 _root.card2Match = this.theCard.cardFace._currentframe;
	}

	// begin animating
	this.theCard.play();
	// count attempt
	_root.attemptCount++;
	_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.
stop();
  

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