예제 #1
0
        static void PlayBlackJack(List <Player> Players, Dealer dealer, CardDeck cardDecks)
        {
            //Place a bet
            foreach (Player player in Players)
            {
                Console.WriteLine($"How much would you like to bet {player.Name}? Your balance is: ${player.Chips}");
                //Capture bet
                long BetAmt = Convert.ToInt64(Console.ReadLine());
                player.MakeBet(BetAmt);
            }

            //Deal cards
            cardDecks.DealCards(Players, dealer);
            cardDecks.DisplayAllCards(Players, dealer);
            System.Threading.Thread.Sleep(2000);
            //Set up player action
            foreach (Player player in Players)
            {
                Console.WriteLine("------------------------------------------------------------------------");
                cardDecks.PlayerCardAction(player, dealer);
            }
            cardDecks.DealerCardAction(dealer);
            List <Player> RemovePlayers = new List <Player>();

            foreach (Player player in Players)
            {
                if (dealer.Score >= player.Score)
                {
                    Console.WriteLine($"{player.Name}, you lost {player.BetAmt} chips.");
                    player.Chips -= player.BetAmt;
                    if (player.Chips == 0)
                    {
                        RemovePlayers.Add(player);
                    }
                }
                else
                {
                    if (player.HasBlackJack == true)
                    {
                        player.BetAmt *= 1.5;
                        Console.WriteLine($"Winner Winner Chicken Dinner {player.Name}! You had blackjack and win {player.BetAmt}! That is 1.5x your bet.");
                        player.Chips += player.BetAmt;
                    }
                    else
                    {
                        Console.WriteLine($"{player.Name}, you won {player.BetAmt} chips.");
                        player.Chips += player.BetAmt;
                    }
                }
            }
            //Remove Bankrupt players
            foreach (Player player in RemovePlayers)
            {
                Console.WriteLine($"{player.Name}, you are bankrupt. We have kicked you out of the casino.");
                System.Threading.Thread.Sleep(1000);
                Players.Remove(player);
            }
            foreach (Player player in Players)
            {
                player.ClearPlayerData(player);
            }
            dealer.ClearDealerData(dealer);
        }