//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"); } } }
/// <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."); } }
// 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."); } }
/// <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."); } }