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 - Call Dealer/Player Hand scores once during `PlayerStay` #5

Closed Psypher9 closed 2 years ago

Psypher9 commented 2 years ago

After the line with await MakeDealerFinish() neither the Player or the Dealer's scores should change. You might consider updating the following to only call for scores one time and use a local variable because the hands are being re-summed on every call. Perhaps this:

        public async Task PlayerStay()
        {
            playerStayed = true;
            await MakeDealerFinish();
            if (CheckDealerScore() == ScoreState.Bust)
            {
                GameOver("Player Won");
            }
            else if (GetDealerHandScore() < GetPlayerHandScore())
            {
                GameOver("Player Won");
            }
            else if (GetDealerHandScore() > GetPlayerHandScore())
            {
                GameOver("Dealer Won");
            }
            else
            {
                GameOver("Push");
            }
        }

could become:

        public async Task PlayerStay()
        {
            playerStayed = true;
            await MakeDealerFinish();
            int dealerScore = GetDealerHandScore(); 
            int playerScore = GetPlayerHandScore();

            if (CheckDealerScore() == ScoreState.Bust || dealerScore < playerScore )
            {
                GameOver("Player Won");
            }
            else if (dealerScore  > playerScore)
            {
                GameOver("Dealer Won");
            }
            else
            {
                GameOver("Push");
            }
        }