Last active
November 15, 2016 21:42
-
-
Save AspenForester/082601c7dacb1ccafadb3c9e75c43d82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pardon the slightly inconsistent indention