$Running = $true $GameOver = $false $Wallet = 0 $Cards = 0,0,0 function AskQuestion($prompt) { while($true) { $ans = Read-Host $prompt "?" if($ans) { return $ans.ToUpper() } else { Write-Host "PLEASE ANSWER THE QUESTION." } } } function IsAnInt($value) { return $value -match "^[-*\d]+$" } function GetIntInput($prompt) { while($true) { $ans = Read-Host $prompt " " if(IsAnInt($ans)) { return [int]$ans } else { Write-Host "YOU DID NOT ENTER AN INTEGER." } } } function AskForBet() { while($true) { $bet = GetIntInput("WHAT IS YOUR BET?") if($bet -lt 0) { Write-Host "PLEASE BET A NON-NEGATIVE AMOUNT." } elseif($bet -gt $Wallet) { Write-Host "SORRY MY FRIEND, BUT YOU BET TOO MUCH." Write-Host "YOU HAVE ONLY" $Wallet "DOLLARS TO BET." } else { return $bet } } } function AskToPlayAgain() { while($true) { $ans = AskQuestion("DO YOU WANT TO PLAY AGAIN") if(($ans -eq "YES") -or ($ans -eq "Y")) { return $true } if(($ans -eq "NO") -or ($ans -eq "N")) { return $false } else { Write-Host "PLEASE ANSWER ""YES"" OR ""NO""" } } } function AskToSeeTheRules() { while($true) { $ans = AskQuestion("DO YOU WANT TO SEE THE RULES") if(($ans -eq "YES") -or ($ans -eq "Y")) { return $true } if(($ans -eq "NO") -or ($ans -eq "N")) { return $false } else { Write-Host "PLEASE ANSWER ""YES"" OR ""NO""" } } } function DisplayCard($card) { if($card -eq 11) { Write-Host "JACK" } elseif($card -eq 12) { Write-Host "QUEEN" } elseif($card -eq 13) { Write-Host "KING" } elseif($card -eq 14) { Write-Host "ACE" } else { Write-Host $card } } function DisplayRules() { Write-Host "ACEY DUCEY IS PLAYED IN THE FOLLOWING MANNER:" Write-Host "THE DEALER (COMPUTER) DEALS TWO CARDS FACE UP" Write-Host "YOU HAVE THE OPTION TO BET OR NOT BET DEPENDING" Write-Host "ON WHETHER OR NOT YOU FEEL THE NEXT CARD WILL" Write-Host "HAVE A VALUE BETWEEN THE FIRST TWO." Write-Host "" Write-Host "IF YOU DO NOT WANT TO BET, INPUT A 0 (ZERO)." } function GenerateRandomNumber { param ( [int]$minimum, [int]$maximum, $show ) $value = Get-Random -Minimum $minimum -Maximum $maximum if($show -eq $true) { Write-Host $value } return $value } function SelectCard() { while($true) { [int]$card = GenerateRandomNumber -minimum 2 -maximum 15 -show $false if(($card -ne $Cards[0]) -and ($card -ne $Cards[1]) -and ($card -ne $Cards[2])) { DisplayCard($card) return $card } } } Write-Host "*** ACEY DUCEY : POWERSHELL ***" $Running = $true if(AskToSeeTheRules -eq $true) { DisplayRules } while($Running -eq $true) { $Wallet = 100 $GameOver = $false while($GameOver -eq $false) { Write-Host "YOU NOW HAVE" $Wallet "DOLLARS." $Cards[0] = SelectCard $Cards[1] = SelectCard $bet = AskForBet if($bet -gt 0) { $Cards[2] = SelectCard if( (($Cards[2] -gt $Cards[0]) -and ($Cards[2] -lt $Cards[1])) -or (($Cards[2] -gt $Cards[1]) -and ($Cards[2] -lt $Cards[0]))) { Write-Host "YOU WIN!!!" $Wallet = $Wallet + $bet } else { Write-Host "SORRY, YOU LOSE." $Wallet = $Wallet - $bet } if($Wallet -lt 1) { Write-Host "SORRY FRIEND, YOU ARE BROKE." $GameOver = $true } } else { $GameOver = $true } } Write-Host "*** GAME OVER ***" $Running = AskToPlayAgain } Write-Host "OK, HOPE YOU HAD FUN." Write-Host "THANKS FOR PLAYING!"