Anonymous user
Playing cards: Difference between revisions
→{{header|D}}
(Go solution) |
|||
Line 478:
}
}</lang>
From the Python version:
<lang d>import std.random, std.conv, std.stdio;
class Card {
enum suits = ["Clubs", "Hearts", "Spades", "Diamonds"];
enum pips = ["2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King", "Ace"];
string pip, suit;
this(string pip, string suit) {
this.pip = pip;
this.suit = suit;
}
override string toString() {
return this.pip ~ " of " ~ this.suit;
}
}
class Deck {
Card[] deck;
this() {
foreach (suit; Card.suits)
foreach (pip; Card.pips)
this.deck ~= new Card(pip, suit);
}
override string toString() {
return text(this.deck);
}
void shuffle() {
randomShuffle(this.deck);
}
Card deal() {
this.shuffle();
Card c = this.deck[$-1];
this.deck.length -= 1;
return c;
}
}
void main() {}</lang>
=={{header|E}}==
|