java实现模拟斗地主洗牌和发牌并对牌进行排序

这里写代码片 import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class Poker {
    /*
     * 用Hashmap创建牌盒 
     * 1存储发牌
     * 2 装牌
     *  3洗牌 
     * 4 发牌
     *  5看牌
     * 
     */
    public static void main(String[] args) {
         HashMap hezi=new HashMap<>();
         ArrayList list=new ArrayList<>();
         //数字
         String[] shu= {"3","4","5","6","7","8","9","10","J","Q","K""A","2"};
            //花色
        String[] se= {"♠","♡","♢","♣"};
        int index=0;
        //装牌
        for(String s1:se) {
            for(String s2:shu) {

                hezi.put(index, s2.concat(s1));
                list.add(index);
                index++;
            }
        }
        hezi.put(index,"小王");
        list.add(index);
        index++;
        hezi.put(index, "大王");
        list.add(index);

        //洗牌
        Collections.shuffle(list);//洗索引即可
        //发牌
        TreeSet p1=new TreeSet<>();
        TreeSet p2=new TreeSet<>();
        TreeSet p3=new TreeSet<>();
        TreeSet dipai=new TreeSet<>();
        for(int i=0;iif(i>=list.size()-3) {
                dipai.add(list.get(i));
            }else if(i%3==0) {
                p1.add(list.get(i));
            }else if(i%3==1) {
                p2.add(list.get(i));
            }else {
                p3.add(list.get(i));
            }
        }
        method("赵六", hezi, p1);
        method("张三", hezi, p2);
        method("王小二", hezi, p3);
        method("底牌", hezi, dipai);
    }

    public static void method(String name,HashMap hezi,TreeSetlist) {
        System.out.println(name+"的牌为:");
        for (Integer integer : list) {
            String value=hezi.get(integer);
            System.out.print(value+" ");
        }
        System.out.println();
    }

}

你可能感兴趣的:(java实现模拟斗地主洗牌和发牌并对牌进行排序)