public void DealCards(ICardsDeck cardsDeck) { //Need to collect cards for each player var dictionary = this.Players.ToDictionary(player => player, player => new List<Card>()); //Need to observe when players get all needed cards var playerList = new List<Player>(Players); while (playerList.Count > 0) { foreach (var player in this.Players) { if (playerList.Contains(player)) { var cardsList = dictionary[player]; if (!cardsDeck.IsDeckEmpty() && cardsList.Count < this.CalculateNumberOfNeedeCards(player)) { GetCardFromDeck(cardsList, cardsDeck); } else { playerList.Remove(player); } } } } foreach (var player in this.Players) { player.Cards.AddRange(dictionary[player]); } }
private void GetCardFromDeck(List<Card> cardList, ICardsDeck cardsDeck) { cardList.Add(cardsDeck.Pop()); }