예제 #1
0
파일: hand.cs 프로젝트: AAkins1983/CS234N
        //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");
                }
            }
        }
예제 #2
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.");
            }
        }
예제 #3
0
파일: Train.cs 프로젝트: catfood781/Lab01
        // 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.");
            }
        }
예제 #4
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.");
            }
        }