Created
August 30, 2018 16:00
-
-
Save aelshamy/c36bc2138ccf0e33364b8826ef3e02ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var deck = new Deck(); | |
deck.shuffle(); | |
deck.deal(5); | |
print(deck.deal(5)); | |
} | |
class Deck { | |
List<Card> cards = []; | |
final ranks = [ | |
'Ace', | |
'Two', | |
'Three', | |
'Four', | |
'Five', | |
'Six', | |
'Seven', | |
'Eight', | |
'Nine', | |
'Ten', | |
'Jack', | |
'Queen', | |
'King' | |
]; | |
final suits = ['Diamonds', 'Hearts', 'Clubs', 'Spades']; | |
Deck() { | |
for (var suit in suits) { | |
for (var rank in ranks) { | |
var card = new Card(rank: rank, suit: suit); | |
cards.add(card); | |
} | |
} | |
} | |
shuffle() { | |
cards.shuffle(); | |
} | |
Iterable<Card> cardWithSuit(String suit) { | |
return cards.where((card) => card.suit == suit); | |
} | |
List<Card> deal(int handSize) { | |
var hand = cards.sublist(0, handSize); | |
cards = cards.sublist(handSize); | |
return hand; | |
} | |
toString() { | |
return cards.toString(); | |
} | |
} | |
class Card { | |
String rank; | |
String suit; | |
Card({this.rank, this.suit}); | |
toString() { | |
return '$rank of $suit'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment