1
00:00:00,120 --> 00:00:00,910
Hey, welcome back.

2
00:00:00,930 --> 00:00:06,150
Let's play through the game to determine what we need to do next in order to accomplish the next move

3
00:00:06,150 --> 00:00:06,560
in the game.

4
00:00:06,570 --> 00:00:08,010
So we've got the start game button.

5
00:00:08,250 --> 00:00:10,380
We asked the player to select a case.

6
00:00:10,380 --> 00:00:12,360
So this is going to be their hidden case.

7
00:00:12,540 --> 00:00:17,700
And this is the one that they can choose to kind of play out until the end or take the offers as they're

8
00:00:17,700 --> 00:00:18,240
presented.

9
00:00:18,240 --> 00:00:20,580
And we've already loaded a number of different offers.

10
00:00:20,790 --> 00:00:24,720
We've built out the game board and now we've got a fully functional game board.

11
00:00:24,720 --> 00:00:30,180
So we do have already one of these values is selected, but the player has no idea what they've already

12
00:00:30,180 --> 00:00:30,780
selected.

13
00:00:30,930 --> 00:00:36,630
So the objective is to select a bunch of cases and then they get a bunch they get offers presented to

14
00:00:36,630 --> 00:00:36,840
them.

15
00:00:37,050 --> 00:00:43,170
So we don't have that offer being presented to them because it's said select one case and we selected

16
00:00:43,170 --> 00:00:46,920
four cases now and we haven't seen any of the offers being presented.

17
00:00:47,190 --> 00:00:50,220
The rest of the graphics and the view part is working.

18
00:00:50,460 --> 00:00:56,970
And the next step in order to check to see if there's an offer available is going to be when they select

19
00:00:56,970 --> 00:00:59,910
the case and they close this.

20
00:01:00,060 --> 00:01:04,110
This is where we can present the offer so we can present it within that close action.

21
00:01:04,260 --> 00:01:07,740
And that's really where they're moving next and that's how they're moving through the game.

22
00:01:08,010 --> 00:01:15,060
So already have that close popup action happening there where we're showing and we're displaying that

23
00:01:15,060 --> 00:01:18,210
logic of hiding the popup.

24
00:01:18,390 --> 00:01:25,980
But now we can apply some logic and we can offer a games, make an offer at this point, or we can check

25
00:01:25,980 --> 00:01:30,540
to see if there is an offer available or should be made at this point.

26
00:01:30,690 --> 00:01:36,120
And if there isn't, then they can continue to click through until we do have an offer or until the

27
00:01:36,120 --> 00:01:38,400
game is over and they run out of cases.

28
00:01:38,550 --> 00:01:43,860
And this is another thing that we need to account for if they've selected the last case or the second

29
00:01:43,860 --> 00:01:49,290
last case that we need to end the game so all of this can be done within the close pop up, because

30
00:01:49,290 --> 00:01:51,330
this is where we do the moves in the game.

31
00:01:51,540 --> 00:01:54,870
So we're going to output all of the game offers length.

32
00:01:55,140 --> 00:02:00,060
So as the player moves through the game, we're going to output the game offers.

33
00:02:00,420 --> 00:02:04,110
So right now we have five and we still have five.

34
00:02:04,290 --> 00:02:06,090
So we haven't been able to move through that.

35
00:02:06,300 --> 00:02:09,090
And the game offers are all coming from here.

36
00:02:09,240 --> 00:02:12,180
And notice that as well, that we removed out.

37
00:02:12,180 --> 00:02:16,500
We filtered out the ones that didn't match up with the number of values that we have.

38
00:02:16,650 --> 00:02:19,590
So that's why we've got the five items there within the offer.

39
00:02:19,710 --> 00:02:26,250
And we need to check to make sure that if an offer is available, we need to be able to make that offer.

40
00:02:26,430 --> 00:02:28,320
So let's have a condition to do that.

41
00:02:28,590 --> 00:02:34,290
And this condition is going to check the game and use that holding array.

42
00:02:34,590 --> 00:02:40,140
So the holding array, remember, is the one that we set from before where we've got all of the values

