1
00:00:00,830 --> 00:00:05,750
The way that I usually make games is I try to anticipate what the next step is.

2
00:00:05,780 --> 00:00:11,840
So we've got our starting point and we're starting and now we're presenting the player with a question

3
00:00:11,840 --> 00:00:13,190
of whether it's higher or lower.

4
00:00:13,220 --> 00:00:19,150
And we also need to build out the deck of cards and we also need to display the card for the player.

5
00:00:19,760 --> 00:00:25,970
I also, before we begin this lesson, I want to go into style and update one of the styling values

6
00:00:25,970 --> 00:00:32,120
of score, because right now the style is not in line, it's not in line block.

7
00:00:32,120 --> 00:00:35,840
So I want to set that up, taking the class score.

8
00:00:37,200 --> 00:00:38,970
Using the display property.

9
00:00:40,130 --> 00:00:44,850
And display in line block, so that no longer goes onto a second row.

10
00:00:45,020 --> 00:00:51,770
So it's nice and neat and compact in there, going back to index and for the drawing of the card, we

11
00:00:51,770 --> 00:00:55,820
need to do a quick check to make sure that we have an existing deck.

12
00:00:56,030 --> 00:00:59,460
So deck is a global variable that we set up in the earlier lesson.

13
00:00:59,630 --> 00:01:06,670
It's an array and checking to see if this array has a length of greater than zero.

14
00:01:07,010 --> 00:01:09,710
And if it does, then we run this block of code.

15
00:01:10,010 --> 00:01:12,830
And if it doesn't, then we know we need to build a deck.

16
00:01:12,830 --> 00:01:18,970
And that's where we can run a function that can say, make deck, return back, draw a card.

17
00:01:19,250 --> 00:01:24,350
So after we make the deck, we're going to run, draw a card, and then this time the deck will have

18
00:01:24,350 --> 00:01:29,670
a length and we can output that value of the card and return that one back to the player.

19
00:01:30,170 --> 00:01:33,160
So for now, we'll just do our return card.

20
00:01:33,170 --> 00:01:34,850
I'll set a default value for card.

21
00:01:35,120 --> 00:01:40,790
So the way that this function is going to work, once we get to this value where it says my card invoking

22
00:01:40,790 --> 00:01:47,000
the function called draw card going over to this function, we're going to look to see what the length

23
00:01:47,000 --> 00:01:47,690
of decks.

24
00:01:48,170 --> 00:01:53,210
And currently when we first start out the length of deck is nothing because we don't have anything in

25
00:01:53,210 --> 00:01:54,070
that array yet.

26
00:01:54,590 --> 00:01:56,360
So it's going to move on to the else.

27
00:01:56,870 --> 00:02:03,020
It's going to go into the make deck function, invoke this function here or not make card.

28
00:02:03,020 --> 00:02:07,370
So we need to have another one here for make deck.

29
00:02:07,850 --> 00:02:10,670
And this is where we're going to build out our deck of cards.

30
00:02:11,270 --> 00:02:17,210
Once it completes that, it's going to return draw a card, which is going to loop it back into this

31
00:02:17,210 --> 00:02:17,780
function.

32
00:02:19,450 --> 00:02:24,730
And then go through these conditions again, and the next time it goes through, once we have a deck,

33
00:02:24,730 --> 00:02:26,940
we'll have a length for that deck.

34
00:02:27,940 --> 00:02:29,860
So it's going to make deck.

35
00:02:30,820 --> 00:02:35,830
And first of that, we want to do here is zero any content that might currently be in the deck.

36
00:02:35,830 --> 00:02:37,780
And we don't have anything in there right now.

37
00:02:38,140 --> 00:02:40,320
And this is going to be a series of loops.

38
00:02:40,600 --> 00:02:48,910
So setting up our first loop, setting eye to zero, we're going to loop through while the value of

39
00:02:48,910 --> 00:02:49,510
suits.

40
00:02:50,140 --> 00:02:57,310
So suits is that array where we've got all of the suits is less than the value of suits length.

41
00:02:58,000 --> 00:03:02,530
We're going to increment I by one as we loop through these values.

42
00:03:02,830 --> 00:03:10,810
We need a loop inside of a loop so this loop we can set let G equals zero and we're going to loop through

43
00:03:10,810 --> 00:03:14,680
G while G is less than ranks.

44
00:03:15,660 --> 00:03:18,810
Length and then increment by one.

45
00:03:19,290 --> 00:03:20,490
So what's happening here?

