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
        //Removes domino from hand
        private void Play(int index, Train t)
        {
            bool   mustFlip = false;
            Domino d        = handOfDominos[index];

            if (t is PrivateTrain)
            {
                PrivateTrain privateT = (PrivateTrain)t;
                if (privateT.IsPlayable(d, out mustFlip, this))
                {
                    handOfDominos.RemoveAt(index);
                    if (mustFlip)
                    {
                        d.Flip();
                    }
                    privateT.Play(d, this);
                }
                else
                {
                    throw new Exception("Domino " + d.ToString() + " cannot be played.");
                }
            }
            else
            {
                if (t.isPlayable(d, out mustFlip))
                {
                    handOfDominos.RemoveAt(index);
                    if (mustFlip)
                    {
                        d.Flip();
                    }
                    t.Play(d);
                }
                else
                {
                    throw new Exception("Domino " + d.ToString() + " does not match");
                }
            }
        }
 public void Play(Domino d, Hand h)
 {
     if (IsPlayable(d, out bool mustFlip, h))
     {
         if (!mustFlip)
         {
             Play(d);
         }
         else
         {
             d.Flip();
             Play(d);
         }
     }
 }
Ejemplo n.º 4
0
 public void Play(Domino d, Hand h)
 {
     if (h == this.hand || this.IsOpen)  // this is our hand
     {
         if (this.PlayableValue == d.Side1)
         {
             this.Play(d);
         }
         else if (this.PlayableValue == d.Side2)
         {
             d.Flip();
             this.Play(d);
         }
     }
 }
