using DominionBase.Cards; using DominionBase.Enums; using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace DominionBase.Piles { public class DeckCollection : IPile, IEnumerable { private readonly List _decks = new List(); public DeckCollection(Deck deck) { Add(deck); } public DeckCollection(IEnumerable collection) { _decks.AddRange(collection); } public DeckCollection(params Deck[] collection) { _decks.AddRange(collection); } public void Add(Deck deck) { _decks.Add(deck); } public ItemCollection this[Categories type] { get { return new ItemCollection(_decks.SelectMany(d => d[type])); } } public ItemCollection this[Type type] { get { return new ItemCollection(_decks.SelectMany(d => d[type])); } } public ItemCollection this[string name] { get { return new ItemCollection(_decks.SelectMany(d => d[name])); } } public ItemCollection this[Predicate predicate] { get { return new ItemCollection(_decks.SelectMany(d => d[predicate])); } } public int Count { get { return _decks.Sum(d => d.Count); } } public IEnumerator GetEnumerator() { foreach (var deck in _decks) { var enumerator = deck.GetEnumerator(); while (enumerator.MoveNext()) yield return enumerator.Current; enumerator.Dispose(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public bool Contains(Card card) { return this.Any(c => c == card); } } }