package cclass01.set.class02;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class PokerDemo {
/**创建hashmap集合
创建arraylis集合
创建花色数组和点数数组
从0开始往hashmap存编号,并存储对应的牌
同时往arraylist里存储编号,洗牌,发牌,看牌
*/
public static void main(String[] args) {
HashMap<Integer, String >hm= new HashMap<Integer, String>();
ArrayList<Integer>array= new ArrayList<Integer>();
String [] colors= {"♠","♥","♣","♦"};//定义花色数组
String [] numbers= {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
int index=-1;
for (String number :numbers) {
for (String color : colors) {
String Pook= color.concat(number);
hm.put(index, Pook);
array.add(index);
index++;
}
}
hm.put(index, "小王");
array.add(index);
index++;
hm.put(index, "大王");
array.add(index);
Collections.shuffle(array); //洗牌
//发牌
TreeSet<Integer>play1= new TreeSet<Integer>();
TreeSet<Integer>play2= new TreeSet<Integer>();
TreeSet<Integer>play3= new TreeSet<Integer>();
TreeSet<Integer>play4= new TreeSet<Integer>();
//发牌
for (int i = 0; i < array.size(); i++) {
if (i>=hm.size()-3) {
play4.add(array.get(i));//留三张底牌
}else if (i%3==0) {
play1.add(array.get(i));
}else if(i%3==1) {
play2.add(array.get(i));
}else if(i%3==2){
play3.add(array.get(i));
}
}
//每位选手附带hashmap键值对应
lookPoker("马云",play1,hm);
lookPoker("马化腾",play2,hm);
lookPoker("王健林",play3,hm);
lookPoker("底牌",play4,hm);
}
//创建看牌的方法
public static void lookPoker(String name,TreeSet<Integer>tSet,HashMap<Integer, String >hm){
System.out.println(name+" ");
for (Integer key : tSet) {
String value= hm.get(key);
System.out.print(value+"-");
}
System.out.println();
}
}