Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Playing-cards/Groovy/playing-cards-1.groovy
Normal file
37
Task/Playing-cards/Groovy/playing-cards-1.groovy
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import groovy.transform.TupleConstructor
|
||||
|
||||
enum Pip {
|
||||
ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING
|
||||
}
|
||||
enum Suit {
|
||||
DIAMONDS, SPADES, HEARTS, CLUBS
|
||||
}
|
||||
|
||||
@TupleConstructor
|
||||
class Card {
|
||||
final Pip pip
|
||||
final Suit suit
|
||||
|
||||
String toString() { "$pip of $suit" }
|
||||
}
|
||||
|
||||
class Deck {
|
||||
private LinkedList cards = []
|
||||
|
||||
Deck() { reset() }
|
||||
|
||||
void reset() {
|
||||
cards = []
|
||||
Suit.values().each { suit ->
|
||||
Pip.values().each { pip ->
|
||||
cards << new Card(pip, suit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Card deal() { cards.poll() }
|
||||
|
||||
void shuffle() { Collections.shuffle cards }
|
||||
|
||||
String toString() { cards.isEmpty() ? "Empty Deck" : "Deck $cards" }
|
||||
}
|
||||
3
Task/Playing-cards/Groovy/playing-cards-2.groovy
Normal file
3
Task/Playing-cards/Groovy/playing-cards-2.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Deck deck = new Deck()
|
||||
deck.shuffle()
|
||||
(0..<5).each { println deck.deal() }
|
||||
Loading…
Add table
Add a link
Reference in a new issue