package chapter6.demo64;

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

// Game.java - 游戏类
public class Game {
    private Deck deck;
    private Player player1;
    private Player player2;
    private Player player3;
    private ArrayList<Card> bottomCards;

    /**
     * 初始化游戏
     */
    public Game() {
        deck = new Deck();
        player1 = new Player("玩家1");
        player2 = new Player("玩家2");
        player3 = new Player("玩家3");
        bottomCards = new ArrayList<>();
    }

    /**
     * 开始游戏
     */
    public void start() {
        // 1. 洗牌
        deck.shuffle();

        // 2. 发牌
        for (int i = 0; i < 54; i++) {
            Card card = deck.dealCard();
            if (i >= 51) {
                bottomCards.add(card);
            } else {
                switch (i % 3) {
                    case 0:
                        player1.receiveCard(card);
                        break;
                    case 1:
                        player2.receiveCard(card);
                        break;
                    case 2:
                        player3.receiveCard(card);
                        break;
                }
            }
        }

        // 3. 显示结果
        showResult();
    }

    /**
     * 显示游戏结果
     */
    private void showResult() {
        System.out.println(player1.showHand());
        System.out.println(player2.showHand());
        System.out.println(player3.showHand());
        System.out.println("底牌：" + bottomCards);
    }

    /**
     * 程序入口
     */
    public static void main(String[] args) {
        Game game = new Game();
        game.start();
    }
}