43
00:02:40,140 --> 00:02:43,890
as we constructed the game board and we need to check to see the length.

44
00:02:44,070 --> 00:02:49,080
And this is really how many items are still left or how many cases are still in play.

45
00:02:49,080 --> 00:02:56,670
And then we're taking our game offers value and we're checking to see which offer we're on.

46
00:02:57,180 --> 00:03:01,020
So we know that if we haven't made any offers, we're going to be on the first one.

47
00:03:01,500 --> 00:03:08,400
This is using an index value and with JavaScript, the arrays are zero based index value.

48
00:03:08,420 --> 00:03:16,980
So we can see that if those are equal, if we're on the offers and the offers are made and remember,

49
00:03:16,980 --> 00:03:18,390
we sorted the offers.

50
00:03:18,570 --> 00:03:24,900
So the first offer is going to pop up at fourteen and we're checking to see if this array length is

51
00:03:24,900 --> 00:03:29,640
going to be fourteen and if it is that we know that we need to add an offer.

52
00:03:29,760 --> 00:03:37,020
So let's make sure that that is working as expected and then within the console and offer.

53
00:03:37,200 --> 00:03:39,300
So this is where the offer will take place.

54
00:03:39,720 --> 00:03:40,710
Let's see if it works.

55
00:03:41,010 --> 00:03:43,140
So now we should be sending one.

56
00:03:43,140 --> 00:03:46,110
We've got fifteen left and four at fourteen.

57
00:03:46,140 --> 00:03:47,100
So we send the offer.

58
00:03:47,110 --> 00:03:52,560
So that was working so confirmed to be working and sometimes you have to do it step by step and play

59
00:03:52,560 --> 00:03:53,910
the game over and over again.

60
00:03:53,910 --> 00:03:57,270
So that's why it's always good that you play a game that you're enjoying.

61
00:03:57,900 --> 00:03:59,700
So let's do a game offer.

62
00:03:59,700 --> 00:04:01,140
We're putting this global.

63
00:04:01,350 --> 00:04:06,510
This is a brand new game offer this this is what the game is going to offer.

64
00:04:06,600 --> 00:04:12,810
And we're going to calculate out a value that we should be offering and we're going to create a brand

65
00:04:12,810 --> 00:04:15,300
new function to calculate the offer.

66
00:04:15,690 --> 00:04:21,060
And what this will do is this is going to look through all of the available author offers and it will

67
00:04:21,060 --> 00:04:23,970
come up with a value that we want to present to the user.

68
00:04:24,210 --> 00:04:28,440
So let's move down and create that function without passing any parameters.

69
00:04:28,620 --> 00:04:35,040
But we are going to be returning back the calculation and we can create a variable, call it total,

70
00:04:35,340 --> 00:04:37,350
so we'll send that value back.

71
00:04:37,740 --> 00:04:39,960
So let's see how we can work it total.

72
00:04:40,290 --> 00:04:47,090
And the way that we want to work the total is we want to loop through and get all of the total values

73
00:04:47,100 --> 00:04:50,280
of the remaining cases and we're going to divide that by two.

74
00:04:50,280 --> 00:04:53,940
And that's going to be the offer that we're going to make or we're not going to divide it by two.

75
00:04:54,120 --> 00:04:59,310
We're going to divide it by the remaining items in the game holding array.

76
00:04:59,460 --> 00:04:59,780
And so.

77
00:04:59,870 --> 00:05:03,180
That will give us a rough average of how much is left.

78
00:05:03,710 --> 00:05:09,150
So let's create total and total is from the game select.

79
00:05:09,170 --> 00:05:12,110
So this is the player's selected case value.

80
00:05:12,380 --> 00:05:17,270
And the reason we're starting with this is that we want to add all the other ones.

81
00:05:17,270 --> 00:05:22,550
And because the player doesn't know which one they've selected and we need to add this in to get an

82
00:05:22,550 --> 00:05:26,300
accurate total of all of the values that are currently still in play.

