Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. Function GetNumber([int]$min, [int]$max) {
  2. Return Get-Random -minimum $min -maximum ($max + 1)
  3. }
  4.  
  5. Function PlayGame() {
  6. Write-Host "This is a guess-the-number game.`r`nYou have 6 guesses to guess a number between 1 and 100."
  7.  
  8. $secretNum = GetNumber 1 100
  9.  
  10. [int]1..6 | ForEach {
  11. $guess = Read-Host
  12. If ($guess -eq $secretNum) {
  13. Write-Host "Correct!"
  14. Return
  15. }
  16. ElseIf ($guess -gt $secretNum) {
  17. Write-Host "Too high!"
  18. }
  19. Else {
  20. Write-Host "Too low!"
  21. }
  22.  
  23. $remainingGuesses = 6 - $_
  24. Write-Host "You have $remainingGuesses guesses left"
  25. }
  26.  
  27. Write-Host "The number was $secretNum"
  28. }
  29.  
  30. PlayGame
  31.  
  32. # Borrowed from https://technet.microsoft.com/en-us/library/ff730938.aspx
  33. Write-Host "Press any key to continue ..."
  34. $host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement