public virtual void EndDrawing() { _AsynchronousDrawing = false; if (_AsynchronousCardsDrawnEventArgs != null && CardsDrawn != null) { CardsDrawn(this, _AsynchronousCardsDrawnEventArgs); } _AsynchronousCardsDrawnEventArgs = null; this.Revealed.EndChanges(); }
public CardCollection DrawFrom(DeckPosition deckPosition, int number, Object destination) { CardCollection cards = new CardCollection(); if (number <= 0) return cards; CardCollection cardsFirst = _DrawPile.Retrieve(this, deckPosition, c => true, number); cards.AddRange(cardsFirst); cards.RemovedFrom(DeckLocation.Deck, this); if (_AsynchronousDrawing) { if (_AsynchronousCardsDrawnEventArgs == null) _AsynchronousCardsDrawnEventArgs = new CardsDrawnEventArgs(cardsFirst, deckPosition, number); else _AsynchronousCardsDrawnEventArgs.Cards.AddRange(cardsFirst); } else if (CardsDrawn != null) { CardsDrawnEventArgs cdea = new CardsDrawnEventArgs(cardsFirst, deckPosition, number); CardsDrawn(this, cdea); } if (destination is Type) this.AddCardsInto((Type)destination, cardsFirst); else if (destination is DeckLocation) this.AddCardsInto((DeckLocation)destination, cardsFirst); else throw new Exception(String.Format("Destination of {0} ({1}) is not supported", destination, destination.GetType())); if (cardsFirst.Count < number && _DrawPile.Count == 0 && _DiscardPile.Count > 0) { this.ShuffleForDrawing(); CardCollection cardsSecond = _DrawPile.Retrieve(this, deckPosition, c => true, number < 0 ? number : number - cards.Count); cards.AddRange(cardsSecond); cardsSecond.RemovedFrom(DeckLocation.Deck, this); if (_AsynchronousDrawing) { if (_AsynchronousCardsDrawnEventArgs == null) _AsynchronousCardsDrawnEventArgs = new CardsDrawnEventArgs(cardsSecond, deckPosition, number); else _AsynchronousCardsDrawnEventArgs.Cards.AddRange(cardsSecond); } else if (CardsDrawn != null) { CardsDrawnEventArgs cdea = new CardsDrawnEventArgs(cardsSecond, deckPosition, number); CardsDrawn(this, cdea); } if (destination is Type) this.AddCardsInto((Type)destination, cardsSecond); else if (destination is DeckLocation) this.AddCardsInto((DeckLocation)destination, cardsSecond); else throw new Exception(String.Format("Destination of {0} ({1}) is not supported", destination, destination.GetType())); } return cards; }
public virtual void BeginDrawing() { this.Revealed.BeginChanges(); _AsynchronousDrawing = true; _AsynchronousCardsDrawnEventArgs = null; }