In this lecture we're going to build on what we've learned in the last lecture and really start to design
our game.
I can write any code in this lecture but we will solve the entire problem.
So we know that the players should be prompted to play again once the game is over.
So how would we in just a few kind of lines really solve this problem.
So how I would go about it is say I'm going to write some pseudo code here.
So I say do you know play the game.
And then while
we want us to play again.
Right.
It's a very simple kind of way to solve the problem.
And you may think I'm being a bit cheeky here by just kind of really solving a very high level but you're
going to see in a second why I'm why I'm doing this.
So we've kind of Virdi solve the entire problem but we've really glossed over the real meat of it.
So let's actually break down how we played the game.
Skinner right.
Play the game here.
So we know from the description that we have to set the secret number at the start.
So maybe the very first thing to do one set secret number.
And since we don't know how to kind of choose it or change it every time we're just going to set it
to a known value.
For now
because at least then we'll be able to play the game and make any changes we need to make in order to
play the game.
For so the next step is to watch when we have to actually set the number of guesses.
Right.
And thanks to our understanding of the problem the last lecture we know exactly what to set it to.
So the the log is going to be two of the upper.
Well we know the range.
So is this going to be 100.
And it's probably going to be like this maybe maybe the ceiling of it or something.
If you remember that function in math and go to the next highest integer.
OK.
So that will be that.
And the next thing is to get the yes from where.
Right.
So I start guessing.
So get the yes from the player.
Well really what we need to do is prompt these for really prompt three four prompts the user to make
a guess.
And remember we should output the number of guesses left.
K.
so the next thing is once we get it we should Shak see if the guess is equal to the secret number or.
K.
And this might have a few cases so this is the case where if the guess is not equal to the secret number
and then kind of 5 a 1
it we should decrement each number of guesses left
and then the next thing we should do is
check to see if the class was higher or lower.
And
the secret number 8.
So if it was
OK so safe skewing it silly but
her it's five today OK.
So if it was higher and we print at the guess is too high right.
Otherwise a to b if the guess is lower
than
right that I guess was two.
And if it was exact then it's actually doesn't that doesn't matter too much.
You'll see why in a second so we have to do this multiple times right because what if they didn't guess
the numbers.
So this actually has to be all in the big.
So again use to do while loops.
Notice her using the do while here.
Because we want to do this at least once right.
We want to at least get get to see her number and then make the player guess at least once.
OK.
So while wow wow.
While the game is over
OK.
So and as I'm using English and and sort of a little bit of code so you sort of do our pseudo code here.
So this is really what I call solving the problem.
So let's go through this one more time and see if this really solves the problem.
So we do play the game wow.
We want to play again.
Right.
So we just keep doing this while we keep wanting to play.
OK.
So playing the game then is we have to again loop because it might take multiple tries for the user
to actually get the secret number.
So we set the secret number although this should be not inside.
Right.
So in fact these first steps should not be inside it.
So these steps should be this.
We only want to loop
wow they haven't gotten Yes.
So this
so what we do is we prompt the user to make a guess get guess from the player check to see if that guess
is equal to the secret number.
If it's not equal then more decrement How many guesses we have left and then check to see if it's higher
or lower than the secret number.
And then if it's higher will print that the guess is too high.
And if it's lower the print that the guess is too low.
And while the game is not over.
OK.
And then if the game is over we should then display results of the game.
Right.
So say if he
tell the player if he got it or not.
Right.
So hopefully that makes sense.
So see how it kind of went through a few iterations before before we've even like actually coded anything.
We're solving the problem or make all our mistakes right here so we don't have to have so many mistakes
later when we actually implement the code.
And so I made that mistake of having these two inside that do while loop in me and take it out because
that didn't make any sense.
K so now what do we do.
Right.
Does this solve the entire problem.
I would kind of think so right.
It seems like it does but there are a few things that kind of seem a little bit too big.
Great.
So for example like this.
Play the game thing here right.
And any anything that seems kind of too big we should actually think about making that function.
So play the game.
So to say functions
so play the game will become you know play a game.
Right.
So it's become a play game function so any anything that's really big will make into a function.
So play game is one maybe want to play again should be another one to play again or she's got some thing
to play again.
They will be a function.
You know how to do this.
The secret number is just terrible.
Same with this.
It's going to be almost literally this.
In fact he prompt the user to make a guess and then I'll put them up.
Guesses left and they get the guess from the player could be one function.
So you say get the guess from the player because we've actually made that function before remember we
had the we actually got an integer as a function.
So so sad to say.
Yes.
OK.
That would be a function
and is there any other ones.
Well maybe the game is not over.
So none of these after 5 onwards I think we know how to do that.
These will just be kind of if statements.
And we know how to compare numbers to numbers.
We know how to output whether it's too high or too low and we have to compare.
If you think so we know how do that.
So really this is game is not over.
Just make that into is game over.
OK.
So that be a function and maybe display results
it functions well let's call it like that.
OK.
So we've already done the kind of solving of the play game that's really the core of the game itself
right.
But let's solve the rest of the functions before we even start coding them.
So we again we've done we actually solve these two before.
In one of our input examples is like looping with input and then that function that we did in the practice.
So let's just skip these K because we don't really we don't need to go over that again we're just kind
of do what we did before only maybe slightly modified.
And we were so people trying to solve the is game over.
So it is game over.
When is it over.
Really.
So the game is over when the number of tries left is zero or if the player's gas was equal to the secret
number right.
So really it's just number of guesses left zero or where.
Yes.
Is equal to the seeker number ain't.
That's really there's no nothing else really magical about it.
And so let's move on to the players.
This should be pretty simple to.
So we want to tell the player that they got it if it did tell them they didn't get it if they didn't.
Right.
So even saying like if this pseudocode If player got it then
you know that they got it.
And also when the secret number again just in case that was it was one of our
requirements here.
So as the game ends by saying what the secret number was it rightless if the player gets the right number.
OK.
So when you say it otherwise
we'll say
French.
They didn't get
and also French secret name.
So that's kind of it.
I think we've really solve the problem here.
So in the next lecture we'll actually implement this whole thing and we'll see how well we've really
broken down the problem and understood the problem.
So hopefully we can implement it quite quickly.
So I'll see you in the next lecture.