Esempio n. 1
0
    public void Start()
    {
        OnStart?.Invoke();

        _deck = new Deck();

        // Clearing cards
        Dealer.Clear();
        foreach (Player player in Players)
        {
            player.Clear();
        }

        // Making bets
        foreach (Player player in Players)
        {
            player.MakeBet();
        }

        // Give the players and yourself 2 cards
        Dealer.BeginGame(Players, _deck);

        // If dealer blackjack
        if (Dealer.HasBlackjack)
        {
            OnEnd?.Invoke();
            Finish();
            KickBankrupts();
            return;
        }

        // Players taking cards
        foreach (Player player in Players)
        {
            while (player.Action == PlayerAction.Hit)
            {
                player.Hit(_deck.GetCard());
            }
            player.Stand();
        }

        // Take cards while the score is less than 17
        Dealer.GetCards(_deck);

        OnEnd?.Invoke();
        Finish();
        KickBankrupts();
    }
Esempio n. 2
0
    public void BeginGameTest()
    {
        List <Player> players = new List <Player>()
        {
            new MadBot("Mad", 1000),
            new RiskyBot("Risky", 1000),
            new SillyBot("Silly", 1000)
        };
        Deck   deck   = new Deck();
        Dealer dealer = new Dealer();

        dealer.BeginGame(players, deck);

        foreach (Player player in players)
        {
            Assert.AreEqual(2, player.Cards.Count);
        }

        Assert.AreEqual(2, dealer.Cards.Count);
    }