示例#1
0
        private void CheckWinConditions()
        {
            List <Player> playerStopList = new List <Player>();

            PlayersWithBlackJack    = new PlayerCollection();
            PlayersWithoutBlackJack = new PlayerCollection();
            PlayerCollectionCurrentGame.LinqSort();
            this.BlackJackDealer.RevealAllCards();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.ResetColor();
            Decimal currentBlackJackPayout = 0.00m;

            foreach (Player currentPlayer in PlayerCollectionCurrentGame.List)
            {
                if (currentPlayer.HandValue == 21)
                {
                    PlayersWithBlackJack.AddPlayer(currentPlayer);
                }
                else
                {
                    PlayersWithoutBlackJack.AddPlayer(currentPlayer);
                }
                currentBlackJackPayout  += currentPlayer.CurrentBet;
                currentPlayer.CurrentBet = 0.00m;
            }
            //Check blackjack options.
            if (PlayersWithBlackJack.List.Count > 1 && BlackJackDealer.TotalCardValue != 21)
            {
                Decimal moneyPerPlayer = (currentBlackJackPayout / PlayersWithBlackJack.List.Count);
                foreach (Player currentPlayer in PlayersWithBlackJack.List)
                {
                    currentPlayer.CurrentMoney += moneyPerPlayer;
                    currentPlayer.CurrentBet    = 0.00m;
                }
            }
            else if (PlayersWithBlackJack.List.Count > 1 && BlackJackDealer.TotalCardValue == 21)
            {
                foreach (Player currentPlayer in PlayersWithBlackJack.List)
                {
                    currentPlayer.CurrentMoney += currentPlayer.CurrentBet;
                    currentBlackJackPayout     -= currentPlayer.CurrentBet;
                    currentPlayer.CurrentBet    = 0.00m;
                }
                BlackJackDealer.CasinoEarnings += currentBlackJackPayout;
            }
            else if (PlayersWithBlackJack.List.Count == 1)
            {
                Player player = PlayersWithBlackJack.List[0];
                player.CurrentMoney += currentBlackJackPayout;
                player.CurrentBet    = 0.00m;
            }
            else
            {
                //Execute non-blackjack options in Else
                foreach (Player currentPlayer in PlayersWithoutBlackJack.List)
                {
                    //Check win conditions
                    if (BlackJackDealer.TotalCardValue == currentPlayer.HandValue)
                    {
                        currentPlayer.CurrentMoney += currentPlayer.CurrentBet;
                    }
                    else if (BlackJackDealer.TotalCardValue < 21 && BlackJackDealer.TotalCardValue < currentPlayer.HandValue && currentPlayer.HandValue < 21)
                    {
                        currentPlayer.CurrentMoney += (currentPlayer.CurrentBet * 2);
                    }
                    else if (BlackJackDealer.TotalCardValue > 21 && currentPlayer.HandValue < 21)
                    {
                        currentPlayer.CurrentMoney += (currentPlayer.CurrentBet * 2);
                    }
                    else if (BlackJackDealer.TotalCardValue > 21 && currentPlayer.HandValue > 21)
                    {
                        currentPlayer.CurrentMoney += currentPlayer.CurrentBet;
                    }
                    else
                    {
                        BlackJackDealer.CasinoEarnings += currentPlayer.CurrentBet;
                    }
                    currentPlayer.CurrentBet = 0.00m;
                }
            }
        }
示例#2
0
        private void CheckWinConditions()
        {
            List <Player> playerStopList = new List <Player>();

            PlayersWithBlackJack    = new PlayerCollection();
            PlayersWithoutBlackJack = new PlayerCollection();
            PlayerCollectionCurrentGame.LinqSort();
            BlackJackDealer.RevealAllCards();
            foreach (Player currentPlayer in PlayerCollectionCurrentGame.List)
            {
                Console.WriteLine("{0} has a Hand value of {1}", currentPlayer.UserName, currentPlayer.HandValue);
                if (currentPlayer.HandValue == 21)
                {
                    PlayersWithBlackJack.AddPlayer(currentPlayer);
                }
                else
                {
                    PlayersWithoutBlackJack.AddPlayer(currentPlayer);
                }
            }
            //This one Works
            if (PlayersWithBlackJack.List.Count == 0 && BlackJackDealer.TotalCardValue == 21)
            {
                foreach (Player currentPlayer in PlayersWithoutBlackJack.List)
                {
                    BlackJackDealer.CollectPlayerBet(currentPlayer);
                }
            }
            else if (PlayersWithBlackJack.List.Count >= 1 && BlackJackDealer.TotalCardValue == 21 && BlackJackDealer.DealerOpenCards.Count == 2)
            {
                PlayerCollection playersWithNatural = new PlayerCollection();
                foreach (Player currentPlayer in PlayersWithBlackJack.List)
                {
                    if (currentPlayer.PlayerCards.Count == 2)
                    {
                        playersWithNatural.AddPlayer(currentPlayer);
                        BlackJackDealer.NaturalBlackJackPayout(currentPlayer);
                    }
                }
                if (playersWithNatural.List.Count == 0)
                {
                    Console.WriteLine("The dealer has a natural blackjack! Everyone loses their bet.");
                }
                else
                {
                    Decimal currentBlackJackPayout = BlackJackDealer.CreateBlackjackPayout(PlayerCollectionCurrentGame);
                    Decimal payoutPerPlayer        = currentBlackJackPayout / playersWithNatural.List.Count;
                    foreach (Player player in playersWithNatural.List)
                    {
                        PlayerCollectionCurrentGame.List.Remove(player);
                        Console.WriteLine("{0}, you have a natural Black Jack! Your share of the payout is {1}!", player.UserName, payoutPerPlayer);
                        BlackJackDealer.PayBlackjackPlayerBet(player, payoutPerPlayer);
                    }
                }
                foreach (Player player in PlayerCollectionCurrentGame.List)
                {
                    BlackJackDealer.CollectPlayerBet(player);
                }
            }
            else if (PlayersWithBlackJack.List.Count == 1)
            {
                Decimal currentBlackJackPayout = BlackJackDealer.CreateBlackjackPayout(PlayersWithoutBlackJack);
                Player  currentPlayer          = PlayersWithBlackJack.List[0];
                String  blackJackPayout        = currentBlackJackPayout.ToString("C", new CultureInfo("en-US"));
                Console.WriteLine("{0}, you have blackjack! You win {1}!", currentPlayer.UserName, blackJackPayout);
                BlackJackDealer.PayBlackjackPlayerBet(currentPlayer, currentBlackJackPayout);
            }
            else if (PlayersWithBlackJack.List.Count > 1 && BlackJackDealer.TotalCardValue != 21)
            {
                Decimal currentBlackJackPayout  = BlackJackDealer.CreateBlackjackPayout(PlayersWithoutBlackJack);
                Decimal moneyPerPlayer          = (currentBlackJackPayout / PlayersWithBlackJack.List.Count);
                String  moneyPerPlayerInDollars = moneyPerPlayer.ToString("C", new CultureInfo("en-US"));
                foreach (Player currentPlayer in PlayersWithBlackJack.List)
                {
                    Console.WriteLine("{0}, you have blackjack! You share {1}!", currentPlayer.UserName, moneyPerPlayerInDollars);
                    BlackJackDealer.PayBlackjackPlayerBet(currentPlayer, moneyPerPlayer);
                }
            }
            else if (PlayersWithBlackJack.List.Count > 1 && BlackJackDealer.TotalCardValue == 21)
            {
                foreach (Player currentPlayer in PlayersWithBlackJack.List)
                {
                    String currentBetInDollars = currentPlayer.CurrentBet.ToString("C", new CultureInfo("en-US"));
                    Console.WriteLine("{0}, you and the dealer have blackjack! You get your bet of {1} back.", currentPlayer.UserName, currentBetInDollars);
                    BlackJackDealer.ReturnPlayerBet(currentPlayer);
                }
                foreach (Player player in PlayersWithoutBlackJack.List)
                {
                    BlackJackDealer.CollectPlayerBet(player);
                }
            }
            else
            {
                //Execute non-blackjack options in Else
                foreach (Player currentPlayer in PlayersWithoutBlackJack.List)
                {
                    String currentBetInDollars = currentPlayer.CurrentBet.ToString("C", new CultureInfo("en-US"));
                    //Check win conditions
                    Console.WriteLine("{0}, you have {1} and the Dealer has {2}", currentPlayer.UserName, currentPlayer.HandValue, BlackJackDealer.TotalCardValue);
                    if (BlackJackDealer.TotalCardValue > 21 && currentPlayer.HandValue < 21)
                    {
                        currentBetInDollars = (currentPlayer.CurrentBet * 2).ToString("C", new CultureInfo("en-US"));
                        Console.WriteLine("The dealer has score that exceeds the blackjack limit! You win {0}", currentBetInDollars);
                        BlackJackDealer.PayPlayerBet(currentPlayer);
                    }
                    else if (BlackJackDealer.TotalCardValue < 21 && BlackJackDealer.TotalCardValue < currentPlayer.HandValue && currentPlayer.HandValue < 21)
                    {
                        currentBetInDollars = (currentPlayer.CurrentBet * 2).ToString("C", new CultureInfo("en-US"));
                        Console.WriteLine("You have a higher score then the dealer! You win {0}", currentBetInDollars);
                        BlackJackDealer.PayPlayerBet(currentPlayer);
                    }
                    else if (BlackJackDealer.TotalCardValue > 21 && currentPlayer.HandValue > 21)
                    {
                        currentBetInDollars = currentPlayer.CurrentBet.ToString("C", new CultureInfo("en-US"));
                        Console.WriteLine("Both you and the dealer have a higher score then 21. You get your bet of {0} back.", currentBetInDollars);
                        BlackJackDealer.ReturnPlayerBet(currentPlayer);
                    }
                    else if (BlackJackDealer.TotalCardValue == currentPlayer.HandValue)
                    {
                        currentBetInDollars = currentPlayer.CurrentBet.ToString("C", new CultureInfo("en-US"));
                        Console.WriteLine("You and the Dealer have similar scores! You get your bet of {0} back.", currentBetInDollars);
                        BlackJackDealer.ReturnPlayerBet(currentPlayer);
                    }
                    else
                    {
                        currentBetInDollars = currentPlayer.CurrentBet.ToString("C", new CultureInfo("en-US"));
                        Console.WriteLine("The Dealer has a higher score then you! You lose {0}", currentBetInDollars);
                        BlackJackDealer.CollectPlayerBet(currentPlayer);
                    }
                    currentPlayer.CurrentBet = 0.00m;
                }
            }
            String casinoEarningsInDollars = BlackJackDealer.CasinoEarnings.ToString("C", new CultureInfo("en-US"));

            Console.WriteLine("The casino currently has {0}", casinoEarningsInDollars);
            foreach (Player currentPlayer in PlayerCollectionCurrentGame.List)
            {
                Console.WriteLine("{0}, wanna play again? (y/n)", currentPlayer.UserName);
                if (!Regex.IsMatch(Console.ReadLine().ToLower(), yesPattern))
                {
                    playerStopList.Add(currentPlayer);
                }
                else
                {
                    currentPlayer.EndOfRound = false;
                }
            }
            foreach (Player currentPlayer in playerStopList)
            {
                Console.WriteLine("{0} has left the game with {1}", currentPlayer.UserName, currentPlayer.CurrentMoney);
                UpdatePlayerData(currentPlayer);
                TotalPlayerCollection.List.Remove(currentPlayer);
            }
        }