Esempio n. 1
0
        public override void StartGame()
        {
            run           = true;
            Hands         = 0;
            table.players = this.CastToPerson(playerGroup);

            Console.WriteLine($"Game started - {ID}");

            while (run)
            {
                Logs.LogTrace("count of players: " + playerGroup.Count, logID);
                Hands++;

                Logs.LogTrace($"*Start {Hands}*", logID);
                while (pendingPlayers.Count > 0)
                {
                    playerGroup.Add(pendingPlayers.Take());
                }

                CheckForValidPlayers();
                Bets();
                Deal();

                foreach (BlackjackPlayer bp in playerGroup)
                {
                    if (bp.PlayerControlled)
                    {
                        HumanPlay(bp);
                    }
                    else
                    {
                        PlayerAI(bp);
                    }
                }

                DealerAI();

                Logs.LogTrace("Dealer : " + dealer.CardsValue, logID);
                LogLine("Dealer cards: ");
                dealer.ReturnCards().ForEach(a => { Log(a.ToString()); });
                LogLine("");
                LogLine("Card value: " + dealer.CardsValue);

                foreach (BlackjackPlayer bp in playerGroup)
                {
                    Logs.LogTrace("Player: " + bp.CardsValue, logID);
                    if (DecideOutcome(bp))
                    {
                        LogLine("You win!");
                        Logs.LogTrace("Winner");
                        var bet = betPool[bp];
                        bp.Money += bet * 2;
                    }
                    else
                    {
                        LogLine("You lose");
                        Logs.LogTrace("Loser", logID);
                    }
                }
                ShuffleCardsBackIn();
                PrintPlayersMoney();
                End();

                if (Hands > 30)
                {
                    run = false;
                }
                if (playerGroup.Count < 1)
                {
                    run = false;
                }

                Logs.LogTrace($"*End {Hands}*", logID);
                Thread.Sleep(1500);
            }

            LogLine($"Game has ended {logID}");
        }
Esempio n. 2
0
 private void Hit(BlackjackDealer bp)
 {
     bp.AddCards((Card)st.Dequeue());
     bp.CardsValue = CalcCards(bp.ReturnCards());
 }