예제 #1
0
        public void Play()
        {
            Player player     = new Player();
            Hand   playerHand = player.Deal(deck);

            //TODO This needs to be refactored. Too much indentation
            if (playerHand.IsBusted())
            {
                Console.WriteLine("You dun f****d up, son!");
                Console.WriteLine("Game Over!");
            }
            else
            {
                Console.WriteLine("Player stays at {0}", playerHand.Total());

                Console.WriteLine();
                Console.WriteLine("Dealer Playing");
                Dealer dealer     = new Dealer();
                Hand   dealerHand = dealer.Deal(deck);
                if (dealerHand.IsBusted())
                {
                    Console.Write("Dealer busted!");
                    Console.WriteLine();
                    Console.WriteLine("Player Wins!");
                }
                else
                {
                    Console.WriteLine();
                    if (playerHand.Total() > dealerHand.Total())
                    {
                        Console.WriteLine("Player's {0} beats Dealer's {1}", playerHand.Total(), dealerHand.Total());
                        Console.WriteLine("Player Wins!");
                    }
                    else
                    {
                        Console.WriteLine("Dealer's {1} beats Player's {0}", playerHand.Total(), dealerHand.Total());
                        Console.WriteLine("Game Over!");
                    }
                }
            }
        }
예제 #2
0
        public void Play()
        {
            Player player = new Player();
            Dealer dealer = new Dealer(deck);

            Console.WriteLine($"Dealer's first card: {dealer.ToString()}");

            Hand playerHand = player.Deal(deck);

            if (playerHand.IsBusted)
            {
                Console.WriteLine("Player busted.");
                return;
            }

            Console.WriteLine("Player stays at {0}", playerHand.Total);
            Console.WriteLine();
            Console.WriteLine("Dealer Playing");

            Hand dealerHand = dealer.Deal(deck);

            if (dealerHand.IsBusted)
            {
                Console.Write("Dealer busted.");
                return;
            }

            Console.WriteLine();
            if (playerHand.Total > dealerHand.Total)
            {
                Console.WriteLine($"Player's {playerHand.Total} beats Dealer's {dealerHand.Total}");
                Console.WriteLine("Player Wins!");
            }
            else
            {
                Console.WriteLine($"Dealer's {dealerHand.Total} beats Player's {playerHand.Total}");
                Console.WriteLine("Game Over!");
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: M011y/Blackjack
        }//end of method to change text colour

        //method to play game
        public static void Play()
        {
            //create dealer and players
            var dealer  = new Dealer(new Player("Dealer"), new List <Card>());
            var players = new List <Player>();

            CreatePlayers(players);

            Console.WriteLine();

            //deal 2 cards to each player
            foreach (Player player in players)
            {
                Console.WriteLine($"{player.Name}");
                while (player.Hand.Count < 2)
                {
                    var card = dealer.Deal();
                    player.Hand.Add(card);
                    player.Score = Score.EvaluateHand(player.Hand);
                    TextColour(card.House);
                    Console.WriteLine($"The card dealt is {card.Face} of {card.House}");
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                }

                //Display player score
                Console.WriteLine($"{player.Name}'s score is {player.Score}");

                //ask player to stick or twist
                StickOrTwist(dealer, player);

                #region Betting (Not Finished)
                //ask each player how much they want to bet
                //Console.WriteLine($"{player.Name}");
                //Console.WriteLine("How many chips would you like to put down ?");
                //string input = Console.ReadLine();
                //int chips = Convert.ToInt32(input);
                //player.Bet = Bet.TotalBet(chips);

                //Display player bet
                //Console.WriteLine($"{player.Name}'s current bet is {player.Bet}");
                //Console.WriteLine();

                ////ask if they want to bet more
                //Console.WriteLine($"Your current bet is {player.Bet}");
                //Console.WriteLine("Would you like to put down more chips? Y or N");
                //string answer = Console.ReadLine();

                ////more chips
                //if (answer is "y" || answer is "Y")
                //{
                //    Console.WriteLine("How many chips would you like to put down?");
                //    string input = Console.ReadLine();
                //    int chips = Convert.ToInt32(input);
                //    player.Bet = Bet.TotalBet(chips);
                //    Console.WriteLine($"{player.Name}'s current bet is {player.Bet}");
                //    Console.WriteLine();
                //}

                ////no more
                //else if (answer is "n" || answer is "N")
                //{
                //    Console.WriteLine("Next Player!");
                //    Console.WriteLine();
                //}
                #endregion
            }

            //get 2 random cards for dealer
            while (dealer.Hand.Count < 2)
            {
                var card = dealer.Deal();
                dealer.Hand.Add(card);
                dealer.Player.Score = Score.EvaluateHand(dealer.Hand);
                TextColour(card.House);
                Console.WriteLine($"The card dealt is {card.Face} of {card.House}");
                Console.ForegroundColor = ConsoleColor.DarkBlue;
            }

            //keep dealing if under 17
            while (dealer.Player.Score < 17)
            {
                var card = dealer.Deal();
                dealer.Hand.Add(card);
                dealer.Player.Score = Score.EvaluateHand(dealer.Hand);
                TextColour(card.House);
                Console.WriteLine($"The card dealt is {card.Face} of {card.House}");
                Console.ForegroundColor = ConsoleColor.DarkBlue;
            }

            //display dealer score
            Console.WriteLine($"Dealer's score is {dealer.Player.Score}");

            //busts or blackjacks
            BustsAndBlackjacks(players, dealer);

            //closest to 21
            Winner(players, dealer);

            //play again?
            PlayAgain();

            //pause console
            Console.ReadLine();
        }//end play method