/// <summary> /// The general construction of a deck. /// </summary> /// <param name="options">The options that denotw how this deck is supposed to operate.</param> /// <param name="doInitialize"> /// Whether or not to run the initialization routine. This is generally <see langword="true"/> for creating a deck and /// <see langword="false"/> when deserializing the deck. /// </param> public Deck(IDeckOptions options, bool doInitialize = true) { Contract.Requires(options != null); Known.CollectionChanged += OnKnownChanged; Options = options; ListenToOptions(); Hands = new ReadOnlyObservableCollection <IHand <TElement> >(HandSet); _drawPile = new DrawPile <TElement>(this); _discards = new DiscardPile <TElement>(this); _table = new Table <TElement>(this); _tableau = new Tableau <TElement>(this); if (doInitialize) { Initialize(); } Initialized = true; }
/// <summary> /// Determines if an area contains an element. /// </summary> /// <param name="element">The element to look for.</param> /// <param name="location">The location to check.</param> /// <returns><see langword="true"/> if the element is in that location.</returns> public bool Contains(TElement element, Location location = Location.DrawPile) { Contract.Requires(Enum.IsDefined(typeof(Location), location)); switch (location) { case Location.DiscardPile: return(DiscardPile.Contains(element)); case Location.Hand: return(HandSet.Any(hand => hand.Contains(element))); case Location.Table: return(Table.Contains(element)); case Location.DrawPile: return(DrawPile.Contains(element)); default: throw new NotImplementedException($"The value of {location} wasn't coded for."); } return(false); }