Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we started talking about how we're going to begin adding different methods to
our deck and card classes will first begin with this first task up here.
So we want to have the ability to create a new deck and make sure that there are 50 to playing cards
inside of it.
Remember, a standard deck of cards has 52 cards for suits and 13 ranks, or however many 13 ranks.
Now, one thing I want to make really clear here is that even though I'm kind of indicating right here
that these are a bunch of methods that are going to exist on the deck, this make a deck function right
here?
Well, it's a little bit different than the other functions you see listed on here.
Let me tell you why.
I want you to imagine that at some point in the future, after we finish up this deck class and the
card class, we end up writing out our main function.
And then maybe inside this main function, you and I write some code to create a new instance of the
deck class.
So maybe we would write something like var deck is new deck.
Now, I don't know about you, but I would really expect that the instant I called New Deck right here,
I would just poof, magically get fifty two cards added for me to this card's property or this cards
field.
I would not want to have to run some additional method or additional function like, say, deck at all
cards or something like deck build my cards or something like that to generate those fifty two cards
and add them to this list.
In other words, I want to make sure that the instant I create a new deck, I automatically get 52 cards
added to this cards property.
So what I'm kind of driving out here.
Long story short, I think that we need to add a constructor function to the deck class.
So the instant we create a new instance of deck, we automatically get the opportunity to do some initialization
of our deck class and add those 52 cards in without having to require an extra function call like that
or any additional kind of hubbub to get this class initialized.
So I'm going to clean up this main function right here and then inside the declasse, I'm going to add
on my constructor function.
We just spoke about constructor functions a moment ago.
Remember to define one inside of a class.
We write out the exact name of the class as a function inside the class body.
So because my class name is Deck with a capital D. I'll add on a new function called Deck Place my parentheses
and then my curly braces like so.
So now this function right here is going to be called automatically every time we create a new instance
of a deck, which makes it a perfect location to create our big list of cards and add it to this cards
property right here.
OK, so let's take a quick pause right now.
We'll come back in the next video and start implementing the logic to add all of our cards to that cards
list.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.