-
Notifications
You must be signed in to change notification settings - Fork 1
/
numberGuess.ps1
55 lines (47 loc) · 1.28 KB
/
numberGuess.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$maxValue = 10
$answer = 0
$score = 1000
function playGame {
$answer = generateNumber -maxValue $maxValue
userGuess
}
function generateNumber {
return Get-Random -Maximum $maxValue -Minimum 1
}
function userGuess {
$userInput = Read-Host "Raad het getal tussen de 1 en de $($maxValue): "
evaluateInput $userInput
}
function evaluateInput {
try {
$userInput = [int]$userInput
} catch [System.Management.Automation.RuntimeException] {
Write-Output "Voer aub. alleen een cijfer in!"
userGuess
}
if ($userInput -gt 0 -and $userInput -le $maxValue) {
if ($userInput -eq $answer) {
Write-Output "*** GEFELICITEERD, $($userInput) IS HET JUISTE ANTWOORD! ***"
Write-Output "Je hebt $($score) punten behaald!"
break
} else {
giveHint($userInput)
}
} else {
Write-Output "Alleen getallen tussen de 1 en de $($maxValue)!"
userGuess
}
}
function giveHint {
if ($userInput -lt $answer) {
Write-Output "Het getal wat je zoekt is groter!"
$score = $score - 100
userGuess
}
if ($userInput -gt $answer) {
Write-Output "Het getal wat je zoekt is kleiner!"
$score = $score - 100
userGuess
}
}
playGame