« Smallville Season 8 | Main | Political Bull »

Shuffling a Flash Card Deck

Well, we have already made the deck of cards, so now we need to shuffle it. You can feel free to copy this code if you are making a flash based card game yourself. Or even PHP as it would be pretty easy to port over.

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

TrackBack

TrackBack URL for this entry:
http://www.crisgriffith.com/cgi-bin/mt/mt-tb.cgi/60

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on May 17, 2008 9:18 PM.

The previous post in this blog was Smallville Season 8.

The next post in this blog is Political Bull.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.34