83
00:05:26,780 --> 00:05:33,320
So taking the holding array and looping through each one of the items within the holding array and putting

84
00:05:33,320 --> 00:05:34,500
a value of L.

85
00:05:34,700 --> 00:05:38,960
So we're looping through all of these and all we're going to do is we're going to total it.

86
00:05:39,170 --> 00:05:45,920
So just do a quick total of whatever the value of total plus total plus total until we get a value of.

87
00:05:46,490 --> 00:05:51,590
So now we've got value that's being returned back and we can continue to do our calculation.

88
00:05:51,890 --> 00:05:55,580
So over here we've got where we're calculating the offer.

89
00:05:55,820 --> 00:06:04,550
We need to divide it by the game holding array length value plus one, because that plus one is going

90
00:06:04,550 --> 00:06:06,650
to represent the users case.

91
00:06:06,800 --> 00:06:11,540
So let's try that and console log out the game offer.

92
00:06:11,690 --> 00:06:17,360
So now we need to select so the send offer and we're offering 35 at this point.

93
00:06:17,780 --> 00:06:23,390
And that's a fair evaluation because we did get rid of a few of the larger one and I got a log out the

94
00:06:23,390 --> 00:06:29,060
total so that we can have a better idea of what the total is that we're sending back before we're sending

95
00:06:29,060 --> 00:06:29,450
it back.

96
00:06:29,480 --> 00:06:35,440
And also do a console log adding and a bunch of ostracizes because we've got quite a few console logs,

97
00:06:35,450 --> 00:06:36,460
messages going.

98
00:06:36,470 --> 00:06:38,000
So it's a little hard to distinguish.

99
00:06:38,030 --> 00:06:42,730
So there we've got our total and we're dividing it by the number within the array.

100
00:06:42,950 --> 00:06:48,350
So the more that we pick and eventually we need to get another offer as well, that we need to move

101
00:06:48,350 --> 00:06:51,280
it to the next index value of game offers.

102
00:06:51,290 --> 00:06:53,900
So we'll take our game offer made.

103
00:06:54,270 --> 00:06:59,180
We're going to increment it by one because we have made an offer or we will be making an offer in this

104
00:06:59,180 --> 00:06:59,500
case.

105
00:06:59,930 --> 00:07:03,370
And now let's determine what we want to output for the offer.

106
00:07:03,740 --> 00:07:09,770
So good to have a condition there and then using the pop up and we're going to create a brand new pop

107
00:07:09,770 --> 00:07:09,950
up.

108
00:07:09,950 --> 00:07:11,090
So pop up too.

109
00:07:11,300 --> 00:07:13,600
And this is going to be for the offer pop up.

110
00:07:13,940 --> 00:07:20,240
So we already have the pop up one and we want to duplicate this for pop up number two so that we can

111
00:07:20,240 --> 00:07:23,600
have both pop up values to going back into here.

112
00:07:23,760 --> 00:07:31,190
And let's do this as pop up, too, and it will update this and have a message block and we'll update

113
00:07:31,190 --> 00:07:32,540
this as well as needed.

114
00:07:32,720 --> 00:07:38,360
But for now, we're going to keep it as message pop up, too, and we can send over that same HTML.

115
00:07:38,510 --> 00:07:40,220
So let's construct some HTML.

116
00:07:40,220 --> 00:07:42,400
And this is, again, that message back to the user.

117
00:07:42,560 --> 00:07:47,930
So always think of what you want to present to the user and I want to present them how many offers I've

118
00:07:47,930 --> 00:07:48,170
made.

119
00:07:48,170 --> 00:07:51,860
So offer no whatever offer value that we have.

120
00:07:51,860 --> 00:07:59,030
And getting that game offer value, offer made value is going to tell us how many offers we've made

121
00:07:59,240 --> 00:08:01,670
and notice that we've already incremented it here.

122
00:08:01,850 --> 00:08:07,520
So that means that even though it's zero based, we're going to start out at one because we've already

123
00:08:07,520 --> 00:08:13,040
done the increase of the value there and then concatenating it together to div.

