Ejemplo n.º 1
0
        private bool isHolding; //< Variable stores if the user is isHoldinging.

        #endregion Fields

        #region Constructors

        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        /** Default constructor creates a dealer with the max number of points.
            Note: Do not put variables or logic into the constructor. Make a function for them, and call that
            function because it is easier to test.
        */
        public BlackjackPlayer()
            : base("Dealer", 0x7FFFFFFF, true)
        {
            Hand = new BlackjackHand ();
            isHolding = false;
        }
Ejemplo n.º 2
0
 /** Constructor creates a player. */
 public BlackjackPlayer(String thisPlayerName, int startingPoints)
     : base(thisPlayerName, startingPoints, false)
 {
     Hand = new BlackjackHand ();
     isHolding = false;
 }
Ejemplo n.º 3
0
        /** Runs the unit test. */
        public override void RunTests()
        {
            Debug.Write ("Testing the Blackjack Hand class\n" + CardGame.ConsoleLine ('*') +
                            "Creating stock...\n");
            int i;  //< Temp looping variable.

            var stock = new Deck();
            stock.Shuffle();

            Debug.Write("Printing shuffled stock:\n" + stock.ToString() + "\nCreating handA...\n");

            var handA = new BlackjackHand();

            Debug.Write("Drawing 2 cards from the top of the stock...");

            for (i = 0; i < 5; i++)
                handA.AddCard(stock.DrawCard ());

            Debug.Assert(handA.NumCards == 5, "Error: There were not 5 cards in the stock!!!");

            Debug.Write("\nTesting DealHand (Deck)...\n\n");

            handA.Clear();
            handA.DealHand(stock);

            Debug.Write("Printing handA: " + handA.ToString() + "\n\n");

            Debug.WriteLine("Attempting to draw more cards than the stock has... Expect to see a bunch of add null card to CardPile errors.");

            for (i = 0; i < 60; i++)
                handA.AddCard(stock.DrawCard());

            Debug.Write("\nPrinting handA:\n\n" + handA.ToString() + "\n\nClearing Hand and shuffling the stock...");

            handA.Clear();
            stock.Shuffle();

            Debug.Assert(handA.NumCards == 0, "Error! The hand didn't clear right!\n");

            Debug.Write("\n\nTesting min and max score functions...\n");

            handA.AddCard(new Card(10, 3));
            handA.AddCard(new Card (1, 4));    //< A 10 + an ace is a 21!

            Debug.Assert(handA.GetMinScore() == 11, "Error! The min score didn't calculate properly!\n" +
                "handA.GetMinScore () = " + handA.GetMinScore() + "\n" +
                handA.ToString());
            Debug.Assert(handA.GetMaxScore() == 21, "Error! The max score didn't calculate properly!\n" +
                "handA.GetMaxScore () = " + handA.GetMaxScore() + "\n" +
                handA.ToString());

            Debug.Assert(handA.GetMinScore() <= handA.GetMaxScore(), "Error! handA's min score (" + handA.GetMinScore() + ") was greater than the max score (" + handA.GetMaxScore() + ")");

            Debug.Write("\nTesting GetCard (int)...\n\n");

            Debug.Assert(handA.GetCard(0).PipValue == 10, "Error! handA card(0)'s pip value wasn't 10!\n\n" +
                handA.ToString() + "\n\n" +
                handA.GetCard(0).ToString() +
                "\n\nhandA.GetCard (0).GetPipValue () = " + handA.GetCard(1).PipValue + "\n");

            Debug.Assert(handA.GetCard(-10) == null, "Error! Invalid card index didn't return null Card!");

            var handB = new BlackjackHand ();

            handB.AddCard(new Card (9, 1));
            handB.AddCard(new Card (4, 1));

            Debug.Assert(handB.GetMinScore() == 13 && handB.GetMaxScore() == 13, "Error! Min and Max " +
                "score we not the same, which should be 13.\n" + handA.ToString () + handB.ToString ());

            Debug.Write("Testing compare function... \n\n");

            Debug.Assert(handA.Compare(handB) > 0, "Error! The ace plus 10 didn't win!");

            Debug.Write("Compairing 5 plus King to Jack plus queen");

            handA.Clear();
            handB.Clear();

            handA.AddCard(new Card (5, 1));
            handA.AddCard(new Card (13, 1));
            handB.AddCard(new Card (11, 1));
            handB.AddCard(new Card (13, 1));

            Debug.WriteLine ("Testing the GetMaxScore () and GetMinScore ():\n" + handA.ToString () + handB.ToString ());

            Debug.Assert(handA.GetMinScore() <= handA.GetMaxScore(), "Error! handA's 2nd test min score (" + handA.GetMinScore() + ") was greater than the max score (" + handA.GetMaxScore() + ")\n" + handA.ToString () + handB.ToString ());
            Debug.Assert(handB.GetMinScore() <= handB.GetMaxScore(), "Error! handB's min score (" + handB.GetMinScore() + ") was greater than the max score (" + handB.GetMaxScore() + ")\n" + handA.ToString () + handB.ToString ());

            Debug.WriteLine ("Testing the compare functions:\n" + handA.ToString () + handB.ToString ());

            Debug.Assert(handA.Compare(handB) > 0, "Error! The handB was over 21 and the score of 15 lost!\n" + handA.ToString () + handB.ToString ());

            Debug.Write("\n\nDone testing the BlackjackHand class.\n\n\n");
        }