Beispiel #1
0
        }//end of create player

        //method to stick or twist
        public static void StickOrTwist(Dealer dealer, Player player1)
        {
            //ask player if they want to stick or twist
            Console.Write("Do you want to stick or twist? Enter s or t: ");
            string answer = Console.ReadLine();

            //twist
            if (answer is "t" || answer is "T")
            {
                var card = dealer.Deal();
                player1.Hand.Add(card);
                player1.Score = Score.EvaluateHand(player1.Hand);
                TextColour(card.House);
                Console.WriteLine($"The card dealt is {card.Face} of {card.House}");
                Console.ForegroundColor = ConsoleColor.DarkBlue;

                //display new score
                Console.WriteLine($"Your score is {player1.Score}");

                //bust over 21
                if (player1.Score > 21)
                {
                    Console.WriteLine("You're bust!");
                    Console.WriteLine();
                }

                else
                {
                    StickOrTwist(dealer, player1);
                }
            }
Beispiel #2
0
        }//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