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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| package com.itheima.demo06.Test;
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List;
public class DouDiZhu { public static void main(String[] args) { HashMap<Integer,String> poker = new HashMap<>(); ArrayList<Integer> pokerIndex = new ArrayList<>(); List<String> colors = List.of("♠", "♥", "♣", "♦"); List<String> numbers = List.of("2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"); int index = 0; poker.put(index,"大王"); pokerIndex.add(index); index++; poker.put(index,"小王"); pokerIndex.add(index); index++; for (String number : numbers) { for (String color : colors) { poker.put(index,color+number); pokerIndex.add(index); index++; } }
Collections.shuffle(pokerIndex);
ArrayList<Integer> player01 = new ArrayList<>(); ArrayList<Integer> player02 = new ArrayList<>(); ArrayList<Integer> player03 = new ArrayList<>(); ArrayList<Integer> diPai = new ArrayList<>(); for (int i = 0; i <pokerIndex.size() ; i++) { Integer in = pokerIndex.get(i); if(i>=51){ diPai.add(in); }else if(i%3==0){ player01.add(in); }else if(i%3==1){ player02.add(in); }else if(i%3==2){ player03.add(in); } }
Collections.sort(player01); Collections.sort(player02); Collections.sort(player03); Collections.sort(diPai);
lookPoker("刘德华",poker,player01); lookPoker("周润发",poker,player02); lookPoker("周星驰",poker,player03); lookPoker("底牌",poker,diPai); }
public static void lookPoker(String name,HashMap<Integer,String> poker,ArrayList<Integer> list){ System.out.print(name+":"); for (Integer key : list) { String value = poker.get(key); System.out.print(value+" "); } System.out.println(); }
}
|