// methods
		public static void Play()
		{
			string playAgain;
			const int computerMaxScoreAllowed = 18; // this is the highest the computer will go score-wise before standing
			const int perfectScore = 21;

			do
			{
				Console.Clear();
				Console.WriteLine("Welcome to Blackjack!  Hit enter to draw a card, type s to stand and end game.");

				var game = new BlackjackGame("you", "computer");
				game.ShuffleDeck();

				var you = game.You;
				var computer = game.Them;

				// start out with 2 cards
				var firstCard = game.Hit(you);
				Console.WriteLine("\n" + game.DisplayPlayerCardAndScore(you, firstCard));

				var secondCard = game.Hit(you);
				Console.WriteLine("\n" + game.DisplayPlayerCardAndScore(you, secondCard));

				// your turn
				while (game.GetPlayerScore(you) < perfectScore)
				{
					var userAction = Console.ReadLine();
					if (!string.IsNullOrEmpty(userAction) && userAction.ToLower() == "s")
					{
						break;
					}

					var card = game.Hit(you);
					Console.WriteLine(game.DisplayPlayerCardAndScore(you, card));
				}

				// computer turn
				while (game.GetPlayerScore(computer) < computerMaxScoreAllowed)
				{
					var card = game.Hit(computer);
					Console.WriteLine("\n" + game.DisplayPlayerCardAndScore(computer, card));
				}

				Console.WriteLine(game.DisplayResults());
				playAgain = Console.ReadLine();

			} while (!string.IsNullOrEmpty(playAgain) && playAgain.Substring(0, 1).ToLower() == "y");
		}
Beispiel #2
0
        // methods
        public static void Play()
        {
            string    playAgain;
            const int computerMaxScoreAllowed = 18;             // this is the highest the computer will go score-wise before standing
            const int perfectScore            = 21;

            do
            {
                Console.Clear();
                Console.WriteLine("Welcome to Blackjack!  Hit enter to draw a card, type s to stand and end game.");

                var game = new BlackjackGame("you", "computer");
                game.ShuffleDeck();

                var you      = game.You;
                var computer = game.Them;

                // start out with 2 cards
                var firstCard = game.Hit(you);
                Console.WriteLine("\n" + game.DisplayPlayerCardAndScore(you, firstCard));

                var secondCard = game.Hit(you);
                Console.WriteLine("\n" + game.DisplayPlayerCardAndScore(you, secondCard));

                // your turn
                while (game.GetPlayerScore(you) < perfectScore)
                {
                    var userAction = Console.ReadLine();
                    if (!string.IsNullOrEmpty(userAction) && userAction.ToLower() == "s")
                    {
                        break;
                    }

                    var card = game.Hit(you);
                    Console.WriteLine(game.DisplayPlayerCardAndScore(you, card));
                }

                // computer turn
                while (game.GetPlayerScore(computer) < computerMaxScoreAllowed)
                {
                    var card = game.Hit(computer);
                    Console.WriteLine("\n" + game.DisplayPlayerCardAndScore(computer, card));
                }

                Console.WriteLine(game.DisplayResults());
                playAgain = Console.ReadLine();
            } while (!string.IsNullOrEmpty(playAgain) && playAgain.Substring(0, 1).ToLower() == "y");
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Type b to play Blackjack, p to play Poker, any other key to quit.");

            var userResponse = Console.ReadLine();

            switch (userResponse)
            {
            case "b":
                BlackjackGame.Play();
                break;

            case "p":
                PokerGame.Play();
                break;
            }
        }