Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,030 --> 00:00:05,350
In the last section, we put together our deck constructor function, which is going to be a perfect
2
00:00:05,350 --> 00:00:11,530
location to create our list of 52 cards and add them all to this cards list right here before we start
3
00:00:11,530 --> 00:00:13,540
just writing out some code to make that happen.
4
00:00:13,570 --> 00:00:17,440
Let's take a quick look at a diagram that's going to lay out the strategy that we're going to use to
5
00:00:17,440 --> 00:00:20,950
create all 52 cards in one fell swoop.
6
00:00:22,060 --> 00:00:28,360
All right, so here's the idea, we're going to begin by creating two separate lists, each list is
7
00:00:28,360 --> 00:00:30,140
going to contain a bunch of strings.
8
00:00:30,700 --> 00:00:36,280
Now, we haven't dealt too much with lists just yet, but lists are essentially identical to arrays
9
00:00:36,280 --> 00:00:38,140
in just about every other language.
10
00:00:38,920 --> 00:00:44,440
So we define a list by placing some square brackets like so, and then we separate all the elements
11
00:00:44,440 --> 00:00:45,770
inside of it with commas.
12
00:00:46,690 --> 00:00:51,190
We're going to have one list of all the different ranks, like ACE two, three, four, five, six,
13
00:00:51,190 --> 00:00:52,450
seven, all the way up to King.
14
00:00:53,110 --> 00:00:57,070
And then our list of suits of hearts, diamonds, spades and clubs.
15
00:00:58,170 --> 00:01:04,110
We're then going to write out a nested for loop, so we're going to save for every suit inside of this
16
00:01:04,110 --> 00:01:10,740
list of suits and for every rank in this list of ranks, we're going to create a brand new card and
17
00:01:10,740 --> 00:01:12,480
add it to our cards list.
18
00:01:12,870 --> 00:01:17,400
And remember, the cards list is a field on the deck class right here.
19
00:01:18,550 --> 00:01:21,040
OK, so let's find our constructor function.
20
00:01:21,070 --> 00:01:25,450
Here it is right here, and we're going to start implementing this logic will first begin by creating
21
00:01:25,450 --> 00:01:29,950
the ranks list and then these suits list and we'll put together these four loops.
22
00:01:30,130 --> 00:01:31,180
So let's get to it.
23
00:01:32,280 --> 00:01:38,190
All right, so I'm going to write out first my list of how let's do ranks, so let's save our ranks.
24
00:01:39,200 --> 00:01:43,130
I'll place my square brackets and then I'll do ASW to.
25
00:01:44,120 --> 00:01:45,890
Three, four.
26
00:01:47,850 --> 00:01:51,690
Five, and I think that's probably enough, we could definitely go all the way up to King if we wanted
27
00:01:51,690 --> 00:01:56,340
to, but I think five is enough and I'll do the same thing for my list of suits.
28
00:01:57,000 --> 00:01:59,340
So I'll do what is it, diamonds?
29
00:01:59,730 --> 00:02:00,360
Hearts.
30
00:02:02,440 --> 00:02:04,510
Clubs, spades.
31
00:02:06,090 --> 00:02:12,060
So then we're going to put together a double nested for loop for loops inside of Dart, again, very
32
00:02:12,060 --> 00:02:14,250
similar to just about every other language out there.
33
00:02:14,820 --> 00:02:18,750
So we write our four keyword and then we can vary it very easily.
34
00:02:18,750 --> 00:02:21,810
Iterate over all the elements inside of one of these lists.
35
00:02:21,810 --> 00:02:28,660
By placing a set of parentheses, we'll write out a variable to capture each individual element.
36
00:02:28,710 --> 00:02:33,120
So I'll say for var suits in suits.
37
00:02:34,630 --> 00:02:40,390
So this for Loop right here is going to iterate over every suit within our list of suits and then it
38
00:02:40,390 --> 00:02:42,940
will execute the body of the for loop right here.
39
00:02:43,880 --> 00:02:47,900
So then inside this for Loop, we're going to set up another one, we'll say, for every.
40
00:02:48,890 --> 00:02:55,040
Rank in our list of ranks, and then right here is where we can add some code to actually go ahead and
41
00:02:55,040 --> 00:02:57,950
create our new card and add it to our list of cards.
42
00:02:58,670 --> 00:03:00,110
So let's take a quick pause right here.
43
00:03:00,110 --> 00:03:04,700
When we come back in the next video, we're going to start adding the logic to create each individual
44
00:03:04,700 --> 00:03:05,120
card.
45
00:03:05,480 --> 00:03:07,660
So quick break and I'll see you in just a minute.
4445
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.