コード例 #1
0
ファイル: Program.cs プロジェクト: ztang34/UCSD
        static void Main(string[] args)
        {
            Dealer myDealer = new Dealer();

            bool playAgain = false;

            List <int> cardsToReplace = new List <int>();

            do
            {
                //divider
                Console.WriteLine(new String('=', 20));

                //show credits before playing
                Console.WriteLine($"Credits: {myDealer.Credits}");
                Console.WriteLine();

                //deal cards
                myDealer.Deal();

                //show cards in poker hand
                Console.WriteLine(myDealer.ShowCards());

                //show best hand and update credits
                Console.WriteLine("Best Hand: " + myDealer.ShowBestHand());
                Console.WriteLine();

                //prompt user to select cards to hold
                string input = string.Empty;
                do
                {
                    Console.Write("Select cards to hold (Example: 135): ");
                    input = Console.ReadLine();
                }while (!(int.TryParse(input, out int cardsToHold) && ReplaceCards(cardsToHold, out cardsToReplace)));

                //replace cards
                for (int i = 0; i < cardsToReplace.Count; ++i)
                {
                    myDealer.ReplaceCard(cardsToReplace[i]);
                }

                Console.WriteLine(myDealer.ShowCards());
                Console.WriteLine("Best Hand: " + myDealer.ShowBestHand());

                Console.WriteLine($"Credits: {myDealer.Credits}");
                Console.WriteLine();

                //prompt user if wants to play again
                do
                {
                    Console.Write("Play again (y/n)?");
                }while (!CheckPlayAgain(Console.ReadLine(), out playAgain));
            }while (playAgain);
        }