Welcome back.
How's your project coming along?
I hope you had an opportunity to try out some of the code, this lesson we're going to be updating and
tweaking and having a wind condition.
So keeping it at only dealing out the eight cards.
And we can see that sometimes whenever we're only dealing out the eight cards, we almost have a winner
here.
So player one is lost and they're pretty much out of the game.
And if we do one more attack, we're going to see that player three is now out of the game.
So we should have a clear condition and checking to see if Player eight is winning.
So we need to have a full count of how many cards are in total.
So let's create a global object.
We can call it total.
And then as we build out the array, we can increase the number of total.
So we build out our deck of cards so we know how many cards are in total.
And that means that we can also look for the number of cards and see if one player has that many cards
equal to that number of cards.
And then we know that they've won the game because they actually have all of the cards.
So where we're building the deck and every time we add a new card, we can increase the total by one.
So this will give us the total number of cards that we've dealt out and basically a total number of
cards that are available.
So over here where we're checking and we're outputting, if the player has lost, we should also run
a win condition here, meaning that if a player has, the deal's length is equal to total.
So we'll do a quick check here.
If DLs length is equal to total, then that player has actually won.
So we can set the inner HTML for that player to be equal to winner.
And this is where we can also run the restart function.
And if this is not true, that we can go ahead and we can do as we've done before where we update and
we add the card information.
So let's see what happens.
So now whenever we hit attack, you see that we get a clear winner so we can actually run the win condition,
because at this point, this player has all of the cards and we can also output the cards length as
well.
So there's a little bit more information.
And sometimes you do have to kind of play through it a few times just to make sure that everything is
working as expected.
But now we see we've got winner eight cards.
So that means that we got all of the cards and we want to run our win condition here.
So let's create a function and we can call it a win game and we're going to run this.
So this is what happens when the game is over.
And what we need to do at this point is we need to reset some of the options, that we've got a clear
winner and we want to reset some of the options.
So we want to be able to select the number of players, give the players the ability to restart and
then have all of that functionality once again.
So we want to run our button toggle function.
That's one of the things that we want to do.
We also want to output information so we can clear this out and looping through.
So let X equals zero.
And there's a number of ways to do this, looping through all the players objects again.
And incrementing X by one, we're checked, we'll get the players inner object and update its HTML.
So we can update the information or we can do winner lost if one or two, so deal x length and territory
operator.
So if this value is greater than total, then this is the one that's the winner.
So we can write a winner.
We'll make this all uppercase.
Otherwise we're going to look and write loser so we don't have to repeat ourselves so we can get rid
of this winner here.
So total cards.
So that's what we'll output and then we'll append to the inner HTML winner or loser and take that message
area.
And we're going to update that to have our HTML select.
Number of players, so I have that option again to select the number of players and we might also want
to update the QUERREY selector selecting the input element and we can update the value to equal three.
So it's not in case that attack round has been set to quite a bit more.
So see how that works.
So now we've got and unfortunately so it has to be equal to so greater than or equal to total because
of course it's equal to the total.
So we've got winner, loser, loser lost.
So all of that information is being output and we can restart the game.
So we've got start again and we see that we've got a few problems that showed up.
So we need to take care of that and do some bug fixing in the upcoming lesson.
So now we've got the win game and we've got to reset some more information here back to its original
when we start the game.
And so that's maybe something that we do when we start the game is that we're going to clear out this
game area.
So coming up, we're going to do some bug fixing on the application.