124
00:08:13,220 --> 00:08:17,290
So we're sending over this HTML string to the user.

125
00:08:17,300 --> 00:08:21,560
So this is the information we're providing to them and the game offer.

126
00:08:21,590 --> 00:08:25,580
So this is the offer that we're actually going to be sending over, and that's the one that we just

127
00:08:25,580 --> 00:08:27,020
spent all that time calculating.

128
00:08:27,020 --> 00:08:34,220
So offer this so the user can see what was offered to them because of course that is important for them

129
00:08:34,220 --> 00:08:35,120
to make the decision.

130
00:08:35,210 --> 00:08:38,990
And also we need to output whatever cases are next.

131
00:08:39,290 --> 00:08:41,590
So how many more cases they need to select?

132
00:08:41,600 --> 00:08:42,890
So we calculate that.

133
00:08:42,900 --> 00:08:45,380
So that's a temp case next.

134
00:08:45,650 --> 00:08:48,350
So how many cases are next to the next offer?

135
00:08:48,530 --> 00:08:51,770
So that's, again, more information that the user needs to know.

136
00:08:51,770 --> 00:08:54,530
And creating that, let's set up that variable.

137
00:08:54,530 --> 00:08:56,210
So kempt case next.

138
00:08:56,480 --> 00:08:59,180
And this can just be a value.

139
00:08:59,210 --> 00:09:02,240
So right now we're just set and we can set it up to zero.

140
00:09:02,600 --> 00:09:07,520
So and do the calculation here on how many temporary cases are next.

141
00:09:07,730 --> 00:09:12,880
And we could actually also we might want to have an option for last offer.

142
00:09:13,160 --> 00:09:18,020
So this might not even necessarily need to equal anything and we can make an update on it.

143
00:09:18,200 --> 00:09:22,460
So let's just declare the variable and do a quick update.

144
00:09:22,670 --> 00:09:26,570
As for this one, this is going to be that it's the last case.

145
00:09:26,840 --> 00:09:31,880
So I don't want to give them how many cases are left because, of course, the last case, so there's

146
00:09:31,880 --> 00:09:38,810
no cases left so that we need a customized message and we'll just put the last offer so the user or

147
00:09:38,810 --> 00:09:41,750
the player knows how many offers are next.

148
00:09:41,750 --> 00:09:43,400
And then this is the last offer.

149
00:09:43,580 --> 00:09:49,610
So we're need to set a variable of game last offer and we're going to set that one to two.

150
00:09:49,880 --> 00:09:52,490
So that's the same one that we're set to false earlier.

151
00:09:53,030 --> 00:09:59,010
So this is our game last offer and we're going to pass over this value into the very.

152
00:09:59,080 --> 00:10:01,170
Simple message that's in the pop up message.

153
00:10:01,530 --> 00:10:08,340
So now let's do the one for the typical case where we need to calculate how many offers are left and

154
00:10:08,340 --> 00:10:12,350
we'll use that same variable, that case variable and started it.

155
00:10:12,370 --> 00:10:17,310
So this can be a string as well and giving them how many cases are left.

156
00:10:17,520 --> 00:10:22,170
So this, again, is going to be a calculation and we have all the information that we need to make

157
00:10:22,170 --> 00:10:23,200
that calculation.

158
00:10:23,700 --> 00:10:29,610
So we've got all of that existing information where we just do one more calculation of this, because

159
00:10:29,610 --> 00:10:31,110
we know it's not the last case.

160
00:10:31,380 --> 00:10:38,970
I'm going to wrap it in a bracket and I'm subtracting from that number one number, should I subtract?

161
00:10:38,980 --> 00:10:41,310
And that's just the game offers me.

162
00:10:41,340 --> 00:10:45,470
So that will give me from that game offers array.

163
00:10:45,660 --> 00:10:52,270
It's going to give me the one before it and then the one that we're currently looking at.

164
00:10:52,290 --> 00:10:57,300
And give me a calculated value because this one is going to be a larger value.

165
00:10:57,310 --> 00:10:58,780
So that's where we're subtracting it.

