Deck of Cards Shuffler

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

First load of this page shows a standard deck of 52 cards, one suit per row and listed in descending order, with aces high.


Click anywhere to randomly shuffle the deck. Try and find any 5 cards in a row that make hands such as straights, flushes, full house, & four of a kind. Find a royal flush and it's your lucky day!

  
var deck:Array = new Array();

//Steps to creating a deck of cards that has been very well shuffled.
//1.create card index array holding numbers from 1 through 52, representing the 52 cards in a standard deck of cards
//2.randomly pick a card from deck and push it into a new array, temp_deck.
//3.repeat step 2 until all cards are moved from deck into temp_deck.
//4.move contents of temp_deck into deck and empty temp_deck. Cards are now shuffled.
//5.repeat steps 2 - 4 several times for extra shuffling. the more the better

this.stage.addEventListener(MouseEvent.CLICK, dealIt);

function dealIt(e:MouseEvent):void{
	shuffleDeck();
	dealDeck();
}

//short hand deck values
var deck:Array = new Array("Ac","2c","3c","4c","5c","6c","7c","8c","9c","Tc","Jc","Qc","Kc","Ah","2h","3h","4h","5h","6h","7h","8h","9h","Th","Jh","Qh","Kh","As","2s","3s","4s","5s","6s","7s","8s","9s","Ts","Js","Qs","Ks","Ad","2d","3d","4d","5d","6d","7d","8d","9d","Td","Jd","Qd","Kd");

//make array holding ordered index of cards

for(var di:int=0; di<52; di++){
	deck[di] = di+1;
}

//trace(deck); // trace ordered index

var temp_deck:Array = new Array();

function shuffleDeck():void{

	//Steps 2-5 as described above.

	for(var i:int=0;i<17;i++){

		while(deck.length > 0){
			var rand:int = Math.random()*deck.length;
			temp_deck.push(deck[rand]);
			deck.splice(rand,1);
		}

		deck = temp_deck;
		temp_deck = new Array();
	}
}

function dealDeck():void{

// display cards on screen

for (var k:int=0;k<4;k++){
	for(var j:int=1; j<14; j++){
		var l:Loader= new Loader();
			l.load(new URLRequest("http://patrickmoraitis.com/assets/code/cards/deck/" + deck[(j-1)+13*k].toString() +  ".png"));

			l.scaleX = l.scaleY = .5;
			l.x = ((41*j))-39;
			l.y = 25 + k*100;
			l.contentLoaderInfo.addEventListener(Event.COMPLETE, function addCard(e:Event):void{addChild(l);});

			addChild(l);
	}
}}

dealDeck();