Ejemplo n.º 5
0
 // assumes the domino has already been removed from the hand
 public void Play(Hand h, Domino d)
 {
     if (IsPlayable(d, out bool?mustFlip))
     {
         if (mustFlip == true)
         {
             d.Flip();
         }
         dominos.Add(d);
     }
     else
     {
         throw new ArgumentException("This domino is not playable");
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Play - Does not return anything - assumes you have already checked the domino
        /// </summary>
        /// <param name="d">domino</param>
        public void Play(Domino d)
        {
            bool mustFlip = false;

            if (this.IsPlayable(d, out mustFlip))
            {
                if (mustFlip)
                {
                    d.Flip();
                }
                this.Add(d);
            }
            else
            {
                throw new ArgumentException("You just tried to play a Domino that cannot be played");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Plays the domino at the index on the train.
        /// Flips the domino if necessary before playing.
        /// Removes the domino from the hand.
        /// Throws an exception if the domino at the index
        /// is not playable.
        /// use IsPLayable from train class.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="t"></param>
        private void Play(int index, Train t)
        {
            bool   mustFlip, playable;
            Domino d = handOfDominos[index];

            playable = t.IsPlayable(this, d, out mustFlip);
            if (playable == false)
            {
                throw new Exception("The domino is not playable.");
            }
            if (mustFlip == true)
            {
                d.Flip();
            }
            this.RemoveAt(index);
            t.Add(d);
        }
Ejemplo n.º 8
0
        public void Play(Domino d, Hand h)
        {
            bool mustFlip = false;

            if (isPlayable(d, out mustFlip) == true)
            {
                if (mustFlip)
                {
                    d.Flip();
                }
                add(d);
            }
            else
            {
                throw new ArgumentException("No play for you!");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///assumes the domino has already been removed from the hand
        /// </summary>
        public void Play(Hand h, Domino d)
        {
            bool mustFlip = false;

            if (IsPlayable(h, d, out mustFlip))
            {
                if (mustFlip)
                {
                    // need to raise an event here
                    d.Flip();
                }
                Add(d);
            }
            else
            {
                throw new Exception("Domino " + d.ToString() + " does not match last domino in the train and cannot be played.");
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Plays the domino at the index on the train.
        /// Flips the domino if necessary before playing.
        /// Removes the domino from the hand.
        /// Throws an exception if the domino at the index
        /// is not playable.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="t"></param>
        private void Play(int index, Train t)
        {
            Domino d = this[index];

            if (d.Side1 != t.PlayableValue)
            {
                d.Flip();
            }
            if (d.Side1 == t.PlayableValue)
            {
                RemoveAt(index);
                t.Play(this, d);
            }
            else
            {
                throw new ArgumentException("Cannot be played!");
            }
        }
Ejemplo n.º 11
0
        public void Play(Domino d, Train t)
        {
            if (t.IsPlayable(d, out bool mustFlip))
            {
                if (mustFlip != true)
                {
                    t.Play(d);
                }
                else
                {
                    d.Flip();
                    t.Play(d);
                }
                handOfDominos.Remove(d);
            }

            throw new Exception("Domino is not playable on this train");
        }
Ejemplo n.º 12
0
        // assumes the domino has already been removed from the hand
        public void Play(Hand h, Domino d)
        {
            bool mustFlip = false;

            if (IsPlayable(h, d, out mustFlip))
            {
                if (mustFlip)
                {
                    //raise the event
                    d.Flip();
                }
                Add(d);
            }
            else
            {
                throw new Exception("Domino" + d.ToString() + " does not match last domino.");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// assumes the domino has already been removed from the hand
        /// </summary>
        /// <param name="h"></param>
        /// <param name="d"></param>
        public void Play(Hand h, Domino d)
        {
            bool mustFlip = false;

            if (IsPlayable(h, d, out mustFlip))
            {
                if (mustFlip)
                {
                    d.Flip();
                }

                Add(d);
            }
            else
            {
                throw new Exception("domino" + ToString() + "This Domino has already been removed");
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Plays the domino at the index on the train.
        /// Flips the domino if necessary before playing.
        /// Removes the domino from the hand.
        /// Throws an exception if the domino at the index
        /// is not playable.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="t"></param>
        private void Play(int index, Train t)
        {
            bool   mustFlip = false;
            Domino d        = handOfDominos[index];

            if (t.IsPlayable(this, d, out mustFlip))
            {
                handOfDominos.RemoveAt(index);
                if (mustFlip)
                {
                    d.Flip();
                }
                t.Play(this, d);
            }
            else
            {
                throw new Exception("Domino " + d.ToString() + " cannot be played on this train.");
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// // assumes the domino has already been removed from the hand
        /// hand h: what hand we are playing from? domino d has been removed form hand list.
        /// </summary>
        /// <param name="h"></param>
        /// <param name="d"></param>

        public void Play(Hand h, Domino d)
        {
            Domino myDomino;
            bool   mustFlip;
            bool   flag = IsPlayable(d, out mustFlip);

            if (flag == false)
            {
                throw new Exception("The Domino cannot be played.");
            }
            else if (mustFlip == true && flag == true)
            {
                dominos.Add(d);
            }
            else
            {
                d.Flip();
                dominos.Add(d);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Plays the first playable domino in the hand on the train
        /// Removes the domino from the hand.
        /// Returns the domino.
        /// Throws an exception if no dominos in the hand are playable.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public Domino Play(Train t)
        {
            bool   mustFlip, playable;
            Domino d1;

            for (int i = 0; i < this.Count; i++)
            {
                Domino d = this[i];
                playable = t.IsPlayable(this, d, out mustFlip);
                if (playable == true)
                {
                    if (mustFlip == true)
                    {
                        d.Flip();
                    }
                    this.RemoveAt(i);
                    return(d);
                }
            }
            throw new Exception("Cannot play");
        }
Ejemplo n.º 17
0
        public void play(Domino d)
        {
            bool mustFlip;

            if (isEmpty == false)
            {
                if (isPlayable(d, out mustFlip)) //If this is true it's side 1
                {
                    if (mustFlip == true)
                    {
                        d.Flip();
                        add(d);
                    }
                    add(d);
                }
                else
                {
                    throw new Exception("Ugh.");
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Plays the domino at the index on the train.
        /// Flips the domino if necessary before playing.
        /// Removes the domino from the hand.
        /// Throws an exception if the domino at the index
        /// is not playable. kind of like the indexer
        /// </summary>
        /// <param name="index"></param>
        /// <param name="t"></param>
        private void Play(int index, Train t) // the UI will never call this method
        {
            //get the domino
            //if its playable, flip
            //should i call play on the train
            bool   mustFlip = false;
            Domino d        = handofDominos[index];

            if (t.IsPlayable(this, d, out mustFlip))
            {
                handofDominos.RemoveAt(index);
                if (mustFlip)
                {
                    d.Flip();
                }
                t.Play(this, d);
            }
            else
            {
                //excetioon
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Finds a domino with a certain number of dots in the hand.
        /// If it can find the domino, it removes it from the hand and returns it.
        /// Otherwise it returns null
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public Domino GetDomino(int value)
        {
            int position = IndexOfDomino(value);

            if (position == -1)
            {
                return(null);
            }
            else
            {
                Domino d = handOfDominos[position];
                handOfDominos.RemoveAt(position);
                if (d.Side1 == value)
                {
                    return(d);
                }
                else
                {
                    d.Flip();
                    return(d);
                }
            }
        }