public GameResults(List <BlackJackPlayer> players, BlackJackPlayer dealer)
        {
            PlayerNames = new string[players.Count];
            HandValues  = new int[players.Count];
            WinLose     = new bool[players.Count];

            DealerValue    = dealer.GetHandValue();
            IsDealerBusted = DealerValue > 21;

            for (int i = 0; i < players.Count; i++)
            {
                PlayerNames[i] = players[i].Name;
                int value = players[i].GetHandValue();
                HandValues[i] = value;
                if (value > 21)
                {
                    WinLose[i] = false;
                }
                else
                {
                    if (IsDealerBusted)
                    {
                        WinLose[i] = true;
                    }
                    else
                    {
                        WinLose[i] = value >= DealerValue;
                    }
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Table table     = new Table();
            var   playerOne = new BlackJackPlayer {
                Name = "Player one"
            };
            var playerTwo = new BlackJackPlayer {
                Name = "Player Two"
            };

            table.AddPlayer(playerOne);
            table.AddPlayer(playerTwo);

            table.StartNewGame();

            Console.WriteLine(table);

            table.PlayGame();

            Console.WriteLine(table);

            var results = table.GetResults();

            Console.WriteLine(results);
        }
 public Table()
 {
     Dealer = new BlackJackPlayer {
         Name = "Dealer"
     };
     Players = new List <BlackJackPlayer>();
 }
 public void AddPlayer(BlackJackPlayer player)
 {
     Players.Add(player);
 }