EthanHair / Games

A side project I'm working on that is just a website where you can play card games.
0 stars 0 forks source link

Proposal - Hands could be in a Dictionary #4

Closed Psypher9 closed 2 years ago

Psypher9 commented 2 years ago

Thinking about a property for a DealerHand and a PlayerHand you might find it easier to find issues if the Hands were condensed into a Dictionay<string, List<Card>>. For now it would simplify this area in `BlackjackGame.cs#L135-146:

        public void DealCard(string dealee)
        {
            if (dealee == "Dealer")
            {
                DealerHand.Add(_deck.DrawCard());
            }
            if (dealee == "Player")
            {
                PlayerHand.Add(_deck.DrawCard());
            }
            UpdateUI();
        }

Could be

        public void DealCard(string dealee)
        {
            Hands[dealee].Add(_deck.DrawCard());  // Could use TryGetValue for more safety but the same principle  
            UpdateUI();
        }

But this would mean that you would already have fundamental support for more players as well.