Beispiel #1
0
        public string GetName()
        {
            BlackJackConsoleWriter.AskForName();
            var name = Console.ReadLine();

            return(name);
        }
Beispiel #2
0
        void DetermineWinner()
        {
            if (!Dealer.HasBust())
            {
                if (Player.CalculateValueOfHand() > Dealer.CalculateValueOfHand() ||
                    (Player.Hand.Count == 5 && Dealer.CalculateValueOfHand() != 21))
                {
                    BlackJackConsoleWriter.PlayerWins();
                    Player.ReturnDoubleMoney();
                    Player.ViewBalance();
                }
                else if (Player.CalculateValueOfHand() == Dealer.CalculateValueOfHand())
                {
                    BlackJackConsoleWriter.PlayerIsReturnedMoney();
                    Player.ReturnMoney();
                    Player.ViewBalance();
                }
                else
                {
                    BlackJackConsoleWriter.PlayerLoses();
                    Dealer.AddWinnings(Player.Bet);
                    Player.ViewBalance();
                }
            }
            else
            {
                BlackJackConsoleWriter.DealerBust();
                Player.ReturnDoubleMoney();
                Player.ViewBalance();
            }

            GameIsOngoing = false;
            CheckBalance();
        }
Beispiel #3
0
        protected override void StartGameCore()
        {
            BlackJackConsoleWriter.WriteTitle();

            var blackJackHandler = new BlackJackHandler(new Player(GetName()));

            BlackJackConsoleWriter.GreetPlayer(blackJackHandler.Player.Name);
            blackJackHandler.InitialiseGame();

            TryRestartGame();
        }
Beispiel #4
0
 void CheckBalance()
 {
     if (Player.IsBalanceZero())
     {
         GameIsOngoing = false;
         BlackJackConsoleWriter.PlayerHasNoMoney();
     }
     else
     {
         RequestNextRound();
     }
 }
Beispiel #5
0
        public void RunGameLoop()
        {
            var move = BlackJackConsoleWriter.RequestMove();

            if (BlackJackInputValidation.IsValidMove(move))
            {
                while (GameIsOngoing)
                {
                    switch (move)
                    {
                    case "1":
                        Player.Elbow(GetNewCard());
                        Player.ViewHand();

                        if (Player.HasBust())
                        {
                            BlackJackConsoleWriter.PlayerBusts();
                            Player.ViewBalance();
                            CheckBalance();
                        }

                        if (Player.Hand.Count == 5)
                        {
                            BlackJackConsoleWriter.PlayerHas5Cards();
                            Player.ReturnDoubleMoney();
                            Player.ViewBalance();
                            GameIsOngoing = false;
                        }

                        break;

                    case "2":
                        Stand();
                        break;

                    default:
                        Player.ViewHand();
                        break;
                    }

                    if (GameIsOngoing)
                    {
                        move = BlackJackConsoleWriter.RequestMove();
                    }
                }
            }
            else
            {
                BlackJackConsoleWriter.InformInvalidChoice();
            }
        }
Beispiel #6
0
        void RunGameCore()
        {
            Player.MakeBet();

            InitialiseHands();

            if (Player.CalculateValueOfHand() == 21)
            {
                BlackJackConsoleWriter.PlayerGetsBlackJack();
                Player.AddWinnings(Player.CalculateWinnings());
                Player.ViewBalance();
                GameIsOngoing = false;
                RequestNextRound();
            }

            RunGameLoop();
        }
Beispiel #7
0
        public void MakeBet()
        {
            BlackJackConsoleWriter.AskForBet();
            BlackJackConsoleWriter.ShowBalance(Balance);
            Bet = float.Parse(Console.ReadLine());

            if (Bet <= Balance)
            {
                BlackJackConsoleWriter.ShowBet(Bet);
                BlackJackConsoleWriter.ShowBalance(Balance -= Bet);
            }
            else
            {
                BlackJackConsoleWriter.ShowInsufficientFunds();
                BlackJackConsoleWriter.ShowBalance(Balance);
                MakeBet();
            }
        }
Beispiel #8
0
        public void RequestNextRound()
        {
            BlackJackConsoleWriter.AskToPlayNextRound();
            var response = Console.ReadLine();

            switch (response)
            {
            case "y":
                RefreshHandsAndDeck();
                InitialiseGame();
                break;

            case "n":
                GameIsOngoing = false;
                break;

            default:
                BlackJackConsoleWriter.GreetPlayer(Player.Name);
                break;
            }
        }
Beispiel #9
0
 public override void ViewBalance()
 {
     BlackJackConsoleWriter.ShowBalance(Balance);
 }
Beispiel #10
0
 public void ViewHand()
 {
     BlackJackConsoleWriter.ShowHand(Hand);
     BlackJackConsoleWriter.ShowHandValue(CalculateValueOfHand());
 }
Beispiel #11
0
 public void ShowValueOfHand()
 {
     BlackJackConsoleWriter.ShowHandValue(SumOfHand);
 }