importjava.util.Arrays;importjava.util.Collections;importjava.util.HashMap;importjava.util.List;importjava.util.Map;public classDouDiZhu {public static Integer[] index = new Integer[54];private static Map allCard = new HashMap();public static voidmain(String[] args) {
initMap(allCard);//1.) 初始化卡牌
List list =Arrays.asList(initIndex(index));
Collections.shuffle(list);//2.)洗牌//3.)发牌
List player1 = list.subList(0, 17);
List player2 = list.subList(17, 34);
List player3 = list.subList(34, 51);
List dipai = list.subList(51, 54);//4.)按大小排序
Collections.sort(player1);
Collections.sort(player2);
Collections.sort(player3);
Collections.sort(dipai);
System.out.print("玩家1:");for(Integer i :player1){
System.out.print(allCard.get(i));
}
System.out.println();
System.out.print("玩家2:");for(Integer i :player2){
System.out.print(allCard.get(i));
}
System.out.println();
System.out.print("玩家3:");for(Integer i :player3){
System.out.print(allCard.get(i));
}
System.out.println();
System.out.print("底牌 :");for(Integer i :dipai){
System.out.print(allCard.get(i));
}
}//初始化卡牌数量
public staticInteger[] initIndex(Integer[] index) {for (int i = 1; i < 55; i++) {
index[i- 1] =i;
}returnindex;
}//将卡牌按大小以及花色(黑红梅方)添加到map
public static void initMap(Mapmap) {
String[] num= { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6","5", "4", "3"};
String[] color= { "♠","♥","♦","♣"};
map.put(1, "|BK|");
map.put(2, "|SK|");int k = 3;for (int i = 0; i < num.length; i++) {for (int j = 0; j < color.length; j++) {
map.put(k, color[j]+num[i]);
k++;
}
}
}
}
运行结果: