1
00:00:00,460 --> 00:00:04,960
What's next when you're building out a game, you've got to ask yourself, what do you want to happen

2
00:00:04,960 --> 00:00:06,330
next within the gameplay?

3
00:00:06,550 --> 00:00:09,400
So we come in, we have select number of players.

4
00:00:09,550 --> 00:00:13,780
We can select a number of players at this point and start the game.

5
00:00:13,780 --> 00:00:18,010
So we hit the start button and we are represented with all the different players.

6
00:00:18,100 --> 00:00:24,040
We've built a deck of cards and we need to also deal the deck of cards now that we have a bunch of players

7
00:00:24,220 --> 00:00:24,820
set up.

8
00:00:24,820 --> 00:00:28,080
So let's create a function in order to deal cards.

9
00:00:28,420 --> 00:00:31,140
And I also want to pass in a value in here.

10
00:00:31,300 --> 00:00:35,290
So this is going to be the first player that's going to get the card.

11
00:00:35,440 --> 00:00:39,070
And the first player that we want to retrieve the card is going to be player one.

12
00:00:39,220 --> 00:00:42,880
But within that array, they're going to be the first character there.

13
00:00:42,880 --> 00:00:45,340
So that's going to have an index value of zero.

14
00:00:45,550 --> 00:00:48,620
So that's why that one is passing in zero.

15
00:00:49,030 --> 00:00:54,880
Let's take deal cards and take our starting player card.

16
00:00:54,880 --> 00:00:56,290
So that's the card that they're on.

17
00:00:56,620 --> 00:00:58,770
We need to pass in that zero value.

18
00:00:58,840 --> 00:01:03,430
And what we're going to do is we're going to keep going and dealing into the deal.

19
00:01:03,430 --> 00:01:06,400
Cards function until we run out of cards.

20
00:01:06,610 --> 00:01:11,060
And then once we run out of cards, then that means that the deck of cards has been dealt.

21
00:01:11,500 --> 00:01:18,910
So let's take our player card value and we're going to pass in a territory operator here checking to

22
00:01:18,910 --> 00:01:26,650
see if the value of player card is greater than or equal to the player's length.

23
00:01:27,220 --> 00:01:31,470
And remember, players was that array that we created in the last one.

24
00:01:31,720 --> 00:01:34,720
So we've got a length for the players of three.

25
00:01:34,960 --> 00:01:37,870
So we're checking to see if it's larger than three.

26
00:01:38,050 --> 00:01:44,710
And if it is, then that means that whatever the value of player card is, the one that we're going

27
00:01:44,710 --> 00:01:46,450
to reset it back to zero.

28
00:01:46,720 --> 00:01:51,850
That's our starting card once again, that's our starting player so that we go back to, again, that

29
00:01:51,850 --> 00:01:53,260
first player with the index.

30
00:01:53,590 --> 00:01:59,080
And if it is larger, so if it is larger than we're going back to zero, otherwise it's going to be

31
00:01:59,080 --> 00:02:03,290
the value of player card and we can also console log that out.

32
00:02:03,310 --> 00:02:08,500
So it's a little bit easier to follow and we're going to log that out as we deal the cards.

33
00:02:08,770 --> 00:02:15,150
So we're going to continuously loop through here and we're removing cards from the deck.

34
00:02:15,340 --> 00:02:22,300
So as long as the deck has a length greater than zero, then we know that we've got more cards to deal.

35
00:02:23,020 --> 00:02:28,780
And if it doesn't have a value of greater than zero, so that means that all of the cards have been

36
00:02:28,780 --> 00:02:29,190
dealt.

37
00:02:29,500 --> 00:02:36,850
We can take our message element and update the text content to say cards dealt.

38
00:02:36,850 --> 00:02:39,400
And that means that all of the cards are dealt.

39
00:02:39,400 --> 00:02:46,050
And we can also add in a return here to return that function so that we're no longer iterating through.

40
00:02:46,640 --> 00:02:52,120
So next, what we need to do is we need to loop through here so this isn't going to do a whole lot quite

41
00:02:52,120 --> 00:02:52,420
yet.

42
00:02:52,630 --> 00:02:56,200
So we see that we've got all the player stuff that we did last time.

43
00:02:56,320 --> 00:03:01,600
And as we're looping through, we're outputting that player card value.

44
00:03:01,780 --> 00:03:07,480
So we've got player card and there's not a whole lot of information there that we have available to

45
00:03:07,480 --> 00:03:11,650
us because we're only dealing the cards once and that's just passing in.

46
00:03:11,650 --> 00:03:13,730
That same zero sets are starting zero.

47
00:03:14,020 --> 00:03:20,920
So now is where things get interesting, where what we want to do is we want to get a random index value

48
00:03:20,950 --> 00:03:25,000
from the deck of cards so that we're not taking always the top card.

49
00:03:25,150 --> 00:03:26,980
We're actually going to be the way we're dealing.

50
00:03:26,980 --> 00:03:35,140
This is we're actually selecting one of the elements randomly using math, random and then math flaw

51
00:03:35,620 --> 00:03:37,300
from our deck of cards.

52
00:03:37,300 --> 00:03:38,500
And then we're going to remove that.

53
00:03:38,830 --> 00:03:42,160
And that's where we just multiply it by the deck length.

54
00:03:42,280 --> 00:03:46,000
And that's going to give us a random index value from the deck of cards.

55
00:03:46,660 --> 00:03:51,480
So let's create the card and the card is going to have a value.

56
00:03:51,940 --> 00:03:58,900
So using the deck of cards, we're going to splice a value so changes the content of array, add new

57
00:03:58,900 --> 00:04:00,550
elements while removing old ones.

58
00:04:00,560 --> 00:04:04,240
Well, we don't want to add anything new, but we do want to remove an existing one.

59
00:04:04,480 --> 00:04:10,810
So we're existing one is available at random index and we only want to remove one card.

60
00:04:10,960 --> 00:04:16,510
And because this is going to be an array that's going to be returned back, we only want the first item

61
00:04:16,510 --> 00:04:17,500
that's available in the.

62
00:04:17,950 --> 00:04:26,290
So now if we do a console log of card, you're going to see that just after that zero, we have a card

63
00:04:26,290 --> 00:04:27,610
that was randomly picked.

64
00:04:27,640 --> 00:04:31,150
So the first card that we're dealing is the queen of diamonds.

65
00:04:31,150 --> 00:04:32,350
It's value is eleven.

66
00:04:32,500 --> 00:04:34,240
So this came when we built the card.

67
00:04:34,240 --> 00:04:35,940
So that's all the card information.

68
00:04:36,280 --> 00:04:44,020
So next thing that we want to do is take our DLS array and depending on what player card we're on.

69
00:04:44,210 --> 00:04:47,740
And remember, this is that array that we constructed in the last one.

70
00:04:47,740 --> 00:04:54,670
We're setting up the players and we added in within DLs, just empty empty arrays.

71
00:04:55,000 --> 00:04:57,190
So that built out the A structure.

72
00:04:57,310 --> 00:04:59,470
So now we can use the player.

73
00:04:59,870 --> 00:05:08,510
Hard to get the index of which array we want to add this in, so we're pushing the card into the array,

74
00:05:08,510 --> 00:05:09,180
basically.

75
00:05:09,860 --> 00:05:13,330
And if we output deals, so now we don't have to output card.

76
00:05:13,460 --> 00:05:21,530
And if we output deals, you can see that within deals we've got our first player has a first card in

77
00:05:21,530 --> 00:05:23,480
their array of cards that they have.

78
00:05:23,900 --> 00:05:31,090
So next we need to implement the player card value and do this all over again until we run out of cards.

79
00:05:31,460 --> 00:05:33,920
So we're going to return a function here.

80
00:05:34,070 --> 00:05:40,070
And the function we're returning is deal cards and we're returning the value of player card because

81
00:05:40,070 --> 00:05:41,020
we incremented it.

82
00:05:41,180 --> 00:05:46,000
So this will continuously loop through while the deck length is greater than zero.

83
00:05:46,130 --> 00:05:50,120
And if it's not greater than zero, then the cards are all dealt out.

84
00:05:50,150 --> 00:05:51,440
So let's see how this plays out.

85
00:05:51,830 --> 00:05:53,990
So let's do a quick refresh and a start.

86
00:05:54,200 --> 00:06:02,270
We get cards dealt now and as you can see, deals array, we have all of the cards have been dealt out

87
00:06:02,270 --> 00:06:02,870
randomly.

88
00:06:03,080 --> 00:06:08,420
So we see that we've got a total of all of the cards dealt out.

89
00:06:09,540 --> 00:06:18,840
Into the iRace, so we've got 18 plus 17 plus 17, so that's a total of 52 cards, all Datto randomly.

90
00:06:18,840 --> 00:06:25,260
So every time we deal the cards, it's going to be a random sampling of the cards for each player.

91
00:06:25,440 --> 00:06:28,040
And this the nice thing about it here, this is fully dynamic.

92
00:06:28,070 --> 00:06:34,110
So if we have four players and then we look at the deals array, you can see that it's dealt it out

93
00:06:34,110 --> 00:06:35,580
to all four players.

94
00:06:35,700 --> 00:06:40,380
So each one in this case got 13 cards and these are all the cards at random.

95
00:06:40,650 --> 00:06:47,940
So this is how you can select a number of players, deal out card cards to them and build a deck and

96
00:06:47,940 --> 00:06:52,230
deal out those cards to them and have this all dynamically available.

97
00:06:52,230 --> 00:06:57,250
So it doesn't matter how many players you have, it will always deal at the cards nice and neatly.

98
00:06:57,660 --> 00:07:00,300
So next, what we want is more visuals.

99
00:07:00,300 --> 00:07:05,610
We want to be able to see the cards that are dealt out and the card that's on top so that we can play

100
00:07:05,610 --> 00:07:08,290
through the rounds and then also determine who's going to win.

101
00:07:08,670 --> 00:07:11,580
So that's going to come up and we're going to set that up.

102
00:07:11,580 --> 00:07:18,240
Now that we've got the play started, the next one is going to be attaching an event listener to the

103
00:07:18,240 --> 00:07:19,080
attack button.

104
00:07:19,320 --> 00:07:22,650
And the tag button is the one that we're going to deal the next round to.

105
00:07:22,890 --> 00:07:28,170
And this is going to specify how many rounds of play we're going to have and how many interactions we're

106
00:07:28,170 --> 00:07:28,670
going to have.

107
00:07:28,950 --> 00:07:35,750
So this input is going to change from being how many players to how many rounds we're using to attack.

108
00:07:36,090 --> 00:07:37,170
So that's all still to come.

109
00:07:37,740 --> 00:07:42,270
So go ahead and set the ability to deal the cards up in your project.
