Skip to content

Instantly share code, notes, and snippets.

@rubenberna
Created December 26, 2022 17:17
Show Gist options
  • Save rubenberna/4ab21fe82410fdbcaab4ac6ce5d66ffc to your computer and use it in GitHub Desktop.
Save rubenberna/4ab21fe82410fdbcaab4ac6ce5d66ffc to your computer and use it in GitHub Desktop.
windy-lotus-1410
void main() {
var deck = Deck();
// print(deck);
// print(deck.deal(5));
print(deck.removeCard('Hearts', 'Four'));
print(deck);
}
class Deck {
List<Card> cards = [];
Deck() {
var ranks = ['Ace', 'Two', 'Three', 'Four', 'Five'];
var suits = ['Diamonds', 'Hearts', 'Clubs', 'Spades'];
for (var suit in suits) {
for (var rank in ranks) {
var card = Card(rank: rank, suit: suit);
cards.add(card);
}
}
}
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 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