daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Dec 12th, 2018 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void main() {
  2.   var deck = new Deck();
  3.   print(deck);
  4.     deck.removeCard('Diamonds', 'Ace');
  5.   print(deck);
  6. }
  7. class Card {
  8.   String rank;
  9.   String suit;
  10.  
  11.   Card({this.suit, this.rank});
  12.  
  13.   toString() {
  14.     return '$rank of $suit';
  15.   }
  16. }
  17.  
  18. class Deck {
  19.   List<Card> cards = [];
  20.  
  21.   Deck() {
  22.     var ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8','9', 'J', 'Q', 'K'];
  23.     var suits = ['Diamonds', 'Heards', 'Clubs', 'Spades'];
  24.    
  25.     for (var suit in suits){
  26.       for (var rank in ranks){
  27.         var card = new Card(
  28.           suit: suit,
  29.           rank: rank
  30.         );
  31.         cards.add(card);
  32.       }
  33.     }
  34.   }
  35.  
  36.   toString() {
  37.     return cards.toString();
  38.   }
  39.  
  40.   shuffle() {
  41.     cards.shuffle();
  42.   }
  43.  
  44.   cardsWithSuit(String suit) {
  45.     return cards.where((card) => card.suit == suit);
  46.   }
  47.  
  48.   deal(int handSize) {
  49.     var hand = cards.sublist(0, handSize);
  50.     cards = cards.sublist(handSize);
  51.    
  52.     return hand;
  53.   }
  54.  
  55.   removeCard(String suit, String rank) {
  56.     cards.removeWhere((card) => (card.suit == suit && card.rank == rank));
  57.   }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top