166
00:10:59,100 --> 00:11:03,530
So in this case, going in here, it's going to be 14 minus 12.

167
00:11:03,690 --> 00:11:05,870
And so it's going to give me a value of two.

168
00:11:05,880 --> 00:11:08,370
So it's going to go or select two.

169
00:11:08,370 --> 00:11:11,160
And let's finish the wording for the player.

170
00:11:11,940 --> 00:11:18,960
More cases sort of telling the player how many more cases they can select if they don't want to take

171
00:11:18,960 --> 00:11:19,240
the off.

172
00:11:19,260 --> 00:11:24,820
And I do need to make that condition in here and make sure that the game offer made.

173
00:11:24,840 --> 00:11:26,180
So we did incremented there.

174
00:11:26,190 --> 00:11:33,410
So keep that in mind that the game offer made and we've incremented it by one game offers length.

175
00:11:33,690 --> 00:11:37,650
So the offer made is not going to be equal to the offers length.

176
00:11:37,890 --> 00:11:41,160
And we know that we've got five offers there that are loaded.

177
00:11:41,190 --> 00:11:47,010
So again, thinking dynamically when we're building this game, we're going to see that if this increments,

178
00:11:47,100 --> 00:11:52,890
if we're on number four, then we don't have anything left which is going to equal the game, offers

179
00:11:52,920 --> 00:11:54,660
length so fully dynamic.

180
00:11:54,840 --> 00:11:59,550
And that means that it's the last offer and there's no more offers after that.

181
00:11:59,760 --> 00:12:02,010
And we're not going to be expecting any more offers.

182
00:12:02,130 --> 00:12:04,380
And we're setting the last offer to True.

183
00:12:04,530 --> 00:12:10,260
Which will trigger the end of game, because that's the last offer that we have available to the player.

184
00:12:10,770 --> 00:12:16,410
And one more thing just out in the bracket there so that we can pop up value and now we're just sending

185
00:12:16,410 --> 00:12:17,570
it over to the pop up.

186
00:12:17,580 --> 00:12:18,320
So let's try it.

187
00:12:18,750 --> 00:12:21,600
So selected case number three, select one more case.

188
00:12:21,870 --> 00:12:22,590
Great job.

189
00:12:22,780 --> 00:12:24,510
Now we need a message.

190
00:12:24,510 --> 00:12:28,410
So we've got to accept content or decline it.

191
00:12:28,680 --> 00:12:34,500
So we've got offer one at thirty five or select two more cases.

192
00:12:34,830 --> 00:12:37,650
So why isn't this coming through on pop up to.

193
00:12:38,010 --> 00:12:43,740
Let's check it out and we see that we're updating the mortal body and we're not updating mortal body

194
00:12:43,740 --> 00:12:43,980
too.

195
00:12:43,980 --> 00:12:45,190
So that was the error there.

196
00:12:45,240 --> 00:12:45,990
Great job.

197
00:12:46,170 --> 00:12:51,840
And now we see we've got the offer so offer one at thirty six or select two more cases.

198
00:12:52,080 --> 00:12:55,950
So next, we need to work in what happens, accept or decline.

199
00:12:56,130 --> 00:13:01,650
And as you can see, we can't play any further because we need to enable these as options.

200
00:13:01,920 --> 00:13:04,500
So that's the next step in the game development.

201
00:13:04,770 --> 00:13:09,570
So go ahead, add all of this stuff into your game and you can be ready to move on to the next one where

202
00:13:09,600 --> 00:13:11,280
we let the user make a decision.

203
00:13:11,430 --> 00:13:14,340
And if they accept the offer, then the game is over.

204
00:13:14,370 --> 00:13:16,080
They walk away with thirty six.

205
00:13:16,200 --> 00:13:20,340
If they decline it, then they keep playing and we're going to tell them how many more cases.

206
00:13:20,580 --> 00:13:24,960
And in two more cases we're going to have another offer for them.

207
00:13:24,960 --> 00:13:29,160
And that's going to be based on what the existing values are on the screen.
