Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function GetNumber([int]$min, [int]$max) {
- Return Get-Random -minimum $min -maximum ($max + 1)
- }
- Function PlayGame() {
- Write-Host "This is a guess-the-number game.`r`nYou have 6 guesses to guess a number between 1 and 100."
- $secretNum = GetNumber 1 100
- [int]1..6 | ForEach {
- $guess = Read-Host
- If ($guess -eq $secretNum) {
- Write-Host "Correct!"
- Return
- }
- ElseIf ($guess -gt $secretNum) {
- Write-Host "Too high!"
- }
- Else {
- Write-Host "Too low!"
- }
- $remainingGuesses = 6 - $_
- Write-Host "You have $remainingGuesses guesses left"
- }
- Write-Host "The number was $secretNum"
- }
- PlayGame
- # Borrowed from https://technet.microsoft.com/en-us/library/ff730938.aspx
- Write-Host "Press any key to continue ..."
- $host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement