Java 模拟斗地主

模拟斗地主

    public static void main(String args[]) {
        ArrayList<String> array = new ArrayList<>();
        String[] colors = {"♥", "♠", "♣", "♢"};
        String[] numbers = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
        for (String color : colors) {
            for (String number : numbers) {
                array.add(color + number);
            }
        }
        array.add("小王");
        array.add("大王");
        Collections.shuffle(array);
        //System.out.println(array);

        ArrayList<String> array0 = new ArrayList<>();
        ArrayList<String> array1 = new ArrayList<>();
        ArrayList<String> array2 = new ArrayList<>();
        ArrayList<String> arrayPoker = new ArrayList<>();
        for (int i = 0; i < array.size(); i++) {
            String poker = array.get(i);
            if (i >= array.size() - 3) {
                arrayPoker.add(poker);
            } else if (i % 3 == 0) {
                array0.add(poker);
            } else if (i % 3 == 1) {
                array1.add(poker);
            } else if (i % 3 == 2) {
                array2.add(poker);
            }
        }
        lookPoker("0 ", array0);
        lookPoker("1 ", array1);
        lookPoker("2 ", array2);
    }

    public static void lookPoker(String name, ArrayList<String> array) {
        System.out.println(name + "的牌是:");
        for (String poker : array) {
            System.out.print(poker + " ");
        }
        System.out.println();
    }

猜你喜欢

转载自www.cnblogs.com/kikyoqiang/p/11494713.html