Java imitation landlords shuffle licensing games

public class Main {
    public static void main(String[] args) {
        // 1. 准备牌
        String[] arr1 = { "黑桃","红桃","方片","梅花" };
        String[] arr2 = { "A","2","3","4","5","6","7","8","9","10","J","Q","K" };
        List<String> arry@R_837_2419@ = new ArrayList<>();
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr2.length; j++) {
                arry@R_837_2419@.add(arr1[i] + arr2[j]);
            }
        }
        arry@R_837_2419@.add("大王");
        arry@R_837_2419@.add("小王");
        // 3个人斗地主,分别为 zhangsan、lisi、wangwu
        List<String> zhangsan = new ArrayList<>();
        List<String> lisi = new ArrayList<>();
        List<String> wangwu = new ArrayList<>();
        // 2. 洗牌
        Collections.shuffle(arry@R_837_2419@);
        // 3. 发牌
        for (int i = 0; i < arry@R_837_2419@.size() - 3; i++) {
            if (i % 3 == 0) {
                zhangsan.add(arry@R_837_2419@.get(i));
            } else if (i % 3 == 1) {
                lisi.add(arry@R_837_2419@.get(i));
            } else if (i % 3 == 2) {
                wangwu.add(arry@R_837_2419@.get(i));
            }
        }
        // 4. 看牌
        pushBoss();
        System.out.println("张三:" + zhangsan);
        System.out.println("李四:" + lisi);
        System.out.println("王五:" + wangwu);
        System.out.print("底牌:[");
        for (int i = 1; i < 4; i++) {
            System.out.print(arry@R_837_2419@.get(arry@R_837_2419@.size() - i));
            if (i < 3) {
                System.out.print(",");
            }
        }
        System.out.print("]");

    }

    /** 随机地主 */
    public static void pushBoss() {
        List<String> players = new ArrayList<String>();
        players.add("张三");
        players.add("李四");
        players.add("王五");
        Random r = new Random();
        int bossIndex = r.nextInt(3);
        String boss = players.get(bossIndex);
        System.out.println("此局地主是:" + boss);
    }
}

The landlord of this game is: Li Si Zhang San: [plum blossom 10, square slice 2, square slice K, square slice J, square slice 5, spade 6, spade 10, heart 3, plum blossom 3, spade 2, plum blossom 8, spade a, heart J, plum blossom 9, heart K, square slice 9, plum blossom q] Li Si: [heart 4, spade 8, square slice 8, square slice 3, heart 2, heart 6, heart 5, spade 3, spade 4, plum blossom 7, square slice Q, Xiao Wang, heart 8, spade K, square slice 6, plum blossom a, spade 7] king 5: [square slice 4, plum blossom 4, square slice 7, spade 5, spade 9, heart 10, plum blossom K, square slice a, heart Q, spade J, plum blossom 2, king, square slice 10, heart a, plum blossom J, plum blossom 5, heart 7] cards: [plum blossom 6, heart 9, spade q]

public class Main2 {
    public static void main(String[] args) {
        // 1.准备牌
        String[] arr1 = { "黑桃","K" };

        // 定义Map集合用来存放索引和牌
        HashMap<Integer,String> pokerMap = new HashMap<>();
        // 定义List集合存储索引(索引为0-53)
        List<Integer> indexList = new ArrayList<>();
        // 定义索引值变量
        int index = 0;
        // 将扑克牌与索引建立对应关系放入Map和List集合中
        for (String num : arr2) {
            for (String color : arr1) {
                pokerMap.put(index,color + num);
                indexList.add(index);
                index++;
            }
        }
        pokerMap.put(index,"小王");
        indexList.add(index++);
        pokerMap.put(index,"大王");
        indexList.add(index);

        // 定义玩家
        TreeSet<Integer> zhangsan = new TreeSet<>();
        TreeSet<Integer> lisi = new TreeSet<>();
        TreeSet<Integer> wangwu = new TreeSet<>();
        TreeSet<Integer> buttoms = new TreeSet<>();

        // 2. 洗牌
        Collections.shuffle(indexList);
        // 3. 发牌
        for (int i = 0; i < indexList.size(); i++) {
            if (i >= indexList.size() - 3) {
                buttoms.add(indexList.get(i));
            } else if (i % 3 == 0) {
                zhangsan.add(indexList.get(i));
            } else if (i % 3 == 1) {
                lisi.add(indexList.get(i));
            } else {
                wangwu.add(indexList.get(i));
            }
        }
        // 4. 看牌
        pushBoss();
        check(pokerMap,zhangsan,"张三");
        check(pokerMap,lisi,"李四");
        check(pokerMap,wangwu,"王五");
        check(pokerMap,buttoms,"底牌");
    }

    /**
     * 看牌
     *
     * @param pokerMap
     * @param player   玩家扑克牌对应索引集合
     * @param name     玩家昵称
     */
    public static void check(HashMap<Integer,String> pokerMap,TreeSet<Integer> player,String name) {
        // 查看手中的牌
        System.out.print(name + ":[");
        for (Integer i : player) {
            System.out.print(pokerMap.get(i) + " ");
        }
        System.out.println("]");
    }

    /** 随机地主 */
    public static void pushBoss() {
        List<String> players = new ArrayList<String>();
        players.add("张三");
        players.add("李四");
        players.add("王五");
        Random r = new Random();
        int bossIndex = r.nextInt(3);
        String boss = players.get(bossIndex);
        System.out.println("此局地主是:" + boss);
    }
}

The landlord of this game is: Zhang San, Zhang San: [square piece a of Hearts 2 square pieces 2 spades 4 spades 4 plum blossoms 4 spades 6 square pieces 6 plum blossoms 6 spades 7 spades 8 spades 9 spades 10 square pieces J square pieces Q spades K spades k] Li Si: [plum blossoms 2 Spades 3 spades 3 square pieces 3 plum blossoms 3 hearts 5 hearts 5 square pieces 5 hearts 7 plum blossoms 8 hearts 9 plum blossoms 9 hearts 10 plum blossoms 10 spades Q plum blossoms Q plum blossoms K Xiaowang Wu: [spades a, hearts a, spades 2 square pieces 4 spades 5, spades 6 square pieces 7 spades 8 square pieces 8 square pieces 9 square pieces 10 spades J, hearts J, plum blossoms J, hearts Q square pieces K king] bottom card: [plum blossoms a, plum blossoms 5, plum blossoms 7]

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>