Griffith Designs

AS2 Game Card Base Deck

by webmasterjunkie on Sep.27, 2010, under Actionscript, Programming

I made a flash based holdem game for a friend a while ago, and had this posted on my old blog, so figured I would repost the whole thing.

First, create the card arrays.

1
2
var cardSuits:Array = new Array ("Hearts", "Clubs", "Diamonds", "Spades");
var cardSigns:Array = new Array ("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K");


Next, create the actual deck.

1
2
3
4
5
6
7
8
9
function create_new_deck ():Array {
var array:Array = new Array;
    for (i = 0; i < cardSuits.length; i++) {
        for (j = 0; j < cardSigns.length; j++) {
            array.push (cardSigns[j] + " " + cardSuits[i]);
        }
    }
    return array;
}

Now, shuffle the deck.

1
2
3
4
5
6
7
8
9
function shuffle_cards (array:Array):Array {
    var _length:Number = array.length, mixed:Array = array.slice (), i:Number, j:Number, k:Object;
    for (j = 0; j < _length; j++) {
        k = mixed[j];
        mixed[j] = mixed[i = random (_length)];
        mixed[i] = k;
    }
    return mixed;
}

There you have it. A complete deck of cards, stacked, and then shuffled.

:, ,

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Connect