package { /* *@ClassName:package::PokerMain *@Intro:这是一个初始化1-52扑克牌,然后进行乱序排列进行洗牌; *@Author:非若 *@Date:2015.07.22 *@LanguageVersion:ActionScript 3.0 * */ import flash.display.Sprite; public class PokerMain extends Sprite { //设置扑克牌总数 private var NUM:Number = 52; public function PokerMain() { //扑克洗牌: init_Shuffle(); } private function init_Shuffle():void { var temp:Object = null; var _pokers:Vector.<Object > = get_Poker(); for (var m:uint=0; m<NUM; m++) { var n:uint = Math.random() * NUM; temp = _pokers[m]; _pokers[m] = _pokers[n]; _pokers[n] = temp; trace(m+"--:--"+_pokers[m].name+"<|>"+_pokers[m].style); } } private function get_Poker():Vector.<Object > { //创建扑克牌对象池 var POKER:Vector.<Object>=new Vector.<Object>(); var _name:String = ""; var _style:String = ""; for (var r:uint=0; r<NUM; r++) { var Poker:Object = {name:null,style:null}; var n:uint=uint((r-0.3)/4); var m:uint=uint((r-1)%4); switch (m) { case 0 : { _style = "红桃"; }; break; case 1 : { _style = "黑桃"; }; break; case 2 : { _style = "方块"; }; break; case 3 : { _style = "梅花"; }; break; default : { _style = "未知"; }; break; } switch (n) { case 0 : _name = "K"; break; case 1 : _name = "A"; break; case 11 : _name = "J"; break; case 12 : _name = "Q"; break; default : _name = String(n); break; } Poker.name = _name; Poker.style = _style; POKER.push(Poker); } return POKER; } } }
时间: 2024-12-28 17:39:57