1
00:00:01,020 --> 00:00:05,940
Welcome back in this lesson, we're going to be creating a deck of cards, so first that we need to

2
00:00:05,940 --> 00:00:10,380
do is set up a few more variables and these are some default variables that we can utilize.

3
00:00:10,800 --> 00:00:11,960
We need a deck.

4
00:00:12,000 --> 00:00:16,120
This is going to be a global variable, which will be the array that we're going to use.

5
00:00:16,440 --> 00:00:18,860
We're also going to set up a few other arrays.

6
00:00:18,870 --> 00:00:21,240
So we've got the ranks of the cards.

7
00:00:21,430 --> 00:00:24,180
And this is where you can list out all the cards that you want.

8
00:00:24,360 --> 00:00:30,030
So want all the way up to nine, 10 and then jox queens.

9
00:00:30,760 --> 00:00:36,090
And these are strings and kings and we want aces to be the largest card.

10
00:00:36,270 --> 00:00:38,130
And then there's the different suits.

11
00:00:38,640 --> 00:00:45,570
So set up another array to hold the suits and we're going to specify the suits as we've got hearts,

12
00:00:45,570 --> 00:00:48,650
diamonds, club and spades.

13
00:00:49,080 --> 00:00:55,230
So using these values, we can loop through the suits and then we can also loop through the ranks and

14
00:00:55,230 --> 00:00:56,390
build a deck of cards.

15
00:00:56,670 --> 00:00:58,820
So that's what we want to do when we start the game.

16
00:00:58,860 --> 00:01:00,510
We've got the start game function.

17
00:01:00,660 --> 00:01:05,610
We've got a global variable to handle and to take all of the deck contents.

18
00:01:05,880 --> 00:01:10,890
So next thing that we want to do when we start the game is we want to build the deck of cards.

19
00:01:11,400 --> 00:01:16,140
So build deck can be the function that will create the deck of cards.

20
00:01:16,410 --> 00:01:19,430
Let's set that function up so we start the game.

21
00:01:19,440 --> 00:01:24,000
We're building our deck and this is going to be a series of loops.

22
00:01:24,240 --> 00:01:28,740
So first that we want to do clear out the existing deck of cards as a global object.

23
00:01:28,980 --> 00:01:32,870
So so we don't have to declare it again and let's use for loops.

24
00:01:33,240 --> 00:01:41,120
So starting with AI is zero and while I is less than and looping through that suits array.

25
00:01:41,130 --> 00:01:45,150
So looping through while I is less than one, we're going to increment it by one.

26
00:01:45,270 --> 00:01:51,330
And so we need another loop inside because we've got another parameter that we're using in order to

27
00:01:51,330 --> 00:01:52,380
build the deck of cards.

28
00:01:52,560 --> 00:02:00,930
So set this one as G and looping through while G is less than ranks length as we've got both of those

29
00:02:00,930 --> 00:02:04,920
arrays that we've got to iterate through in order to build a full deck of cards.

30
00:02:05,230 --> 00:02:09,780
So once we're looping through there, let's create a blank card object.

31
00:02:09,790 --> 00:02:15,090
So this is going to be an object and this can hold all of the information that we need for our card.

32
00:02:15,330 --> 00:02:18,180
So let's set up some values for that object.

33
00:02:18,420 --> 00:02:20,060
So taking in the suit.

34
00:02:20,520 --> 00:02:28,290
So this is going to be coming in as suits and suits is controlled within eye card and we want to get

35
00:02:28,290 --> 00:02:29,770
the rank of the card as well.

36
00:02:30,180 --> 00:02:33,150
So this is held within the ranks array.

37
00:02:33,600 --> 00:02:38,500
So as we iterate through there, when we get to G, we'll output that value.

38
00:02:38,730 --> 00:02:43,740
We've also got a card value, so that can be G plus one.

39
00:02:43,830 --> 00:02:47,220
So setting this up to be whatever the value of J is.

40
00:02:47,370 --> 00:02:51,420
So as we increase in ranks, we can increase the value of the card.

41
00:02:51,810 --> 00:02:56,220
And then lastly, let's take that card and we'll push it into the deck.

42
00:02:56,280 --> 00:03:02,280
So as we loop through both of these loops, by the time we're completed, we're going to have a finished

43
00:03:02,280 --> 00:03:08,850
deck of cards and we can see that when we cancel out whatever the value of deck is.

44
00:03:09,090 --> 00:03:11,130
So let's see what that looks like and refresh.

45
00:03:11,130 --> 00:03:15,270
We hit the start of the game and that builds up our 52 card deck.

46
00:03:15,400 --> 00:03:18,910
And as you can see, we start out with all of the hearts.

47
00:03:18,930 --> 00:03:22,320
So we've got a rank of two and a value of one.

48
00:03:22,320 --> 00:03:25,280
So going up and aces are the largest values.

49
00:03:25,320 --> 00:03:26,270
They have 13.

50
00:03:26,430 --> 00:03:27,960
So they're going to be the highest card.

51
00:03:28,140 --> 00:03:30,780
You might also want to have an ace as a one.

52
00:03:30,900 --> 00:03:34,190
So it all depends on how you want to set up your deck for this case.

53
00:03:34,230 --> 00:03:38,880
What I'm doing is I'm having the ace set up as the highest card, so it's going to be three.

54
00:03:38,880 --> 00:03:45,180
So we get all of the values, all the ranks for the hearts, all the ranks for the values, diamonds,

55
00:03:45,300 --> 00:03:47,010
clubs and spades.

56
00:03:47,140 --> 00:03:52,510
And then we've got all the cards have a value in the order that they appear in the array.

57
00:03:52,740 --> 00:03:55,620
So if you want to switch these around, you're welcome to do that.

58
00:03:55,950 --> 00:04:01,890
But best practices to keep it within that sequential order so that that way you can automatically set

59
00:04:01,890 --> 00:04:03,870
the values as you loop through them.

60
00:04:03,870 --> 00:04:07,500
And it's going to make it a lot easier to compare which card is higher.

61
00:04:07,800 --> 00:04:13,740
So now that we've built a deck, next thing that we do is we need to set up the players and then deal

62
00:04:13,740 --> 00:04:14,280
the cards.

63
00:04:14,550 --> 00:04:17,310
So that's still all to come in the upcoming lessons.

64
00:04:17,340 --> 00:04:19,790
So go ahead and build a deck of cards.

65
00:04:19,800 --> 00:04:24,270
And this is another thing that we're going to do is going to shuffle this deck of cards before we deal

66
00:04:24,270 --> 00:04:25,040
it out as well.
