Beispiel #1
0
        private void Deal()
        {
            //Everyone must have NUM_HAND cards available
            //Doing this in a look to keep 'randomness', rather than dealing to one person, then the next
            var dealt = false;

            if (Hands == null)
            {
                Hands = new ConcurrentDictionary <string, Hand>();
            }
            while (!dealt)
            {
                dealt = true;
                foreach (var player in Players)
                {
                    var playerfull = true;
                    if (!Hands.ContainsKey(player))
                    {
                        Hands[player] = new Hand {
                            CardsInHand = new List <Guid>()
                        };
                    }
                    if (Hands[player].CardsInHand.Count() < NUM_CARDS_PER_HAND)
                    {
                        var card = AvailableWhiteCards.FirstOrDefault();
                        if (card != Guid.Empty)
                        {
                            AvailableWhiteCards.Remove(card);
                            Hands[player].CardsInHand.Add(card);
                        }
                        else
                        {
                            dealt = true; //No cards left
                        }
                        playerfull = false;
                    }
                    dealt = dealt && playerfull;
                }
            }
        }