Skip to content

Instantly share code, notes, and snippets.

@AspenForester
Last active November 15, 2016 21:42
Show Gist options
  • Save AspenForester/082601c7dacb1ccafadb3c9e75c43d82 to your computer and use it in GitHub Desktop.
Save AspenForester/082601c7dacb1ccafadb3c9e75c43d82 to your computer and use it in GitHub Desktop.
Class PlayingCard {
[String] $Suit
[String] $FaceValue
hidden [int] $Value
PlayingCard (){}
PlayingCard ([String] $Suit, [String] $FaceValue){
$this.Suit = $Suit
$this.FaceValue = $FaceValue
$this.Value = ("Joker","Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King").IndexOf($FaceValue)
}
}
Class DeckofCards {
[PlayingCard[]]$Cards
[int]$CardsInDeck
# I would like a 'default' constructor that just calls the constructor below with the parameter
# equal to $false
DeckofCards ([Bool]$WithJokers) {
$Faces = ('Ace','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Jack','Queen','King')
$This.Cards = foreach ($Suit in ("Clubs","Diamonds","Spades","Hearts"))
{
Foreach ($Face in $Faces)
{
[playingCard]::new($Suit,$Face)
}
}
if ($WithJokers)
{
(0..1) | Foreach { $this.Cards += [PlayingCard]::new('','Joker')}
}
$this.CardsInDeck = $this.Cards.Count
}
[void]Shuffle () {
$this.Cards = Get-Random -InputObject $this.Cards -Count $this.CardsInDeck
}
}
@AspenForester
Copy link
Author

Pardon the slightly inconsistent indention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment