Esempio n. 1
0
        private void UpdateWinners()
        {
            //all regular players evaluated against dealer
            foreach (RegularPlayer player in game.players)
            {
                int         pBet          = player.Bet;
                string      pName         = player.Name;
                string      dName         = game.dealer.Name;
                Winninghand currentWinner = game.ReturnWinner(player, game.dealer);
                Console.ForegroundColor = ConsoleColor.Yellow;

                if (currentWinner == Winninghand.Dealer)
                {
                    game.AddMoney(game.dealer, pBet); //add bet $ to dealer winner
                    game.RemoveMoney(player, pBet);   //remove lost $ from loser
                    Console.WriteLine($"{dName} +{pBet}$ | {pName} -{pBet}$");
                }
                if (currentWinner == Winninghand.Player)
                {
                    game.AddMoney(player, pBet);         //add bet $ to player winner
                    game.RemoveMoney(game.dealer, pBet); //remove lost $ from loser
                    Console.WriteLine($"{dName} -{pBet}$ | {pName} +{pBet}$");
                }
                if (currentWinner == Winninghand.Draw)
                {
                    //game.AddMoney(player, pBet);//player reclaim bet $
                    Console.WriteLine($"Draw between {dName} and {pName} (No $ lost for player)");
                }
                Console.ResetColor();
            }
        }
Esempio n. 2
0
        public Winninghand ReturnWinner(RegularPlayer player)
        {
            //returns winner: a regular player OR dealer:
            Winninghand winner = Rules.EvaluateWinner(player.Hand, dealer.Hand);

            return(winner);
        }
        private PlayerResultsData GetRoundResults(IPlayer player, Winninghand winner)
        {
            switch (winner)
            {
            case Winninghand.Dealer:
                return(new PlayerResultsData()
                {
                    CurrentWinner = winner,
                    InfoText = string.Format($"{player.Name} lost {player.BetAmount}$"),
                    Amount = player.BetAmount,
                });

            case Winninghand.Player:
                return(new PlayerResultsData()
                {
                    CurrentWinner = winner,
                    InfoText = string.Format($"{player.Name} won {player.BetAmount}$"),
                    Amount = player.BetAmount * 2,
                });

            case Winninghand.PlayerOnNatural21:
                return(new PlayerResultsData()
                {
                    CurrentWinner = winner,
                    InfoText = string.Format($"{player.Name} won with a natural blackjack!"),
                    Amount = 1.5m * player.BetAmount,
                });

            case Winninghand.Draw:
                return(new PlayerResultsData()
                {
                    CurrentWinner = winner,
                    InfoText = string.Format($"{player.Name} draws"),
                    Amount = player.BetAmount,
                });

            default:
                return(new PlayerResultsData());
            }
        }
        private void UpdateBalancesAfterEvaluation(AiDealer dealer, HumanPlayer player, Winninghand winner)
        {
            switch (winner)
            {
            case Winninghand.Dealer:
                new DealerWins(player, dealer).UpdateBank();
                break;

            case Winninghand.Player:
            case Winninghand.PlayerOnFake21:
                new PlayerWins(player, dealer).UpdateBank();
                break;

            case Winninghand.Draw:
            case Winninghand.BothBust:
                new Draw(player, dealer).UpdateBank();
                break;

            case Winninghand.PlayerOnNatural21:
                new PlayerWinsNatural21(player, dealer).UpdateBank();
                break;

            default:
                break;
            }

            ResetBetsAndCurrentpot(dealer, player,
                                   (d, p) =>
            {
                p.BetAmount = 0;
                d.BetAmount = 0;
            });
        }