public CardDeck(ISquad owner, IEnumerable <ICardData> cards) { Owner = owner; MaximumHandSize = 10; _drawPile = new Stack <Card>(cards.OrderBy(_ => NetRand.Next()).Select((c, i) => new Card(i, c))); _discardPile = new List <Card>(); _handCards = new List <Card>(); _bus = ServiceLocator.Instance.GetService <IMessageBus>(); }
public void DrawCard() { if (_handCards.Count >= MaximumHandSize) { return; } if (_drawPile.Count == 0) { foreach (var c in _discardPile.OrderBy(_ => NetRand.Next())) { _drawPile.Push(c); } _discardPile.Clear(); } var card = _drawPile.Pop(); _handCards.Add(card); _bus.Publish(new CardDrawnMessage(this, card)); }