import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class Demo4 {
public static void main(String[] args) {
String[] num = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
String[] color = {"红桃","黑桃","方块","梅花"};
HashMap<Integer, String> hm = new HashMap<>();
ArrayList<Integer> list = new ArrayList<>();
int index = 0;
for (int i = 0; i < num.length; i++) {
for (int j = 0; j < color.length ; j++) {
hm.put(index, color[j].concat(num[i]));
list.add(index);
index++;
}
}
hm.put(index, "公主");
list.add(index);
index++;
hm.put(index, "王妃");
list.add(index);
Collections.shuffle(list);
TreeSet<Integer> liubei = new TreeSet<>();
TreeSet<Integer> sunquan = new TreeSet<>();
TreeSet<Integer> caocao = 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) {
liubei.add(list.get(i));
}else if (i%3==1) {
sunquan.add(list.get(i));
}else {
caocao.add(list.get(i));
}
}
lookpoker (hm , liubei , "刘备");
lookpoker (hm , sunquan , "孙权");
lookpoker (hm , caocao , "曹操");
lookpoker (hm , dipai , "底牌");
}
public static void lookpoker(HashMap<Integer, String> hm ,TreeSet<Integer> ts ,String name ){
System.out.print(name + "的牌是:");
for (Integer i : ts) {
System.out.print(hm.get(i) + " ");
}
System.out.println();
}
} |