コード例 #1
0
ファイル: Program.cs プロジェクト: jaydenmuzzin/blackjack
        static void NewRound(CardShuffler cs, Player player, Dealer dealer)
        {
            if (cs.RestockRequired())
            {
                cs.Restock();
            }

            player.AddToHand(cs.Deal());
            dealer.AddToHand(cs.Deal());
            player.AddToHand(cs.Deal());
            dealer.AddToHand(cs.Deal(), false);

            Console.WriteLine();

            dealer.CheckBlackjack();

            if (!dealer.Blackjack)
            {
                Console.WriteLine();

                player.ShowHand();

                player.Turn(cs);

                ConsoleKeyInfo keyInfo;

                if (player.HandValue <= 21 && !player.Blackjack)
                {
                    player.ShowHand();
                    Console.WriteLine("Player has been dealt\n");
                    Console.WriteLine("Dealer's turn");
                    Console.WriteLine("Press 'Enter' to continue\n");

                    do
                    {
                        keyInfo = Console.ReadKey(true);
                    }while (keyInfo.Key != ConsoleKey.Enter);

                    dealer.ShowHand();

                    dealer.Turn(cs);

                    if (!dealer.Blackjack)
                    {
                        Console.WriteLine("Player: " + player.HandValue);
                        Console.WriteLine("Dealer: " + dealer.HandValue);
                    }
                }

                Console.WriteLine();
            }
            else
            {
                player.CheckBlackjack();
            }

            Player.DetermineResult(player, dealer);
            player.ShowRecord();
            dealer.ShowRecord();
        }
コード例 #2
0
 public void Turn(CardShuffler cs)
 {
     if (HandValue < 21)
     {
         ProposeHit(cs);
     }
     else
     {
         CheckBlackjack();
     }
 }
コード例 #3
0
        public new void Turn(CardShuffler cs)
        {
            ConsoleKeyInfo keyInfo;

            if (HandValue < 17)
            {
                do
                {
                    Console.WriteLine("Dealer hits");
                    AddToHand(cs.Deal());
                    Console.WriteLine();
                    ShowHand();

                    if (HandValue < 17)
                    {
                        Console.WriteLine("Press 'Enter' for dealer's next card\n");
                    }
                    else if (HandValue > 21)
                    {
                        Console.WriteLine("BUST\n");
                        Console.WriteLine("Press 'Enter' to continue\n");
                    }
                    else
                    {
                        Console.WriteLine("Dealer stands.\n");
                        Console.WriteLine("Press 'Enter' to continue\n");
                    }

                    do
                    {
                        keyInfo = Console.ReadKey(true);
                    }while (keyInfo.Key != ConsoleKey.Enter);
                }while (HandValue < 17);
            }
            else
            {
                Console.WriteLine("Dealer stands.\n");
                Console.WriteLine("Press 'Enter' to continue\n");

                do
                {
                    keyInfo = Console.ReadKey(true);
                }while (keyInfo.Key != ConsoleKey.Enter);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: jaydenmuzzin/blackjack
        static void StartGame()
        {
            int numRounds = 1;

            playing = true;

            Player       player = new Player();
            Dealer       dealer = new Dealer();
            CardShuffler cs     = new CardShuffler(Settings.NumDecks);

            do
            {
                if (numRounds > 1)
                {
                    cs.RetrieveCards(player, dealer);
                }

                NewRound(cs, player, dealer);

                Console.WriteLine("Would you like to play another round?");
                Console.WriteLine("Press 'Y' to start a new round");
                Console.WriteLine("Press 'Esc' to exit the game\n");

                ConsoleKeyInfo keyInfo;

                do
                {
                    keyInfo = Console.ReadKey(true);

                    if (keyInfo.Key == ConsoleKey.Y)
                    {
                        numRounds++;
                    }

                    if (keyInfo.Key == ConsoleKey.Escape)
                    {
                        playing = false;
                    }
                }while (keyInfo.Key != ConsoleKey.Y && keyInfo.Key != ConsoleKey.Escape);
            }while (playing == true);

            Console.WriteLine("Game ended\n");
        }
コード例 #5
0
        protected void ProposeHit(CardShuffler cs)
        {
            Console.WriteLine("Would you like another card?");
            Console.WriteLine("Press 'H' to hit");
            Console.WriteLine("Press 'S' to stand");
            Console.WriteLine("Press 'V' to view your hand\n");

            ConsoleKeyInfo keyInfo;
            bool           hitAvailable = true;

            do
            {
                keyInfo = Console.ReadKey(true);

                if (keyInfo.Key == ConsoleKey.H)
                {
                    AddToHand(cs.Deal());

                    hitAvailable = CanHit(hitAvailable);

                    if (hitAvailable)
                    {
                        Console.WriteLine("\nWould you like another card?");
                        Console.WriteLine("Press 'H' to hit");
                        Console.WriteLine("Press 'S' to stand");
                        Console.WriteLine("Press 'V' to view your hand\n");
                    }
                }

                if (keyInfo.Key == ConsoleKey.V)
                {
                    ShowHand();
                }

                if (keyInfo.Key == ConsoleKey.S)
                {
                    Console.WriteLine("Player stands\n");
                }
            }while (keyInfo.Key != ConsoleKey.S && hitAvailable);
        }