‫Welcome back.
‫And this video, you're going to get a little challenge and you should create tic tac toe.
‫As you can see here, just a console game, not a forms game or anything like that, but just a console
‫game.
‫As you can see here, with nine values or nine fields and player, one can choose a field afterwards,
‫player two can choose a field and so forth.
‫And for example, there is the field one, I enter one and now it's an oh.
‫So this is not a zero, it's an oh then player two's turn is and I'm going to enter five.
‫So now you can see five is replaced by an x and only the numbers that you can see are still available.
‫So let's say I enter five again as player one.
‫It will tell me incorrect input.
‫Please use another field.
‫All right, so I'm going to use three.
‫So let's say player two doesn't understand that you should only enter numbers and he just enters a G
‫or whatever.
‫Then it says, Please enter a number.
‫Incorrect input, please use another field.
‫Right?
‫So it's still player to turn.
‫So what is he going to do?
‫He's going to try to win.
‫So this is going to be super close.
‫Player two.
‫Is going to win and we are play to you one.
‫So he has three crosses in a row and well, please press any key to reset the game.
‫I'm going to press any key.
‫And we are.
‫We have a new round.
‫So you should also create a reset functionality.
‫All right, so that's pretty much it.
‫Try to build that.
‫You will need to use two DX arrays, you'll need to use switch and case and methods and many different
‫things that we have touched in the last videos.
‫So this is going to take quite a while and your solution might look very different to mine.
‫And yeah, in general, if you don't get anywhere, if you if this is too hard for you, no worries.
‫You can simply follow along and try to understand all the steps that I'm going through and I'm going
‫to explain everything that I'm doing.
‫But it's best if you really try by yourself, because when you try it yourself, you will find solutions
‫which will catapult your your skill by a lot, because simply by doing you'll learn most and by just
‫watching, you will not learn as much.
‫So that's really important.
‫As long as you run into errors and you fix them yourself, that's when learning really kicks in.
‫And that's why it's really important that you try it yourself.
‫All right.
‫So I hope you pause the video now and you try it and this can take up quite some time.
‫So you shouldn't be done within 5 minutes.
‫Well, maybe you are correct and you can do it.
‫But otherwise this might take, well, more than an hour or even more than 2 hours based on the solution
‫that you choose.
‫And as I said, there are many different ways to solve this problem.
‫And I have just one which I thought was the one rather close to what we have learned so far.
‫So it's using the functionality that we have all learned so far.
‫So nothing too new.
‫And yeah, that's why I'm going to go ahead and build the app now.
‫All right.
‫So as I said, I hope you tried to create it on your own.
‫So I'm going to create a new project file new.
‫Project.
‫And I'm going to call that tic tac toe exercise.
‫And then it's going to be a console app once again.
‫And let's click, okay, now before I do any complex logic where I check who has one and all those kind
‫of things, I'm going to start off very simple.
‫I'm just going to create our play field first, and by that I mean even the console writing.
‫So I'm going to create a new method and I'm going to call that public static void set field, and I
‫make it static only so that I can use it within my main method.
‫Otherwise I would have to create an object object to exercise in order to use set field.
‫But making it static is totally fine.
‫So next within my set field method, I need to write the lot of console that right line and it's going
‫to look a little like this.
‫So quotation marks, plenty empty fields, then a pipe, some empty fields, and again, some empty
‫fields.
‫So this is the first line.
‫Then console that right line again.
‫You could also use see W double tap.
‫That's the quicker version and then two empty spots or empty fields and again a pipe.
‫And then here what I do is I prepare it so that we can display the numbers.
‫And what are the numbers that I want to display?
‫Well, that's something that we will have to use later on or create later on.
‫So for now, I'm just going to say one, two and three.
‫But later on, we will need to change that.
‫So I'm going to add that to my list to do replace numbers with variables.
‫Okay.
‫Now, I need to create a similar role to that one.
‫But here I'm going to have underscores and we can change that if we see later on that this is not enough
‫or it doesn't look as good, we can easily change that later on.
‫All right.
‫So.
‫This is pretty much it.
‫We need to do that multiple times now.
‫So I'm going to copy that, actually.
‫I'm going to copy all of that.
‫And there we are.
‫And finally, one more row of this.
‫And that should be pretty much it.
‫Let's have a look.
‫Let's call this method set field and let's see how it looks on the console.
‫Actually, we need to run console, but red line or red key is even better.
‫Let's run it.
‫And there we are.
‫It's not perfectly positioned yet, so let's have a look.
‫All right.
‫So one problem here is I need five.
‫Points distance.
‫So five empty spaces.
‫Same here.
‫One, two, three, four, five.
‫That's good.
‫So now let's use this and replace the lines where we had that.
‫So here it's a little testing, you know, it's it's about making it look good and there's some testing
‫involved.
‫So I'm going to use the same approach here, and I'm going to copy those two lines and replace those
‫ones.
‫All right, now in here, we should have two in both directions.
‫Let's test it.
‫And there we are.
‫So that looks a lot better already.
‫One, two, three.
‫Those numbers should be replaced later on, as I said.
‫But that's already how we can set the field.
‫So you might imagine that this will already help us to reset the field later on.
‫All righty.
‫So next, now that we have that, we need to actually create the field.
‫And the play field should be, well, a field in terms of programming, create the play field.
‫And what it will do is static or actually not create the play field, but it's going to be the play
‫field static character.
‫So you could use, well, integers or strings in here as well.
‫But characters are the ones that are most resource efficient.
‫I'm going to call a play field and in here I need to have the different rows.
‫So one row with the one, two and three
‫and then the same thing with the next.
‫So four, five and six and so forth.
‫So I'm going to replace the numbers in a second.
‫So this one is the four, five, six, seven.
‫Actually, this is seven, eight and nine.
‫So there we are.
‫This is our play field.
‫Now, what we need to do is to actually replace those numbers here with the play field here.
‫So this is how generally our play field should look at the beginning, and we want to replace the numbers
‫in here later on.
‫By the user.
‫All right.
‫So what we use here instead of one is actually this play field at a specific position.
‫So actually, we get rid of that part here.
‫Now you need to see it a little better.
‫So this is the play field and I need to have the play field at the position zero, comma zero.
‫All right.
‫And now we do the same thing for the two.
‫So zero, comma one and zero comma two.
‫And then the second row, it's one zero, one, one and one, two.
‫If you're not sure what this means.
‫So this is row zero.
‫This is row one.
‫And that's row two.
‫So.
‫This is Rosie Rowe.
‫Here, then this is a real one.
‫And now we need to do the same thing with row two.
‫So this is going to be two zero.
‫This is going to be two one.
‫And finally, we have two, two, two, two.
‫So now let's start it again.
‫And we should still get the same result.
‫So there we are.
‫One, two, three, and so forth.
‫Great.
‫So now our playing field or playing field is prepared.
‫Now let's check out how we can get user input.
‫And what we need, therefore, is to create.
‫A variable which is going to be our player.
‫So player is going to be let's say we start with player one.
‫So we set it that player two and you will see later on why that makes sense to set it to two.
‫Then we need the user input and input is zero and I'm just going to set that to zero because none of
‫the fields here is zero.
‫So using it using zero is great here.
‫And finally, we need a boolean which checks if the input is correct, because if it's not, then we
‫want to well we want to inform the player and try to get the right input.
‫Alrighty.
‫So now that we have that we need to create a big or a very long do while so do.
‫And after many rows we have the wild statement.
‫And in here I'm just going to use.
‫True.
‫Why do they use do while with true.
‫Well, that's because I want the user to always be able to enter something in my game.
‫And in this case I do some code running in here which is not going to be automated.
‫It's dependent on user input.
‫So it's not an endless loop, but it's always going to be true as long as we play the game.
‫So that's why we need to do while.
‫True.
‫All right.
‫Next, what we need to check is, is player one the one who's who should play or is it player two So
‫whose turn is it?
‫If player is equal to two, then set player to one and else.
‫If actually we could just use els here else.
‫Player is equal to two, so you could either use els or else if in our case the player can only have
‫two values.
‫But if something goes wrong and for some reason player is increased to two, then it always will be
‫or increased.
‫And it'll always be this problem that it's always going to be the player two.
‫So that's why I'm just going to make sure that else if player is equal to one, then switch over to
‫player two.
‫So now, based on whose turn it is, I need to run a switch case statement.
‫So I'm just going to say switch player.
‫So based on whose turn it is, let's run some code.
‫Let's say the case is one.
‫So it means player ones turn.
‫And actually, let me add some code here.
‫Run code as long as.
‫The program runs.
‫So if it's player one stern, what do we want to do?
‫Well, we want to check.
‫What did he enter?
‫And assign the number.
‫Well, assign X to that number.
‫So we have here our play field.
‫So this is one, two, three.
‫And what I want now is if it's player one, then I want this to be replaced by an X.
‫So if he enters one, for example.
‫So in order to do that, I simply create another switch here, switch input because based on the input,
‫I want to check this case.
‫One So did the player enter one player or play field at the position zero zero should be replaced with
‫an x and then we want to break.
‫So then we are done.
‫By the way here it's still complaining.
‫That's because we don't break out of this switch loop here and now we do and now it's happy.
‫So I replace the play field with an x and here it's complaining because I used string and in order to
‫make sure that it works, I use CHA now.
‫So as you can see a past apostrophes.
‫They are there for characters and as you know, the play field has plenty of characters in there.
‫So it's a 2D array of characters.
‫That's why I need to use it that way.
‫All right.
‫So that's for case one.
‫And now I need to do the same thing for the different cases that we have.
‫So for case two, what do we need there?
‫We need to have zero one for case three one.
‫We're actually zero two for case four.
‫It should be one zero.
‫Case five.
‫It's one and one.
‫And if you are not sure what I do here, check again.
‫Roe zero.
‫So this is position zero zero.
‫This is position zero one, this position zero two and so forth.
‫So this is what I'm doing here.
‫So I'm replacing them with the correct values.
‫So the seven is at two and zero eight is at two and one and nine is at two and two.
‫So that's going to be.
‫What's happening if the player one enters a value.
‫And it's always going to replace it with an X.
‫Now what we can do now is we can copy this whole code and do the same thing for player two, right?
‫So we could just say, okay, let's copy this and then let's run it for player two.
‫Actually, I'm going to show you that just so you see why that is not the best approach.
‫So I'm going to add another case here.
‫Case, it's two.
‫And now we need to break out of it as well.
‫So actually this break here.
‫Should be in here and in here we break as well.
‫And we have another switch case so I could copy this code here actually and I can paste it in here.
‫But there is a nicer way we can create a method which simply checks.
‫Is it player one or is it player two are actually it's just going to return an X or an O.
‫So let's go ahead and create this method.
‫Public static void, enter x or O.
‫I'm just going to keep it simple.
‫And what I need here is I need an integer.
‫So I need an integer and I'm going to call that one player.
‫So what I do now is I cut this code out from here.
‫So switch statement, I'm going to cut it in here and I'm not going to need that one here anymore.
‫I will need the player still.
‫And what I'm going to do is I'm going to create a new character.
‫Player sign and I'm going to set that to an empty sign for now or an empty character,
‫which is not empty.
‫And it's in it's a space in here.
‫So now if player is equal to one, then actually we can do it in one row here.
‫Player sign is going to be.
‫X.
‫Else if a player is equal to two, player sign is going to be y or o in this case, actually.
‫And now.
‫We need the user input as well.
‫So I'm going to need the input.
‫And what kind of type was the input?
‫Input was an integer, right?
‫So I'm going to use input here int input and now I replace this X here with the player side.
‫All right.
‫So now what we can do is we can use this method instead of running this coast code here twice.
‫All right, now that we have this method, we actually don't even need the switch case anymore because
‫we already have the player here.
‫So we say player one and then we could simply run the code in here.
‫So let's do that.
‫Let's set the player here.
‫And because we have a little longer text here, we need to use the curly brackets or we have because
‫we have a multi line code that we want to execute.
‫That's why we need to enter this.
‫Okay.
‫So now I can go ahead and I can get rid of this whole switch case statement here and I only need to
‫call my method in here.
‫So the call method was called enter x or O, and here it's going to say enter X or O, first the player.
‫All right, it's going to be player and then the input and that's going to be the input.
‫So I just say the player and the input is what I want to get here.
‫So I do the same thing for the player, too.
‫And what that will do is it will simply set it either to X or O.
‫And it will run the code properly for me.
‫And by the way, we can get rid of this Tudou because we have replaced it already, so we don't need
‫that anymore.
‫All right.
‫Now let's check for the user input because we don't do that yet.
‫So in here I want to create another do while do while.
‫And what is the while?
‫So what is the condition?
‫It's that input correct is false.
‫So as long as the input is incorrect, I want to go ahead and try again.
‫So in here we're going to ask the player to enter his code and yeah, to go ahead.
‫So I'm just going to enter this here console.
‫Right.
‫And player at the position zero.
‫So which is the player the turn it is choose your field and now we need to get the input of the user.
‫So I'm going to use input convert to int 32 and I'm going to use console dot read line.
‫So I want to get the entry of the user and I want to convert it into our input.
‫So it's going to use that string and make an integer out of it and store it in input.
‫And now we can go ahead and use input, but the way we use input here already, but that's no problem
‫because it's a do while loop.
‫So it's going to get to this input and I'm going to change it to what we have entered.
‫So first it's going to be zero, then it's going to check again and then it's going to be what we have
‫entered.
‫All right.
‫So this is going to be our key here.
‫And now let's run it.
‫Let's see what happens.
‫All right.
‫So that we are and it doesn't show the text that we have just written.
‫So this whole line here.
‫Right.
‫But if I press enter, then it shows up.
‫And that's because we still have the read key in here.
‫So set field read key.
‫We had that earlier on so that we could still see what's in our program or in our game.
‫And if I get rid of it now, we are fine.
‫So.
‫Player one Choose your field and I'm just going to enter one for example, now it says Player to choose
‫your field and I'm going to use those different fields.
‫Now what doesn't happen yet is our text is not being updated yet.
‫So that's something that we have to take care of.
‫Now, in order to do that, we need to clear our console.
‫So console dot clear is going to happen here and now what we need to do is to set our field every time
‫that we are in this do loop.
‫So the set field should not be run within our main only once, but it should be run every single time
‫that we are within the do loop.
‫So it means we will simply set the field in here.
‫So now let's run it again.
‫The word please choose your field and I'm just going to use, let's say six.
‫Now it's place to turn, let's enter four and now we can see that six is suddenly entered.
‫Now four should be entered the next time that I enter something and there we are.
‫So we still have the problem that it's updated to late is not updated after the user has entered it,
‫but it's updated afterwards.
‫So let's check how we can solve that.
‫And that is because Set Field is before we check the player.
‫So let's do that.
‫Now we check the player and then we do the set field.
‫Now let's run it again.
‫So let's see, choose one field.
‫I'm going to choose field five and we see now it's zero or actually in oh now player two is going to
‫choose six, that's an X.
‫Now three is going to be an O, two is going to be an X and so forth.
‫So we have that functionality.
‫But what we are still lacking is the capability of checking if the user has entered something that is
‫allowed or not.
‫Because what I can still do is I can override.
‫So let's say player one chooses one player to choose this one again.
‫So as you can see now from an O, it ran to an X.
‫So player one is going to say, okay, now I want to have this field so it's going to enter it.
‫So what we need to do now is we need to check if one player has already entered something and if he
‫did, we don't want the other player to allow or be allowed to override that field.
‫So that's something we need to do in this do while loop because in here we check if the input is correct
‫and we can set the input incorrect if the user didn't enter a correct value.
‫So by the way, while we're at it, we can also fix a problem that we have here.
‫So if I enter, let's say a G, then my program crashes.
‫So I have this input which creates an error so we can get that with a try and catch, so we can solve
‫the problem with a try catch.
‫And this is going to be a very, very simple try catch.
‫So I'm not going to make it more complex than that.
‫And the only thing that I'm going to.
‫I'm gonna write onto the console right line.
‫Please enter a number.
‫So now if somebody does that again, so I'm going to enter anything.
‫It's not crashing yet, but it's also not writing onto the console because it's resetting afterwards.
‫Or is it not?
‫Well, yeah, it's resetting pretty much because we don't call for an exit statement here.
‫So what we need to do next, at least we fix that arrow.
‫Now we need to check if the input is one and the playfield.
‫At that position.
‫So at zero zero, which is the one position, is still a character of one and we need another bracket
‫here.
‫So that's the case.
‫Then set input.
‫Correct.
‫To true.
‫And now we need to do the same thing with every single field that we have.
‫So else, if input is equal to two and the play field is still open at that field at that position,
‫so it's going to be zero.
‫One is still a two.
‫Then please go ahead and set input.
‫Correct to true as well.
‫And here I'm missing another equal sign.
‫So this is what we need to copy and paste now multiple times so that we can catch each case.
‫So it's three, four, five, six.
‫And in here.
‫I ran into an error here.
‫Seven.
‫Eight.
‫And nine.
‫And now, of course, I need to replace those positions here as well, and I need to adjust those characters.
‫So seven, eight, nine.
‫Now we have the three was a02.
‫The four was at one zero.
‫Then five was at 1111 actually six was with one two.
‫That one was a20.
‫At two one and at two two.
‫So now we have all the correct cases when everything is good and now we need an LS here.
‫So else something is not correct.
‫So we want to inform the user about it.
‫So console dot right line a new line incorrect input.
‫Please use another field and we can also make sure that input correct is set to false.
‫So what we actually can do here is we can create a region.
‫So I'm going to call that region and it's going to end.
‫Just after this piece here and region.
‫So let me do that.
‫And now I also want to inform about what this region does.
‫And it's testing or test if a field is already taken, because that's the idea behind this whole region
‫or behind this whole do while code that we have here which checks okay, is this field taken or not?
‫If it's taken, then do something else.
‫If it's not taken, then go ahead.
‫So now let's run it again.
‫Let's see.
‫Player one uses one.
‫Player two tries to use one again and it says incorrect input.
‫Please use another field.
‫So he uses two.
‫Now let's use that.
‫Okay.
‫And as you can see, I can simply enter the different values and all seems to be good.
‫But as you also can see, player one has already won twice, so he has crossed here.
‫So that's something that we need to check next.
‫So we need to check if there is a winner.
‫And let's create a new region.
‫Just below set field where we check for the winner.
‫So here new region.
‫And I'm going to end the region directly and region.
‫And in here I have the whole code check winning condition.
‫And how do we do that?
‫Well, we need to check which characters do the different players have.
‫So we had that here player signed for the player.
‫One is an X for player two is an O.
‫So what we need to check now.
‫Or actually was it the right way?
‫Yeah.
‫If for play one, it's an X for player two is an O.
‫So these are the correct characters.
‫So what we need to check here or I'm going to use it with an array or make it with an array.
‫Player characters are an X and an O.
‫And now for each character that I have for each char player char in player chars, I want to check the
‫winning condition.
‫So what that will do is it will check if it's true for an X or if it's true for an O.
‫So in here we simply check, okay, is player one winning or is player two winning?
‫And we do that by checking if play field zero zero is equal to player char.
‫And Playfield
‫zero one.
‫Is equal to player char and also play field at zero two is equal to player char.
‫So if that's the case, then go ahead and run some code.
‫So in here I'm just going to write something like for now, see w we have a winner.
‫All right, so I just want to test that before we write the whole if statement, which is much, much
‫longer.
‫So player one is going to win the first row because this is the only row that we have entered here.
‫So in case the for all the three fields within that row, the, the character is the same.
‫We have a winner.
‫So that's pretty much the only thing that we have set in here.
‫So I'm going to say, okay, player one is going to be one.
‫Player two is going to be for player one is going to be two, five and three and we have a winner.
‫So you see the first row is full of zeros or of Oh's, so that means we have a winner.
‫And now what we need to do is we need to replace that with all the different conditions that we can
‫have.
‫So with all the different positions and if you look at the game, I'm just going to open it up again.
‫The possible winning conditions are one, two, three, four, five, six, seven, eight, nine.
‫Then we have 753159147258 and 369.
‫So we have one, two, three.
‫So six.
‫Plus two.
‫So we have eight different conditions in which we have a winner, and that's pretty much what we need
‫to do here.
‫So we need to create this eight times with the different options.
‫So I'm going to stop that here.
‫And each time we need to use an or sign because those are the or winning conditions.
‫So I'm going to do that six more times.
‫So we have one, two, three, four, five, six, seven, eight.
‫That's good.
‫And now, as I said, the different conditions are zero, zero and so forth.
‫Now the same thing with the one one, 011 and one two, and then with a third row 222021 and two two,
‫then we have the horizontal ones going from top to bottom.
‫So zero zero, then one zero and two zero.
‫Then we have.
‫One and one, actually.
‫Zero and one.
‫Sorry, zero one.
‫Ten one one and 1202, two, one and two, two.
‫And now we have the diagonal ones.
‫So it's zero zero.
‫Then let me check at zero zero.
‫Then one, one and two, two.
‫And finally, we have.
‫One, two, one, one.
‫And.
‫Two zero.
‫So those should be the eight conditions that we have.
‫And now we only need to check who has one.
‫So what we check here is with this long statement.
‫If.
‫Player, character or player char is equal to an x.
‫We know that player two has one.
‫So console red line in a new line player two has one.
‫And here I actually need to be very careful like that.
‫All right.
‫So that's the one case.
‫And then the other case is that the other player has one.
‫So I'm just going to use ls here and it's going to say player one has one.
‫And I also want to break out of the game here.
‫So break in here.
‫So let's run it and see if we can actually reproduce that.
‫So let's say we want to have the diagonal one.
‫So one, two, five, three, nine and we see player one has one.
‫So what we want now is we want to reset the game and we want to allow to create a new round.
‫So the player should be able to run again and play again.
‫And what we also haven't covered is a draw, so we need to still cover the draw.
‫But first, let's reset the field once we have a winner.
‫So what I want to do is before I break out, I want to reset the field.
‫So in here to do reset field and in order to set a field, we already have a function for that or a
‫method.
‫We created this set field method which does just that.
‫It sets the field once again.
‫But what it doesn't do yet, it doesn't reset our play field because our play field currently is set
‫to a specific value.
‫So this could be an X, this could be an O and so forth.
‫So in order to make sure that we can always reset, we need to copy that.
‫And it's standard version and I'm going to call it play field initial.
‫So this is how it's initially and this is the one that we constantly override.
‫So now we need another method which will do the resetting.
‫And the resetting method is going to be called public static void reset field.
‫And what I need to do here is, first of all, I need to set my play field to the play field initial.
‫So how it was initially and then I can set my field now let's reset the game once the player has one
‫and that's in here.
‫So player one has one or player two has one.
‫So let's reset just here, reset field.
‫And by the way, maybe we should also tell the player or tell the user that they can reset the game.
‫So console right line, please, and or press any key to reset the game.
‫And here we just say.
‫Console the red key and afterwards reset the game.
‫Okay.
‫Let's test it.
‫Choose your field.
‫1 to 5 three nine.
‫Player one has one.
‫Player, please press any key to reset the game.
‫I press any key and there they are.
‫We have reset the game and now it's players two turns player to turn.
‫As you can see here.
‫Choose your field.
‫Now let's try again.
‫As you can see, we have the different order now.
‫PLAYER two As one, please press any key to reset the game.
‫Great.
‫If I type anything incorrect and here I still get this error, but that's fine.
‫And that's exactly what I wanted.
‫So I catch it.
‫I catch the error with it.
‫Try catch that we had.
‫So now there is only one thing left and that's if there is a draw.
‫And there are many ways to solve this problem.
‫And the easiest one is to create a variable which is called turns, and this variable is just going
‫to hold the amount of turns that we have played already.
‫End turns is equal to zero.
‫So at the start we have zero turns and each time that we reset the field or set the field, we want
‫to increase turns by one.
‫Because this method.
‫When is it called?
‫Let's check set field.
‫It's called each time we go into this do while loop.
‫And that's only when there was a correct entry by the user.
‫Now if we have this turns field, we also need to be careful that we reset the turns field.
‫Once we reset our whole field by field, I mean like this is the field of our game.
‫But the turns is a field because it's a global variable, right?
‫So I want to reset turns once we reset the game.
‫So reset field here, we say turns is equal to zero or actually to be more precise because we increase
‫turns by one already, we need to do it just afterwards.
‫So now we only need to check if this condition is true.
‫So here we had the winning condition, if an else.
‫And here this if statement.
‫And here we have the WL statement.
‫So if we don't have a winner, we have a draw.
‫Or actually to be more precise else if turns is equal to ten, then we have a draw.
‫So what we say here is the same thing that we do here.
‫We also need to break out of the game and we also need to reset the game.
‫So reset field and.
‫We should inform the player that there was no winner.
‫So I'm just gonna enter draw as text here.
‫All right, now we solve one problem in the game, so let's, first of all, get a draw.
‫Let's check the draw first.
‫So, one, two, three, four.
‫Six five.
‫Eight, nine and seven.
‫And we see we get the draw.
‫That's fine.
‫Press any key to reset the game.
‫That works as well.
‫Now let's try it again.
‫Actually, not drawing, but winning.
‫And we see player two is one.
‫I press enter and our game does not reset and that has to do with our static variable here.
‫So this character playfield initial and what I need to do is I need to get rid of it here and I need
‫to make it and static actually to create a local variable which is going to be inside our reset field.
‫So I'm just going to create this play field initial and I'm going to set that into my play field.
‫So let's test that once again.
‫One, two, three, four, five, six, seven.
‫Play one has one.
‫Okay, now one, two, three, four, five, six, seven.
‫Play two is one under a key and you see it resets.
‫Now, something that I have figured out or tested and saw that there was still a little error is two,
‫one, three.
‫Four, then five, six and eight.
‫And as you can see, we have a condition where the player has one, but it's not caught up so or it's
‫not catched or caught here.
‫So you can see player two has one.
‫So even though player one has one with the 000 or the zero.
‫So there is still a little problem in my conditions here and you might have figured it out earlier on
‫already.
‫So I'm going to show you how to fix that.
‫And that should be this condition here.
‫So zero one, then it's one one and this one shouldn't be one two, but it should be two one.
‫Now let's test that again.
‫Let's see if we catch this condition.
‫So one, two, three, five, four, eight.
‫And we see player two as one.
‫All right, so we have that one.
‫And yeah, so that's pretty much it.
‫Our game runs and it does what it should.
‫There are some things that you could still improve, of course.
‫So for example, this character sign.
‫So we hand over an input and we check that input once again and we create a character sign and so forth.
‫But we could make it even easier.
‫So we don't take the player itself here.
‫But what we do take is a character which is the player char or player sign.
‫So it should be this could be the same thing.
‫So player sign makes more sense because we have used it here.
‫So then we wouldn't need to create all of that code here.
‫So let's get rid of that.
‫And instead when we call this method, which we do here, we hand over the character.
‫So for player one, we said it was the oh, I think and for player two it was the X.
‫So that will do the same thing.
‫And now we have decreased our code lines a little bit and you can even go ahead and improve the code
‫even further.
‫But that was just some code that I think that you should be able to write based on what you have learned
‫so far in this course.
‫All right.
‫So I hope you manage to do that, even though it looked very different in your case.
‫And please go ahead and share your solution.
‫Or if you took my solution that I have here and improved it, please go ahead and share that as well.
‫And yeah, so that's pretty much it.
‫A pretty long video, I know that, but I hope you learned a lot from it.
‫And even if you didn't do it yourself, you just followed it along and tried to build it.
‫So see you in the next video where we're going to look into a different topic.
‫So see you there.