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 two sections, we customize the way in which the print function represented our deck of
cards and individual card as well.
So that kind of takes care of this print cards functionality right here.
We're now going to move on to this shuffle function.
You'll notice that any time we print out our list of cards right here, they all appear to be in order.
So ACE two, three, four, five, and then starting over a two, three, four, five.
So when we first create our deck of cards, they're all created in order.
Well, definitely a lot of card games out there are all based on chance.
And so we definitely need to have the ability to shuffle the cards in the deck or to randomize their
order.
Now, we certainly could write a little bit of logic by hand to customize the shuffling, but instead
we're going to rely upon a standard library function to automatically shuffle the list of cards for
us.
So in this section, we're going to be focused not so much on how we shuffle cards, per say, but instead
we're going to focus on looking up some of the standard documentation in the Dart API and get a better
idea of how to read the documentation and use a lot of built-In functionality that is included with
the dart language to get started.
We're going to pull up the official dart API documentation.
So inside of a new tab in my browser, I'm going to navigate to API darling Doug.
Now, at the time of this video, Darte is still rolling out version two and version two is what we're
using throughout this course of darte.
When we go to API darte langue.
At present, I see a page that looks like this right here.
And this is the documentation for version one, two, four.
Like I said, we are using DART to throughout this course.
So if you see this page, you'll want to find this link right here and go to the version to documentation.
So if you see a page that looks like this when you go to API darte langue, that's good.
This is the version to documentation.
So once we're here, you'll see on the left hand side a couple of different sections, these are all
portions or modules in the dirt standard library.
If you've ever worked with JavaScript before, JavaScript is known as a language that has a rather weak
standard library.
In other words, there's not a lot of built-In functionality in a lot of the different objects that
you work with.
And a lot of the time we end up having to write a lot of code from scratch to implement some very basic
operations, very much unlike JavaScript, Dart has a very strong standard library.
So in part, whenever you make use of it, there's a tremendous amount of pre generated code.
I should say pre generated, but there's a lot of included code that we get for free just by using darts.
And it means that we can lean on the standard library a little bit to take care of many standard operations
that we might otherwise have to write up by hand if we were making use of something like JavaScript.
So what we're looking for in particular here is the core module, I'm going to click on core on the
left hand side.
And then you'll notice on the right hand side, we get a listing of different classes, so these are
all classes that are included in the core library of darte.
If you scroll down a little bit on the right hand side, you'll find a class called List.
So when you and I make our list of cards right now, we are creating an instance of a list.
So if we look at the documentation for list.
We can find a whole bunch of documentation about all the built in functionality that comes whenever
we create a list.
So in particular, we can scroll down a little bit.
You'll find a list of all the different ways to create a list.
You'll find a list of all the different properties that belong to the list, and then you'll see all
the different methods that we get for free as well.
We're going to come back to this documentation quite a bit.
But in this case, we're going to scroll down right now just a little bit and go directly to the function
we're going to use.
All right, here we go.
So right here is a function or a method called shuffle.
So any time you create a list in darte, you automatically get access to this shuffle method right here.
So if we take our card list or our list of cards that exists inside of our deck, so like this thing
right here and we just call shuffle on it, it will automatically randomize the order of all the elements
within that list and essentially accomplish what you and I are trying to do.
So let's give this a shot.
I'm going to flip back over to Arpad and I'm going to define a new method on my deck class.
So underneath two string, I'm going to add a new method called Shuffle.
And then inside of here, all we're going to do is call cards, dot shuffle, so cards dot shuffle.
Cards is a reference to the list that belongs to our instance of the class.
And then on that list object, we're going to call these shovel method, which is going to automatically
randomize all the elements within that list.
OK, so let's now try this out up inside the main function.
After we create the deck, but before we print it, I'm going to call deck dot shuffle.
So this will invoke the shuffle method on our instance of the class, which in turn is going to call
the shuffle method on our cards list, we then print out the deck of cards and we should see them all
randomized in order.
So I click on Run.
And then you'll notice that I now have five of diamonds, four of diamonds, three of spades, five
of clubs, clearly the list right here has been randomized.
OK, so in this section we started looking at the list documentation.
Those include with DART.
Like I said, we're going to be coming back to this documentation many times throughout this course
and getting a better idea of how the standard library works, because they're going to be using the
standard library quite a bit in just about every application that you create, much more so than if
you're coming from a background in a language like, say, JavaScript.
OK, so let's take a quick pause right here and we'll continue in the next section.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.