public class PokerDemo {
public static void main(String[] args) {
//1.创建一个HashMap集合
//2.创建一个ArrayList集合
//3.创建花色和点数数组
//4.从0开始向HashMap中添加编号,并同时小ArrayList中添加编号
//5.洗牌,发牌,看牌
HashMap<Integer,String> hm=new HashMap<Integer,String>();
ArrayList<Integer> array=new ArrayList<Integer>();
String[] colors={"♠","♥","♣","♦"};
String[] numbers={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
int index=0;
for(String number:numbers){
for(String color:colors){
String poker=color.concat(number);
hm.put(index, poker);
array.add(index);
index++;
}
}
hm.put(index,"大王");
array.add(index);
index++;
hm.put(index,"小王");
array.add(index);
Collections.shuffle(array);
TreeSet<Integer> zhangsan=new TreeSet<Integer>();
TreeSet<Integer> lisi=new TreeSet<Integer>();
TreeSet<Integer> wangwu=new TreeSet<Integer>();
TreeSet<Integer> remain=new TreeSet<Integer>();
for(int x=0;x<array.size();x++){
if(x>=array.size()-3){
remain.add(array.get(x));
}else if(x%3==0){
zhangsan.add(array.get(x));
}else if(x%3==1){
lisi.add(x);
}else if(x%3==2){
wangwu.add(array.get(x));
}
}
lookPoker("张三",zhangsan,hm);
lookPoker("李四",lisi,hm);
lookPoker("王五",wangwu,hm);
lookPoker("底牌",remain,hm);
}
public static void lookPoker(String name,TreeSet<Integer>ts,
HashMap<Integer,String> hm){
System.out.print(name+"的牌:");
for(Integer key:ts){
String value=hm.get(key);
System.out.print(value+" ");
}
System.out.println();
}
}