예제 #1
0
        static void Main(string[] args)
        {
            BlackJackMain blackjack = new BlackJackMain();

            blackjack.play();

            Console.ReadLine();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("********* WELCOME TO BLACK JACK GAME*************");
            Console.WriteLine("---------------------------------------\n");
            try
            {
                int[] Comp = new int[50];
                int[] User = new int[50];
                int   i; char flag;
                int   Totcomp = 0; int Totme = 0;

                BlackJackMain objBlackJack = new BlackJackMain();               //Creating an object for calling abstract class members

                #region Assigning the first 2 cards
                User[0] = objBlackJack.Rand();                  //Assigning the first 2 cards for User
                User[1] = objBlackJack.Rand();

                Comp[0] = objBlackJack.Rand();            //Assigning the first 2 cards for Computer
                Comp[1] = objBlackJack.Rand();
                #endregion

                Totcomp = Comp[0] + Comp[1];
                Totme   = User[0] + User[1];
                Console.WriteLine("Your Cards: " + User[0] + " " + User[1] + " = " + Totme);                                                //Displaying the first 2 card values of both User and Computer
                Console.WriteLine("Computer Cards: " + Comp[0] + " " + Comp[1] + " = " + Totcomp + "\n");

                #region User's Turn
                for (i = 2; Totme < 17; i++)                           //User's Turn. The loop will run till the total of its card values doesnot reach 17
                {
                    Console.WriteLine("\nDo you want another Card (y/n)? ");
                    flag = Console.ReadKey().KeyChar;
                    if (flag == 'y')
                    {
                        User[i] = objBlackJack.Rand();
                        Totme   = Totme + User[i];
                        Console.WriteLine("\n\nHit: " + User[i] + " ,Your total is " + Totme);
                    }
                    else
                    {
                        break;
                    }
                }
                #endregion

                Console.WriteLine("\n");

                #region Computer's Turn
                for (i = 2; Totcomp < 17; i++)      //Computer's Turn. The loop will run till the total of its card values doesnot reach 17
                {
                    Comp[i] = objBlackJack.Rand();
                    Console.WriteLine("\nThe Computer takes a card: " + Comp[i]);
                    Totcomp = Totcomp + Comp[i];
                }
                #endregion

                Console.WriteLine("\n\nYour Score: " + Totme);     //Displaying the score of both user and Computer
                Console.WriteLine("\nComputer Score: " + Totcomp + "\n");

                #region Announcing the Winner
                Console.WriteLine(objBlackJack.winner(Totme, Totcomp));
                #endregion
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception is: " + e.Message);
            }
        }