Last active
October 30, 2018 23:15
-
-
Save condef5/b9cc3ce2a84ffec0b4757a70bc98e5de to your computer and use it in GitHub Desktop.
Dart and Flutter basics.
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.removeCard('Diamons', 'Ace'); | |
print(deck); | |
} | |
class Deck { | |
List<Card> cards = []; | |
Deck() { | |
var ranks = ['Ace', 'Two', 'Three', 'Four', 'Five']; | |
var suits = ['Diamons', 'Hearts', 'Club', 'Spades']; | |
for (var mySuit in suits) { | |
for (var rank in ranks) { | |
cards.add(new Card( | |
suit: mySuit, | |
rank: rank | |
)); | |
} | |
} | |
} | |
toString() { | |
return cards.toString(); | |
} | |
shuffle() { | |
cards.shuffle(); | |
} | |
cardsWithSuit(String suit) { | |
return cards.where((card) => card.suit == suit); | |
} | |
deal(int handSize) { | |
var hand = cards.sublist(0, handSize); | |
cards = cards.sublist(handSize); | |
return hand; | |
} | |
removeCard(String suit, String rank) { | |
cards.removeWhere((card) => (card.suit == suit) && (card.rank == rank)); | |
} | |
} | |
class Card { | |
String suit; | |
String rank; | |
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