//无参构造器,初始化一副牌publicPoker(){String[]colors={"♠","♥","♣","♦"};
pokerList =newArrayList<>();//接下来生成牌//A牌的四种花色for(int i =0; i < colors.length; i++){//四种花色PokerCard pc =newPokerCard(colors[i],"A");
pokerList.add(pc);}//2-10的牌for(int i =2; i <=10; i++){//2-10牌的四种花色for(int j =0; j < colors.length; j++){//四种花色PokerCard pc =newPokerCard(colors[j], i+"");
pokerList.add(pc);}}//JQK牌的四种花色for(int i =0; i < colors.length; i++){//四种花色PokerCard pc =newPokerCard(colors[i],"J");
pokerList.add(pc);}for(int i =0; i < colors.length; i++){//四种花色PokerCard pc =newPokerCard(colors[i],"Q");
pokerList.add(pc);}for(int i =0; i < colors.length; i++){//四种花色PokerCard pc =newPokerCard(colors[i],"K");
pokerList.add(pc);}//大小王PokerCard pc1 =newPokerCard(null,"大王");
pokerList.add(pc1);PokerCard pc2 =newPokerCard(null,"小王");
pokerList.add(pc2);}
洗牌
//洗牌publicvoidShuffle(){//获取牌List<PokerCard> pkcList =this.getPokerList();Object[] total = pkcList.toArray();//洗牌是随机的Random r =newRandom();for(int j =0; j < total.length; j++){int sj = r.nextInt(54);System.out.print(total[sj]+" ");}System.out.println();}
发牌
//发牌publicvoidfaPai(){//获取牌List<PokerCard> pkcList =this.getPokerList();Object[] total = pkcList.toArray();//存储三个玩家的牌Object[][] plays =newObject[3][17];//存储当前剩余牌的数量int leftNum =54;//发牌是随机的Random r =newRandom();//分别把牌分给3个人,留三张底牌,也就是说一个人能分到17张牌for(int i =0; i <17; i++){//为每个人发牌for(int j =0; j < plays.length; j++){//System.out.println(j);int ranNumber = r.nextInt(leftNum);//发牌
plays[j][i]= total[ranNumber];//移动发的牌
total[ranNumber]= total[leftNum -1];
leftNum--;}}for(int i =0; i < plays.length; i++){System.out.print("玩家:"+i+"的牌 ");for(int j =0; j < plays[i].length; j++){System.out.print(plays[i][j]+" ");}System.out.println();}System.out.print("底牌:");for(int i =0;i <3;i++){System.out.print(total[i]);}System.out.println();}