Onwards to part two, and the next task is to start the game by explaining the rules, all you have
to do is print the rules.
So I'm going to make eight print statements.
I'm going to apply the new lines where it's necessary, so here, in here.
And where you see a vertical line, we're going to you scan the next line to get the user to press enter
when they're ready.
And for the sake of running the task, I'm going to remove this function call and then I'll compile
and run the code.
Seems like we're off to a good start, the game starts by explaining the rules.
All right, so now once the user is ready, I have to present them and the computer with a card.
This is as simple as calling the random card function twice, so I'll set a variable string, your card
is equal to a random card and string computer card is equal to another random card.
What I'll do now is I'll print each result according to the instructions I left you in Task three,
so I'll print here's your card.
Then I'll print the user's card.
Then I'll print the new line, as mentioned in the instructions.
And I'll continue printing everything according to the instructions.
OK, you're running my code once more.
Presents me with a card and it presents the computer with a card as well.
I'm going to rerun my code multiple times to make sure the computer and I keep getting random cards.
And everything seems to be working perfectly.
All right, it's time for task, for the next task is to get the dealer to draw five cards.
All this means is that we need to create a for loop that runs exactly five times.
And every time it runs, it's going to call the random card function.
So first, I'm going to print the message now the dealer will draw five cards, press enter to continue.
And then I'll create a for a loop that started equals zero.
Keeps running till I'm less than five I a plus plus in this loop is going to run five times and we want
each card in the river to show every time the user presses enter.
So it only makes sense that we write scan the next line at the beginning of every run.
And after the user presses enter at the beginning of every run, I'm going to draw a random card and
print it.
So that gives me and the computer recovered card, and now we're inside the loop, and every time I
press enter, it draws a new card and it's going to do that five times.
Now, before drawing each card, I want to print the order that it appears in.
So what I can do is print card.
And connect the current value of the counter I during each run.
And now, every time I press enter, it draws a new card and it prints the order that the card appears
in, but it starts at zero and it ends at four, which is kind of weird.
But that's to be expected because the loop starts with equaling zero and it's going to keep running
until it is less than five four, so it's going to run five times.
And during each run, it is going to equal zero one, two or three.
And then the fifth run, it's going to equal four.
But what I can do is have the counters started I equals one and make sure it keeps running as long as
I is less than or equal to five.
So this time, given our starting point and the stop condition, the loop is still going to run five
times, but the counter starts at 1:00 and it keeps coming up until it equals five, beyond which the
condition turns false and the loop breaks.
So here we enter the for loop, the counter starts at one and the loop keeps running until I equals
five and that is perfect.
That is all for task for.
I'm just going to zoom in a little bit.
But as you can see, the only hard part was really creating the random card function, the whole code.
Up to this point, I just been calling the function in different places.
OK, so we're done task for moving on to Task five, we need to determine the winner.
So if you remember in TASC three, the user was given a card and so was the computer.
I need to determine how many times the user's card matches with the river and how many times the computer's
card matches with the river.
And so you'll notice that I left you to integer variables.
They should already be in your workbook.
So inside the loop, as the dealer draws the river, I'm going to compare the user's card against the
card that's currently being drawn.
And if the user's card equals draw the card that's being drawn.
It means the user has a match, and in which case I'll increase the number of matches by one.
And if it matches the computers card.
I'll increase the number of computer matches.
And so now I'm going to print your number of matches is and I'll conduct your matches.
Then I'm going to print the computer number of matches.
Connecting the number of computer matches.
OK, so I got a king and the computer got a 10.
Hopefully I can get more matches than the computer and it seems that none of us match with the ace or
the three or the seven or the four.
And we both have zero matches.
Try this again.
Now I have a six and the computer has an eight.
But when it seems the computer has a match with eight oh and I match with a six boy, this is exciting,
seven nine and it's a tie, OK, whatever.
But in the end, it reflects an accurate score of one and one.
I have one match and the computer has one match.
And now for the last step, after the dealer dragged the river, we need to determine the winner.
So if your number of matches, the users matches, is bigger than computer matches.
We're going to print Ewin.
But if the computer ends up having more matches.
Print the computer wens.
And if they're equal.
Everyone wins.
So it seems I have three.
The computer has a J.
It's a tie and everyone wins.
Let's try and test a scenario where one of us wins.
And it's a tie again.
Oh, I think the computer is going to win this one, and it does.
Let's try and test the scenario where I would win.
So I have a 10.
The computer has a niece and it matches with two other aces in the river, so it wins once again.
And I'm just really unlucky at these Jova games.
But anyways, I'm confident that everything works the way it should.
That is all.
I hope you had fun building poker, Rido, and I hope the solution clarifies any doubts you were having,
because your big challenge is going to require you to build a similar project, blackjack.
So I hope you're ready.