Ejemplo n.º 1
0
        /// <summary>
        /// Plays the domino from the hand on the train.
        /// Flips the domino if necessary before playing.
        /// Removes the domino from the hand.
        /// Throws an exception if the domino is not in the hand
        /// or is not playable.
        /// </summary>
        public void Play(Domino d, Train t)
        {
            //recieve a domino and train, it plays the domino from the hand to the train at the last position.
            //can pass mexican train or player train as it is a generic train(superclass)
            bool   mustFlip, playable;
            Domino d1;
            int    index = 0;

            playable = t.IsPlayable(this, d, out mustFlip);
            if (playable == false)
            {
                throw new Exception("The domino is not playable.");
            }
            if (mustFlip == true)
            {
                d.Flip();
            }
            for (int i = 0; i < this.Count; i++)
            {
                d1 = this[i];
                if (d.Equals(d1))
                {
                    index = i;
                    break;
                }
            }
            this.RemoveAt(index);
            t.Add(d);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// creates a new boardyard list and populates it.
 /// </summary>
 /// <param name="maxDots"></param>
 public BoneYard(int maxDots)
 {
     if (maxDots < 6 || maxDots > 12)
     {
         throw new ArgumentException("Invalid Max Dots");
     }
     else
     {
         Domino blank = new Domino(0, 0);
         boneYardList = new List <Domino>();
         boneYardList.Add(blank);
         for (int i = 0; i <= maxDots; i++)
         {
             for (int j = 0; j <= maxDots; j++)
             {
                 bool   flag  = false;
                 Domino d     = new Domino(i, j);
                 Domino dFlip = new Domino(j, i);
                 foreach (Domino d2Check in boneYardList)
                 {
                     if (d.Equals(d2Check) || dFlip.Equals(d2Check))
                     {
                         flag = true;
                         break;
                     }
                     else
                     {
                         flag = false;
                     }
                 }
                 if (flag == false)
                 {
                     boneYardList.Add(d);
                 }
             }
         }
     }
 }