Hey, are you ready to make a deal?
So that's where we need to go next, is we need to be able to hook up and make these buttons actually
work.
And going into all of our game logic, we can set that up in the beginning where we're in it function
is sitting and add in the event.
So we've got some other event listeners, so we've got that close event listener.
So let's how about we add the event listeners for the deal and no deal elements.
So going back into our HTML.
So now it's been a while since we looked at this and we know that we've got accept and decline.
So we've got a deal, we've got a no deal class.
So let's use those and add them into our query selector to make a selection of those elements and we
can make a deal.
So we're going to send them actually to the same place.
And using the document query selector, we don't need to list these elements because we're not going
to be making any real changes to them.
So, deal, all we need to do is make sure that we're setting up the ADD event listener, so add event
listener and adding the event listener of a click and send them over to a function that we're going
to call make a deal.
So that's it.
So let's do one more.
And also for no deal, we're going to do the same thing.
We're going to send them both over and I'm going to also update when we get the first deal.
So that will be AR 15 and we'll have one at 14.
So we're going to have the deals right away being offered to us.
And that means that we also need to make the function in order to handle the making of the deal because
we're sending them both over to the function, making the deal, and we're going to pick up what the
content of the element says in order to distinguish between the two.
So I know we're sending it over to the same function, but we can pick up content that's contained on
the button and that's how we can differentiate between the two so we can actually know what was hit.
So within the console, taking the easy target.
So the event target and text content that's contained on there, that target and that will tell us either
that they've accepted it or they've declined the deal.
Also, what we want to do is take the page model and page model two, because this is a new action and
we want to hide that.
So do a display.
We're going to hide the model and then we do some type of action.
So we're going to check to see if this content says accept.
And if it does, then we have an excerpt of the game.
And actually, at this point, the game is pretty much over because they've accepted their case.
And we can also have another option to see if it's so.
If they don't accept it, we're just going to move on to the gameplay because then they can just select
more.
And the other thing that we need to look for is that else if and if this was the game last offer.
So if game last if our game last offer is true, that actually means that it's game over.
So either one of these conditions, we need to run a function called end game.
So let's add that function in as well.
And it's going to put it on top and we'll have a placeholder for that because we're going to take care
of that in another lesson.
So end game.
And this is just what we do to kind of reset the game.
And this at this point, the game is over.
So either way, if they're on their last offer, it's game over or if they accept it's game over.
So we want to do is we want to run the end of the game and show what's remaining.
So that's one of the things that we want to do.
And we can run the show the remaining within the end game.
So we can do that in there.
And also we're going to update the game in play.
So both of those we can put an end to both of those.
And the only thing that is different is that I want to have a different pop up message contained in
there.
So I have a different pop up message.
So, again, using the pop up message pop up model that we had and in this case, let's do a div and
you earned.
So we tell that player how much they've earned.
So within the game offer, this is because they accepted the offer.
So whatever was offered was made or the last offer was made.
That's actually what the player's going to end up with.
So we're going to have that value so it can be tickets or dollars or however you're set up and whatever
you're playing for.
So this is going to have a pop up that's going to have whatever tickets within this game and then within
the end game is going to be false because it's no longer true.
So that's going to stop the game.
It's going to halt the game from playing.
And then we also want to show the show the remaining ones.
So we want to basically open up the additional cases that are visible so we can do that as well.
And also the other one, if that's the last offer.
So we might as well do that because we're setting up.
All of the content there, so we've got the pop up was contained within your case, so you declined
the offer, which means that you took what whoever was remaining in the case.
So your case has and this is the case that you selected tickets and you can also customize that message.
And either way, the game is over.
So either one of these the game is over and we need to still show the remaining.
So we'll take care of that function in the next lesson.
So let's try this game and see how it works.
So, again, you always need to play through it quite a few times, usually in order to get a good feel
for it.
So select a case, so select number one now select zero cases.
So right away it's going to give me an offer because I did set it to at 15.
So we start with 60 and I select one.
So let's hope we get an offer right away because we selected the one case already.
So if I accept it, you earn thirty four tickets in the scheme and we should have the start button popping
up again in order to start everything all over again.
So page to display block so that we'll have the start button pop up again.
So if I accept the offer you and thirty four start select a case.
So select zero cases and so far so good.
Looks pretty good.
Select a case and this time I'm going to decline the offer, select ten more cases.
So remember this is calculating this and I'm just trying to click through really quickly and I got the
big one there.
So right now the offer is eight.
So it's based on what the values are remaining or I can select two more cases, so I'm going to just
decline that.
And offer is four, offer no force five or select one more case.
So I decline it and I got great job.
So this is the last offer.
So this is the testing of the last offer.
So either we accept it and we're going to get four or we declined it.
And we find out your case has won tickets and we start again.
We can start again.
So all of the game functionality is there.
We need to make a few minor tweaks and adjustments to make the gameplay a little bit more interesting.
But for the most part, all of our gameplay is there.
We need to just also make sure that the end of game is working properly.
So a few minor tweaks to Justman.
It's still to come.
Go ahead and conclude the game and play through it a few times, make sure that everything is working
as expected and you to be ready to move on to the next lesson where we're going to make some tweaks
to adjust to the gameplay.