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
| public class PokerDemo2 { public static void main(String[] args) {
HashMap<Integer , String> hashMap =new HashMap<Integer , String>(); ArrayList<Integer> array = new ArrayList<Integer>();
String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"}; String[] color = {"♥","♠","♣","♦"};
int index = 0; for (String number : numbers) { for(String huase : color){ String value = huase.concat(number); hashMap.put(index, value); array.add(index); index++; } }
hashMap.put(index, "小王"); array.add(index); index++;
hashMap.put(index, "大王"); array.add(index); index++;
Collections.shuffle(array);
TreeSet<Integer> player1 = new TreeSet<Integer>(); TreeSet<Integer> player2 = new TreeSet<Integer>(); TreeSet<Integer> player3 = new TreeSet<Integer>(); TreeSet<Integer> dipai = new TreeSet<Integer>();
for(int i = 0 ; i < array.size() ; i++){ if(i >= (array.size()-3)){ dipai.add(array.get(i)); }else if( i % 3 == 0){ player1.add(array.get(i)); }else if( i % 3 == 1){ player2.add(array.get(i)); }else if( i % 3 == 2){ player3.add(array.get(i)); } }
lookPoker("张三", hashMap, player1); lookPoker("李四", hashMap, player2); lookPoker("王五", hashMap, player3); lookPoker("底牌", hashMap, dipai); }
public static void lookPoker(String name , HashMap<Integer , String> hashMap, TreeSet<Integer> array){ System.out.print(name + "的牌是:"); for (Integer key : array) { String value = hashMap.get(key); System.out.print(value + " "); } System.out.println(); } }
|