Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,690 --> 00:00:04,950
In the last section, we started talking about how we're going to begin adding different methods to
2
00:00:04,950 --> 00:00:09,740
our deck and card classes will first begin with this first task up here.
3
00:00:10,140 --> 00:00:15,390
So we want to have the ability to create a new deck and make sure that there are 50 to playing cards
4
00:00:15,390 --> 00:00:16,050
inside of it.
5
00:00:16,560 --> 00:00:24,990
Remember, a standard deck of cards has 52 cards for suits and 13 ranks, or however many 13 ranks.
6
00:00:26,310 --> 00:00:30,480
Now, one thing I want to make really clear here is that even though I'm kind of indicating right here
7
00:00:30,480 --> 00:00:36,060
that these are a bunch of methods that are going to exist on the deck, this make a deck function right
8
00:00:36,060 --> 00:00:36,400
here?
9
00:00:36,630 --> 00:00:40,230
Well, it's a little bit different than the other functions you see listed on here.
10
00:00:40,410 --> 00:00:41,370
Let me tell you why.
11
00:00:42,030 --> 00:00:47,010
I want you to imagine that at some point in the future, after we finish up this deck class and the
12
00:00:47,010 --> 00:00:50,340
card class, we end up writing out our main function.
13
00:00:51,000 --> 00:00:55,980
And then maybe inside this main function, you and I write some code to create a new instance of the
14
00:00:55,980 --> 00:00:56,790
deck class.
15
00:00:57,150 --> 00:01:00,450
So maybe we would write something like var deck is new deck.
16
00:01:01,340 --> 00:01:06,470
Now, I don't know about you, but I would really expect that the instant I called New Deck right here,
17
00:01:06,710 --> 00:01:13,430
I would just poof, magically get fifty two cards added for me to this card's property or this cards
18
00:01:13,460 --> 00:01:13,940
field.
19
00:01:14,540 --> 00:01:21,140
I would not want to have to run some additional method or additional function like, say, deck at all
20
00:01:21,140 --> 00:01:27,650
cards or something like deck build my cards or something like that to generate those fifty two cards
21
00:01:27,650 --> 00:01:28,900
and add them to this list.
22
00:01:29,480 --> 00:01:36,170
In other words, I want to make sure that the instant I create a new deck, I automatically get 52 cards
23
00:01:36,380 --> 00:01:37,910
added to this cards property.
24
00:01:38,870 --> 00:01:40,170
So what I'm kind of driving out here.
25
00:01:40,190 --> 00:01:45,170
Long story short, I think that we need to add a constructor function to the deck class.
26
00:01:45,500 --> 00:01:51,590
So the instant we create a new instance of deck, we automatically get the opportunity to do some initialization
27
00:01:51,590 --> 00:01:58,160
of our deck class and add those 52 cards in without having to require an extra function call like that
28
00:01:58,460 --> 00:02:02,090
or any additional kind of hubbub to get this class initialized.
29
00:02:03,210 --> 00:02:07,890
So I'm going to clean up this main function right here and then inside the declasse, I'm going to add
30
00:02:07,890 --> 00:02:09,600
on my constructor function.
31
00:02:10,259 --> 00:02:12,780
We just spoke about constructor functions a moment ago.
32
00:02:12,810 --> 00:02:15,030
Remember to define one inside of a class.
33
00:02:15,270 --> 00:02:19,970
We write out the exact name of the class as a function inside the class body.
34
00:02:20,700 --> 00:02:28,740
So because my class name is Deck with a capital D. I'll add on a new function called Deck Place my parentheses
35
00:02:28,740 --> 00:02:30,540
and then my curly braces like so.
36
00:02:31,470 --> 00:02:36,030
So now this function right here is going to be called automatically every time we create a new instance
37
00:02:36,030 --> 00:02:42,290
of a deck, which makes it a perfect location to create our big list of cards and add it to this cards
38
00:02:42,300 --> 00:02:43,170
property right here.
39
00:02:43,920 --> 00:02:45,740
OK, so let's take a quick pause right now.
40
00:02:45,750 --> 00:02:50,880
We'll come back in the next video and start implementing the logic to add all of our cards to that cards
41
00:02:50,910 --> 00:02:51,270
list.
4218
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.