46
00:03:20,610 --> 00:03:21,940
And actually, it doesn't matter.

47
00:03:21,960 --> 00:03:25,170
You could do ranks on the outside, in suits on the inside.

48
00:03:25,320 --> 00:03:28,080
It's going to still build out everything the same way.

49
00:03:28,290 --> 00:03:30,350
So there's no difference between the order.

50
00:03:30,570 --> 00:03:33,390
We're just looping through all of these values.

51
00:03:33,390 --> 00:03:38,580
And we know that four in a deck of cards Hearts has all of the rank values.

52
00:03:38,580 --> 00:03:43,520
Diamonds has all of the rank values, clubs and spades have all of the rank values.

53
00:03:43,530 --> 00:03:45,210
And that makes up our deck of cards.

54
00:03:45,400 --> 00:03:49,200
So that's why we need to do the two loops to loop through both of those arrays.

55
00:03:49,230 --> 00:03:52,860
So each one of the suits gets assigned a rank value.

56
00:03:52,980 --> 00:03:56,550
And as we're looping through, we're going to build out a card.

57
00:03:56,790 --> 00:03:58,620
So the card is going to be an object.

58
00:03:58,620 --> 00:04:05,700
And that as we loop through, we need to assign that object a suit value and we can get that from that

59
00:04:05,700 --> 00:04:07,880
array that we're building out next.

60
00:04:07,890 --> 00:04:15,190
We've got our rank and selecting our ranks value that's going to correspond with G.

61
00:04:16,360 --> 00:04:24,280
And then we've got our card value and this can correspond with the value of G plus once we get a numeric

62
00:04:24,280 --> 00:04:25,480
value for each card.

63
00:04:26,360 --> 00:04:29,690
And you can assign also some additional values here.

64
00:04:30,290 --> 00:04:36,710
And then lastly, what we're doing is we're taking that deck so that empty Decorah that we have globally

65
00:04:37,010 --> 00:04:39,620
and we're pushing card into that deck.

66
00:04:40,130 --> 00:04:44,930
And as we loop through, you're going to see that we're going to build out our deck of cards.

67
00:04:45,480 --> 00:04:51,290
And then after we finish all of these loops, we're going to see that deck that built that the deck

68
00:04:51,290 --> 00:04:53,070
that we built sitting in the console.

69
00:04:53,090 --> 00:04:54,020
So let's try that it.

70
00:04:55,310 --> 00:05:02,630
I'll make this bigger, we hit start and there's our deck of cards, so the first card here is the two

71
00:05:02,630 --> 00:05:03,260
of hearts.

72
00:05:03,490 --> 00:05:04,850
It's got a value of one.

73
00:05:05,960 --> 00:05:08,940
Three of hearts, a value of two all the way down.

74
00:05:09,080 --> 00:05:15,110
We've got our Jack has value of ten and Ace, which is our highest card, has a value of thirteen.

75
00:05:15,320 --> 00:05:18,170
And that's how we're going to rank all of the cards higher, lower.

76
00:05:18,290 --> 00:05:19,850
So aces are the highest card.

77
00:05:20,000 --> 00:05:23,570
You could also do them, sort them that aces are the lowest card.

78
00:05:23,700 --> 00:05:28,970
And that would just be a matter of sorting them and positioning them differently within the deck where

79
00:05:28,970 --> 00:05:35,080
you could place the ace in the beginning if you wanted the ace to be worth one and so on.

80
00:05:35,300 --> 00:05:41,630
So it does matter of how you want to stock your deck, the value of your deck, some games that aces

81
00:05:41,630 --> 00:05:43,990
are the top, some games the aces are the bottom.

82
00:05:44,120 --> 00:05:46,040
It's up to you how you want to set that up.

83
00:05:46,220 --> 00:05:48,620
And that's basically how you build that deck of cards.

84
00:05:48,830 --> 00:05:50,620
So go ahead and try it out for yourself.

85
00:05:50,990 --> 00:05:57,050
You can try out with the making deck function first if you want, and see how the deck looks like.

86
00:05:57,050 --> 00:06:02,600
Just invoked that function anywhere within your code or outside within your console and try it out and

87
00:06:02,600 --> 00:06:04,280
make sure that you can build out the deck.

88
00:06:04,520 --> 00:06:07,820
And then here you can apply that logic when we're drawing a card.

89
00:06:07,940 --> 00:06:13,070
And coming up next, I'll show you how we can return a card value now that we have a deck of cards.

90
00:06:13,250 --> 00:06:14,960
So that is all still yet to come.
