package cn.kgc.demo.ddz;
import java.util.*;
public class Paixing {
public static void main(String[] args) {
// hashMap集合来存储key,牌型。
HashMap<Integer ,String > pai = new HashMap<>();
// 存花色
String[] color=new String[]{"♠","♥","♣","♦"};
// 存数字
String[] nums=new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
// 设置key变量
int index;
// 存大小王
pai.put(0,"大王");
pai.put(1,"小王");
// 存牌型
index=2;
for(int i=0;i<color.length;i++){
for (int j=0;j<nums.length;j++){
pai.put(index,color[i]+nums[j]);
index++;
}
}
System.out.println(pai);
// 洗牌 取数据value,存新的List集合
System.out.println("***********************************");
ArrayList<String> al = new ArrayList<>();
Set<Integer> set = pai.keySet();
for(Integer key:set){
al.add(pai.get(key));
}
Collections.shuffle(al);
System.out.println(al);
// 发牌 三个玩家玩,没人17张,底牌留三张
System.out.println("***********************************");
// 设置三个玩家
ArrayList<String> lb = new ArrayList<>();
ArrayList<String> zf = new ArrayList<>();
ArrayList<String> gy = new ArrayList<>();
ArrayList<String> dp = new ArrayList<>();
// 取牌分别发给三人
for (int i = 0; i <((color.length*nums.length)-1) ; i++) {
switch (i%3){
case 0:
lb.add(al.get(i));
break;
case 1:
zf.add(al.get(i));
break;
case 2:
gy.add(al.get(i));
break;
}
}
// 设置剩余三张的底牌
for (int i=(color.length*nums.length)-1;i<color.length*nums.length+2;i++){
dp.add(al.get(i));
}
// 看牌
System.out.println("刘备的是"+lb);
System.out.println("张飞的是"+zf);
System.out.println("关羽的是"+gy);
System.out.println("底牌是"+dp);
}
}