Private/Get-RPSResult.ps1
function Get-RPSResult { [CmdletBinding()] [Alias()] [OutputType([Result])] Param ( # Param1 help description [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [Choice]$Player1Choice, # Param2 help description [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=1)] [Choice]$Player2Choice ) Begin { } Process { if ($Player1Choice -eq $Player2Choice) { # Tie. return [Result]::Tie; break; } if ( ($Player1Choice -eq 'Rock' -and $Player2Choice -eq 'Paper') -or ($Player1Choice -eq 'Paper' -and $Player2Choice -eq 'Scissors') -or ($Player1Choice -eq 'Scissors' -and $Player2Choice -eq 'Rock') ) { # Loss. return [Result]::Loss; break; } if ( ($Player1Choice -eq 'Rock' -and $Player2Choice -eq 'Scissors') -or ($Player1Choice -eq 'Paper' -and $Player2Choice -eq 'Rock') -or ($Player1Choice -eq 'Scissors' -and $Player2Choice -eq 'Paper') ) { # Win. return [Result]::Win; break; } } End { } } enum Choice { Rock = 0 Paper = 1 Scissors = 2 } enum Result { Loss = -1 Win = 0 Tie = 1 } |