import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; public class DouDiZhu { public static Integer[] index = new Integer[54]; private static Map<Integer, String> allCard = new HashMap<Integer, String>(); public static void main(String[] args) { initMap(allCard);//1.) 初始化卡牌 List<Integer> list = Arrays.asList(initIndex(index)); Collections.shuffle(list);//2.)洗牌 //3.)发牌 List<Integer> player1 = list.subList(0, 17); List<Integer> player2 = list.subList(17, 34); List<Integer> player3 = list.subList(34, 51); List<Integer> 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 static Integer[] initIndex(Integer[] index) { for (int i = 1; i < 55; i++) { index[i - 1] = i; } return index; } //将卡牌按大小以及花色(黑红梅方)添加到map public static void initMap(Map<Integer, String> map) { 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++; } } } }
运行结果: