package com.yjf.esupplier.common.test; import java.util.ArrayList; import java.util.Collections; /** * @author shusheng * @description 撲克遊戲 * @Email shusheng@yiji.com * @date 2018/12/18 17:37 */ public class PokerDemo { public static void main(String[] args) { // 建立一個牌盒 ArrayList<String> array = new ArrayList<String>(); String[] colors = {"♠", "♥", "♣", "♦"}; // 定義一個點數數組 String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; // 裝牌 for (String color : colors) { for (String number : numbers) { array.add(color.concat(number)); } } array.add("小王"); array.add("大王"); // 洗牌 Collections.shuffle(array); System.out.println("array:" + array); // 發牌 ArrayList<String> fengQingYang = new ArrayList<String>(); ArrayList<String> linQingXia = new ArrayList<String>(); ArrayList<String> liuYi = new ArrayList<String>(); ArrayList<String> diPai = new ArrayList<String>(); for (int x = 0; x < array.size(); x++) { if (x >= array.size() - 3) { diPai.add(array.get(x)); } else if (x % 3 == 0) { fengQingYang.add(array.get(x)); } else if (x % 3 == 1) { linQingXia.add(array.get(x)); } else if (x % 3 == 2) { liuYi.add(array.get(x)); } } // 看牌 lookPoker("風清揚", fengQingYang); lookPoker("林青霞", linQingXia); lookPoker("劉意", liuYi); lookPoker("底牌", diPai); } private static void lookPoker(String name, ArrayList<String> array) { System.out.print(name + "的牌是:"); for (String s : array) { System.out.print(s + " "); } System.out.println(); } }