package com.calender.java;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class PlayPoke {
public static void main(String[] args) {
String[] color = {"红桃", "方块", "梅花", "黑桃"};
String[] num = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
HashMap<Integer, String> poke = new HashMap<>();
ArrayList<Integer> list = new ArrayList<>();
int index = 0;
for(String c : color) {
for(String n : num) {
poke.put(index, c.concat(n));
list.add(index);
index++;
}
}
list.add(index);
poke.put(index, "小王");
index++;
list.add(index);
poke.put(index, "大王");
//洗牌
Collections.shuffle(list);
//发牌
TreeSet<Integer> tangseng = new TreeSet<>();
TreeSet<Integer> houzi = new TreeSet<>();
TreeSet<Integer> bajie = new TreeSet<>();
TreeSet<Integer> dipai = new TreeSet<>();
for(int i = 0; i < list.size(); i++) {
if(i >= list.size() - 3) {
dipai.add(list.get(i));
} else if (i % 3 == 0) {
houzi.add(list.get(i));
} else if(i % 3 == 1) {
tangseng.add(list.get(i));
} else {
bajie.add(list.get(i));
}
}
lookPoke(poke, tangseng, "唐僧");
lookPoke(poke, houzi, "猴子");
lookPoke(poke, bajie, "八戒");
lookPoke(poke, dipai, "底牌");
}
public static void lookPoke(HashMap<Integer, String> poke, TreeSet<Integer> list, String name) {
System.out.print(name + "的牌为:");
for(Integer i : list) {
System.out.print(poke.get(i) + " ");
}
System.out.println();
}
}
|
|