package chapter6.demo64;

import java.util.ArrayList;
import java.util.Collections;

// Deck.java - 牌组类
public class Deck {
    private ArrayList<Card> cards = new ArrayList<>();
    private static final String[] COLORS = {"♠", "♥", "♣", "♦"};
    private static final String[] POINTS = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};

    /**
     * 初始化一副扑克牌
     */
    public Deck() {
        int index = 0;
        // 生成52张普通牌
        for (String point : POINTS) {
            for (String color : COLORS) {
                cards.add(new Card(color, point, index++));
            }
        }
        // 添加大小王
        cards.add(new Card("", "小☺", index++));
        cards.add(new Card("", "大☻", index));
    }

    /**
     * 洗牌
     */
    public void shuffle() {
        Collections.shuffle(cards);
    }

    /**
     * 发牌
     * @return 发出的牌
     */
    public Card dealCard() {
        if (!cards.isEmpty()) {
            return cards.removeFirst();
        }
        return null;
    }
}