package com.silei.linkedlist;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class abc {
public static void main(String[] args) {
HashMap hm = new HashMap();
//定义HashMap变量用于存储每张排的编号以及牌型
ArrayList array = new ArrayList();
//定义ArrayList变量存储排的编号
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){
//遍历花色
hm.put(index, color.concat(number));
//将花色与牌值拼接,并将编号与拼接后的结果存储到hm中
array.add(index);
//将编号存储到array中
index++;}
}/* * 将小王和大王存储到hm中 */
hm.put(index, "小王");
array.add(index);
index++;
hm.put(index, "大王");
array.add(index);
Collections.shuffle(array);
//调用Collections集合的shuffle()方法,将array中存储的编号进行随机的置换,即打乱顺序
/* * 定义四个TreeSet集合的变量用于存储底牌编号以及三个玩家的牌的编号 * 采用TreeSet集合是因为TreeSet集合可以实现自然排序 */
TreeSet playerOne = new TreeSet();
TreeSet PlayerTwo = new TreeSet();
TreeSet playerThree = new TreeSet();
TreeSet dipai = new TreeSet();
//遍历编号的集合,实现发牌
for(int x = 0; x < array.size(); x++){
if(x >= array.size() - 3){
dipai.add(array.get(x));
}else if( x % 3 == 0){
playerOne.add(array.get(x));
}else if(x % 3 == 1){
PlayerTwo.add(array.get(x));
}else if(x % 3 == 2){
playerThree.add(array.get(x));}
}
lookPoker("底牌",dipai,hm);
lookPoker("xiequn",PlayerTwo,hm);
lookPoker("huangshen",playerOne,hm);
lookPoker("diannao",playerThree,hm);
}
/** * 遍历每个玩家的牌以及底牌 * @param name * @param ts * @param hm */
public static void lookPoker(String name,TreeSet ts,HashMap hm){
System.out.print(name+":\t");
//打印玩家名称
for(Integer key : ts){
//遍历玩家TreeSet集合,获得玩家的牌的编号
String value = hm.get(key);
//根据玩家牌编号获取具体的牌值
System.out.print(value+" ");
//打印
}
System.out.println();
}
}