We've almost come to the conclusion of the gameplay part.
And, of course, we need to make some tweaks or adjustments afterwards.
And in this case, we need to find the winner of the game.
And we already have a placeholder there that's just called find winner.
So let's make some updates to it.
Select Player.
And we're going to get the calculations once again because we need to always know the score.
So we're using that score function to get the score from the player hand.
So once again, within the game, player hand object.
And also, let's get the dealer score as this way we can have a numeric score and we can do a comparison
of the score.
So the dealer of player and dealer will apply the logic for that.
So going through and let's take a hit, hit and stand.
And we do need to add in the find winner check in the dealer play function.
So when the dealer plays through.
If the dealer is greater than 17, that means the game's over.
And we need to determine the winner.
And then also down here where we're checking to see if the players over 20 won.
That means that we need to determine and find the winner as well.
And let's play through the game.
You're going to find that often times as you're building out a game.
You need to play through it many times just to make sure you are encountering the bugs or tweaks.
And it is working as expected.
So let's hit stand.
And we see that we run through and the dealer scores twenty.
The player's score is 18.
So we need to be able to determine the winner.
And we see the values of 18 and 23 in the console.
So it means that find winner is running.
So let's add in the additional logic into find a winner and checking to see if a player is greater than
21.
If the player is greater than 21, that means that the game status, tax content is going to be that
you busted or the player busted with and then will output the score so that the player can see what
score it was that they busted with.
And also, we'll do a check to see if dealer is greater than 21.
And if the dealer is greater than 21, then we're going to output that the dealer busted and we can
rate.
Dealer busted with whatever the score of dealer is.
And this is where we're going to actually do the check the winner conditions.
So we check the value of player and see if it's equal to the value of dealer.
So that means that there was a draw.
So there was no winners and update the text content so that the user knows what happens.
And then we can also output the value.
So it can be either one because they're actually going to be both the same.
So they're both equal.
So that means that this was a draw and then else.
If so, this is another alternative that could happen.
So checking to see if the value of player or we're going to wrap this in conditions here in the rounded
brackets.
So player is less than twenty two.
And we check to see if player is greater than dealer.
So we need to check to make sure it is less than twenty two because otherwise the player is busted.
And up here we're just out putting a message if it's busted.
So not taking the action.
So here we've got the actual conditions checking to see if player is less than 22.
And if player is greater than dealer that means that the player is the winner.
Another condition is if dealer is greater than 21.
That also means that the player is the winner.
So that means that the dealer busted and that would mean that this statement was true as well.
So let's update the game status text so that we output the results to the to the player and we're going
to concatenate the text so we'll rate you win and then whatever the value of the player total is.
And then lastly else.
So if that's not true, if the player's not the winner, if it's not a draw, then that means that the
dealer is the winner.
So let's update the message accordingly, that the dealer is the winner and we'll rate.
Dealer wins and whatever the value of the dealer.
So that should mean that we check and we know who the winner is.
So just do a stand.
Dealer busted with 26.
You win with 13.
So that's right that the dealer went all the way.
So he pulled seven.
Plus five, 12.
Plus four, 16.
Plus a queen.
So that's 26.
So the dealer busted with 26.
And that means that you were able to win with the 13.
And so now it should actually Reeth set back to the default where we can play the next round of the
game.
So whatever the result was, we can run the turn on function and enable the game button deal once again,
and that should trigger the ability to play the game throughout.
So even though that we've concluded this round, we're going to allow the player to play another round.
So just stand.
And in this case, the dealer wins and we can deal again.
So we deal another round of cards.
And this time the dealer wins with 17.
And try that one more time.
So, again, the dealer wins.
So we still need to set to update the score and then obviously add in the cash, which is going to make
the betting of the game and the gameplay a little bit more interesting.
So that's still all to come in the upcoming lessons.