Quantcast
Channel: Adobe Community : All Content - All Communities
Viewing all articles
Browse latest Browse all 290743

Shuffling Cards and Checking for Match?

$
0
0

Hey, I am fairly new when it comes to AS3, I seem to be learning most aspects fairly well except for arrays.

 

First off, I will tell you what I am trying to create here.

 

I have a deck of 4 cards.

Each one is labelled with a different name. When I say this, I mean I have each one in my library the AS Linkage name "j2", "d2", "m2", "t2".

I have 4 buttons, 1 button to match each name.

I want the 4 cards to get "shuffled", and then 1 of the cards to get put down on the table (which I will have covered).

After the cards have been shuffled and 1 card has been put down, I want the player to click on a button guessing which card is facedown on the table.

When the played clicks the button, the card will be revealed and it will determine whether or not he/she was correct.

 

The only part I am having trouble with is a proper method to shuffle the 4 cards, lay 1 of them down, and then being able to match it with the button.

 

I have been trying for a few days, and it seems anything I try fails, so I am here now asking for help. You can take a look at my current shuffle/deal method, but I think that is what is causing me problems in matching them up.

 

 

private function createDeck() {
            var unshuf:Array = ["j2","d2","m2","t2"];
            for(var i:Number = 0; i < unshuf.length; i++){
                var shuf = Math.floor(Math.random() * unshuf.length)
                var arrayIndex = unshuf[i];
                unshuf[i] = unshuf[shuf];
                unshuf[shuf] = arrayIndex;
                var ClassRef:Class = Class(getDefinitionByName(unshuf[shuf]));
                var classInstance:* = new ClassRef();
                classInstance.x = 246;
                classInstance.y = 26.45;
                addChild(classInstance)
            }
            trace(unshuf);
            return unshuf;
}

 

 

Thanks.


Viewing all articles
Browse latest Browse all 290743


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>