Let's do a quick walk through of the current functionality of the game so the player comes in, select
the number of players they hit, start and immediately the cards are dealt and we turn over the first
card and each one of the players hands and we'll also compare them to find the winner that's available
there.
So we want to have the ability to launch multiple attacks and to launch another attack.
So let's set that up within this round where we are listening for the button click.
And if the value of the button is attack, that means that we want to run another make cards.
So try that out and we hit start.
And if we do that again, we see that we remake the card.
So there's a few things that we do need to do in order to accommodate this.
And one of them is we need to clear out the current existing card when we come in to make the next round.
That's one of the things that we need to handle when we are making the cards.
So going into the make cards function, we need to clear out the existing content from each one of the
players as we iterate through so we can do that here as we start the loop.
So taking the players object, indicating the index value and setting the inner HTML and we can just
clear that out.
So just have a blank our HTML.
So start attack and we can see that now we're able to play the game and as we continuously press attack,
then we get the next round and all of the winners then get the cards added to their hand and we can
continuously play through and have multiple attacks.
So what if we also want to launch multiple attacks and eventually some of these players are going to
run out of cards and then we can set them as lost?
So we need to handle that as well.
And this is one of the game win conditions that we're going to do near the end of the lessons.
So in this case, we want to get the value that's contained within the input and use that value in order
to calculate how many runs we have so we can call this temp runs and using the document.
Query selector lets select the value of the input, and this is going to tell us how many rounds we
want to play.
Let's also update our RSS.
Inner turmoil, so this is where we were outputting who won and all of the round information.
So let's sit in down there below.
So we want to clear that out each time as well.
And let's set our round to equal to zero, I guess, set a few different variables here.
So one of the variables that we need as a global variable is we need to set up a variable for round
so we can update.
And we know how many rounds have been played as well as another variable four in play.
And we can use this variable to control the gameplay so we can stop it.
And started by checking the inplay value.
So going into our card listing where we're making the cart.
So first let's check to see if inplay is true.
And if it is, then that's that's where we're going to launch the make cards.
And we're also going to loop it multiple times so we can use just a regular for loop setting X to zero
and looping while temp runs is less than.
While X is less than temperance, and then what we'll do is will decrease the value of temperance as
we iterate through certain dentist content so it's easier to read.
So we're checking to see if the value of inplay is true, so this gives us the ability to control it
and also in the message area.
Let's update the inner turmoil.
So we've got new content there and we know how many rounds that we've actually gone through.
So do the round and X plus one.
And as we loop through here, this round value will continuously increase as well.
But what we'll do is we'll just make the cards each time, so let's try that.
So now we start the game and we've got the one attack and we can update this to two attacks.
And also we want to make sure that we're setting that in play to be true when we start the game.
So in start game function.
I want to set this value to be true so that we have our game functionality and our game control boolean
value.
Try that one more time.
So we attack.
We attack again.
Let's try three rounds and you can see that we've got the three rounds played.
So.
Player three one three cards.
Player two, one, three cards.
Player three, one, three cards.
So we see that the count of the cards is changing.
Let's try doing five rounds and we can see at the end of the five rounds, player two has twenty, player
three has twenty and player one has twelve.
And also noticed as well that we've got player two winning even though this is a tie.
So that's one thing that we do need to handle and we need to handle that in one of the upcoming lessons.
In order to handle what were happening here and how we can break the tie, so what we have to do is
keep flipping cards until either one runs out of cards or one of them gets a higher card than the other.
So that's the next thing that we do in the next lesson.
So go ahead and add in the boolean controller for running the game, also listening for the talk button
to be clicked and then giving us an option to run multiple rounds of the game.