1
00:00:00,690 --> 00:00:01,500
Welcome back.

2
00:00:01,530 --> 00:00:03,270
How's your project coming along?

3
00:00:03,270 --> 00:00:08,790
I hope you had an opportunity to try out some of the code, this lesson we're going to be updating and

4
00:00:08,790 --> 00:00:10,920
tweaking and having a wind condition.

5
00:00:11,160 --> 00:00:14,520
So keeping it at only dealing out the eight cards.

6
00:00:14,700 --> 00:00:19,650
And we can see that sometimes whenever we're only dealing out the eight cards, we almost have a winner

7
00:00:19,650 --> 00:00:19,980
here.

8
00:00:20,430 --> 00:00:24,030
So player one is lost and they're pretty much out of the game.

9
00:00:24,030 --> 00:00:29,250
And if we do one more attack, we're going to see that player three is now out of the game.

10
00:00:29,430 --> 00:00:34,760
So we should have a clear condition and checking to see if Player eight is winning.

11
00:00:35,010 --> 00:00:39,200
So we need to have a full count of how many cards are in total.

12
00:00:39,630 --> 00:00:42,480
So let's create a global object.

13
00:00:42,480 --> 00:00:43,620
We can call it total.

14
00:00:43,890 --> 00:00:48,540
And then as we build out the array, we can increase the number of total.

15
00:00:48,540 --> 00:00:52,620
So we build out our deck of cards so we know how many cards are in total.

16
00:00:52,770 --> 00:00:59,340
And that means that we can also look for the number of cards and see if one player has that many cards

17
00:00:59,580 --> 00:01:01,170
equal to that number of cards.

18
00:01:01,170 --> 00:01:04,370
And then we know that they've won the game because they actually have all of the cards.

19
00:01:04,650 --> 00:01:11,180
So where we're building the deck and every time we add a new card, we can increase the total by one.

20
00:01:11,850 --> 00:01:17,910
So this will give us the total number of cards that we've dealt out and basically a total number of

21
00:01:17,910 --> 00:01:19,220
cards that are available.

22
00:01:19,500 --> 00:01:27,540
So over here where we're checking and we're outputting, if the player has lost, we should also run

23
00:01:27,540 --> 00:01:34,830
a win condition here, meaning that if a player has, the deal's length is equal to total.

24
00:01:34,950 --> 00:01:36,390
So we'll do a quick check here.

25
00:01:36,600 --> 00:01:42,390
If DLs length is equal to total, then that player has actually won.

26
00:01:43,230 --> 00:01:49,500
So we can set the inner HTML for that player to be equal to winner.

27
00:01:50,310 --> 00:01:53,870
And this is where we can also run the restart function.

28
00:01:54,840 --> 00:02:02,640
And if this is not true, that we can go ahead and we can do as we've done before where we update and

29
00:02:02,640 --> 00:02:04,250
we add the card information.

30
00:02:04,410 --> 00:02:05,400
So let's see what happens.

31
00:02:05,700 --> 00:02:11,310
So now whenever we hit attack, you see that we get a clear winner so we can actually run the win condition,

32
00:02:11,490 --> 00:02:17,520
because at this point, this player has all of the cards and we can also output the cards length as

33
00:02:17,520 --> 00:02:17,790
well.

34
00:02:18,040 --> 00:02:19,620
So there's a little bit more information.

35
00:02:19,710 --> 00:02:24,480
And sometimes you do have to kind of play through it a few times just to make sure that everything is

36
00:02:24,480 --> 00:02:25,800
working as expected.

37
00:02:25,920 --> 00:02:28,470
But now we see we've got winner eight cards.

38
00:02:28,980 --> 00:02:33,480
So that means that we got all of the cards and we want to run our win condition here.

39
00:02:33,810 --> 00:02:39,430
So let's create a function and we can call it a win game and we're going to run this.

40
00:02:39,630 --> 00:02:42,390
So this is what happens when the game is over.

41
00:02:43,420 --> 00:02:50,200
And what we need to do at this point is we need to reset some of the options, that we've got a clear

42
00:02:50,200 --> 00:02:52,870
winner and we want to reset some of the options.

43
00:02:53,080 --> 00:03:00,130
So we want to be able to select the number of players, give the players the ability to restart and

44
00:03:00,130 --> 00:03:03,410
then have all of that functionality once again.

45
00:03:03,730 --> 00:03:07,060
So we want to run our button toggle function.

46
00:03:07,520 --> 00:03:09,140
That's one of the things that we want to do.

47
00:03:09,790 --> 00:03:17,020
We also want to output information so we can clear this out and looping through.

48
00:03:17,020 --> 00:03:19,110
So let X equals zero.

49
00:03:19,240 --> 00:03:24,250
And there's a number of ways to do this, looping through all the players objects again.

50
00:03:25,110 --> 00:03:34,080
And incrementing X by one, we're checked, we'll get the players inner object and update its HTML.

51
00:03:35,320 --> 00:03:43,990
So we can update the information or we can do winner lost if one or two, so deal x length and territory

52
00:03:43,990 --> 00:03:44,600
operator.

53
00:03:45,520 --> 00:03:51,900
So if this value is greater than total, then this is the one that's the winner.

54
00:03:52,630 --> 00:03:54,370
So we can write a winner.

55
00:03:55,360 --> 00:03:56,800
We'll make this all uppercase.

56
00:03:57,310 --> 00:04:03,670
Otherwise we're going to look and write loser so we don't have to repeat ourselves so we can get rid

57
00:04:03,670 --> 00:04:05,370
of this winner here.

58
00:04:05,380 --> 00:04:06,480
So total cards.

59
00:04:06,490 --> 00:04:13,060
So that's what we'll output and then we'll append to the inner HTML winner or loser and take that message

60
00:04:13,060 --> 00:04:13,540
area.

61
00:04:13,900 --> 00:04:18,370
And we're going to update that to have our HTML select.

62
00:04:19,560 --> 00:04:27,050
Number of players, so I have that option again to select the number of players and we might also want

63
00:04:27,050 --> 00:04:34,940
to update the QUERREY selector selecting the input element and we can update the value to equal three.

64
00:04:35,210 --> 00:04:39,590
So it's not in case that attack round has been set to quite a bit more.

65
00:04:39,800 --> 00:04:40,820
So see how that works.

66
00:04:41,090 --> 00:04:49,010
So now we've got and unfortunately so it has to be equal to so greater than or equal to total because

67
00:04:49,010 --> 00:04:50,930
of course it's equal to the total.

68
00:04:51,230 --> 00:04:53,960
So we've got winner, loser, loser lost.

69
00:04:54,110 --> 00:04:58,250
So all of that information is being output and we can restart the game.

70
00:04:58,260 --> 00:05:02,560
So we've got start again and we see that we've got a few problems that showed up.

71
00:05:02,900 --> 00:05:07,510
So we need to take care of that and do some bug fixing in the upcoming lesson.

72
00:05:07,790 --> 00:05:13,970
So now we've got the win game and we've got to reset some more information here back to its original

73
00:05:14,480 --> 00:05:15,760
when we start the game.

74
00:05:15,920 --> 00:05:19,850
And so that's maybe something that we do when we start the game is that we're going to clear out this

75
00:05:19,850 --> 00:05:20,560
game area.

76
00:05:20,810 --> 00:05:23,720
So coming up, we're going to do some bug fixing on the application.
