class PukerUtils { public constructor ( ) { } /**
     * TODO 去掉pukerIds，而将该数组的下标作为牌的id
     * 牌大小
     */ private static pukerSortValues : Array < number > = [ 12 , 12 , 12 , 12 , 13 , 13 , 13 , 13 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 , 5 , 5 , 5 , 5 , 6 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 8 , 8 , 8 , 8 , 9 , 9 , 9 , 9 , 10 , 10 , 10 , 10 , 11 , 11 , 11 , 11 , 14 , 15 ] ; /**
     * A的大小值
     */ public static AValue : number = 12 ; public static BigKingValue : number = 15 ; public static SmallKingValue : number = 14 ; /**
     * 牌面的id
     */ private static pukerIds : Array < number > = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 ] ; /**
     * 随机生成一副牌
     */ public static getRandomPokers ( ) { let pokers = new Array < Poker > ( ) ; let index ; let newArray = this . pukerIds . slice ( ) ; let pukerIndex ; let array = [ ] ; for ( let i = 0 ; i < this . pukerIds . length ; i ++ ) { index = Math . floor ( Math . random ( ) * newArray . length ) ; pukerIndex = newArray [ index ] ; array . push ( pukerIndex ) ; newArray = ArrayUtils . slice ( newArray , 0 , index ) . concat ( ArrayUtils . slice ( newArray , index + 1 , newArray . length ) ) ; } for ( let j = 0 ; j < array . length ; j ++ ) { let poker = new Poker ( this . pukerIds [ array [ j ] - 1 ] , this . pukerSortValues [ array [ j ] - 1 ] ) ; pokers . push ( poker ) ; } console . log ( "已随机生成一副牌" , pokers . toString ( ) ) ; return pokers ; } public static sortDescPokers ( pokers ) { return pokers . sort ( this . sortDesc ) ; } /**
     * 从一个数组中移除一些元素
     * 使用 ArrayUtils.removeElements时发现，其对对象数组无效，自己写了一个
     */ public static removePokers ( array , elements ) { let result = new Array < Poker > ( ) ; for ( let i = 0 ; i < array . length ; i ++ ) { let falg = false ; for ( let j = 0 ; j < elements . length ; j ++ ) { if ( array [ i ] . getId ( ) == elements [ j ] . getId ( ) ) { falg = true ; } } if ( ! falg ) { result . push ( array [ i ] ) ; } } return result ; } /**
     * 倒序排列的排序条件
     */ public static sortDesc ( a , b ) { if ( a . getOrderValue ( ) < b . getOrderValue ( ) ) return 1 ; else if ( a . getOrderValue ( ) > b . getOrderValue ( ) ) return - 1 ; else return 0 ; } public static randomUsers : Array < any > = [ { uid : "1001" , name : "大可" , sex : "man" } , { uid : "1002" , name : "Tiger" , sex : "lady" } , { uid : "1003" , name : "翔" , sex : "man" } , { uid : "1004" , name : "傻源源" , sex : "man" } , { uid : "1005" , name : "傻乐乐" , sex : "man" } , { uid : "1006" , name : "小巴西" , sex : "lady" } , { uid : "1007" , name : "油烟机" , sex : "man" } , { uid : "1008" , name : "可乐鸡翅" , sex : "lady" } , { uid : "1009" , name : "酸辣土豆丝" , sex : "lady" } , { uid : "1010" , name : "糖拌西红柿" , sex : "man" } , { uid : "1011" , name : "拍黄瓜" , sex : "man" } , { uid : "1012" , name : "空调没有遥控器" , sex : "man" } , { uid : "1013" , name : "这么晚了还不回家" , sex : "lady" } , { uid : "1014" , name : "程咬金" , sex : "man" } , { uid : "1015" , name : "猫砂不会盖" , sex : "man" } , { uid : "1016" , name : "风扇不摇头" , sex : "man" } , { uid : "1017" , name : "油炸花生米" , sex : "man" } , { uid : "1018" , name : "电视不能看" , sex : "man" } , { uid : "1019" , name : "绿萝" , sex : "lady" } , { uid : "1020" , name : "薄荷糖不麻" , sex : "lady" } , { uid : "1021" , name : "翔的小姐姐" , sex : "lady" } , { uid : "1022" , name : "孤单想吃西瓜" , sex : "man" } , { uid : "1023" , name : "一个人看烟花" , sex : "lady" } , { uid : "1024" , name : "大海啊你全是水" , sex : "man" } , { uid : "1025" , name : "骏马啊你四条腿" , sex : "man" } ] ; public static getRandomUser ( ) { let user = this . randomUsers [ Math . floor ( Math . random ( ) * this . randomUsers . length ) ] ; return new User ( user . name , user . sex ) ; } public static textTip : Array < string > = [ "不要" , "没你的大" , "要不起" , "你厉害" , "我认怂" , "你牛" , "过" , "GO" , "PASS" , "0.0" ] ; public static getRandomTextTip ( ) { return this . textTip [ Math . floor ( Math . random ( ) * this . textTip . length ) ] ; } }