langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,109 @@
CLS
Function isNumeric ($x)
{
$x2 = 0
$isNum = [System.Int32]::TryParse($x,[ref]$x2)
Return $isNum
}
$NumberOne = Random -Maximum 10 -Minimum 1
$NumberTwo = Random -Maximum 10 -Minimum 1
$NumberThree = Random -Maximum 10 -Minimum 1
$NumberFour = Random -Maximum 10 -Minimum 1
$NumberArray = @()
$NumberArray += $NumberOne
$NumberArray += $NumberTwo
$NumberArray += $NumberThree
$NumberArray += $NumberFour
Write-Host "Welcome to the 24 game!`n`nHere are your numbers: $NumberOne,$NumberTwo,$NumberThree and $NumberFour.`nUse division, multiplication, subtraction and addition to get 24 as a result with these 4 numbers.`n"
Do
{
$Wrong = 0
$EndResult = $null
$TempChar = $null
$TempChar2 = $null
$Count = $null
$Result = Read-Host
Foreach($Char in $Result.ToCharArray())
{
Switch($Char)
{
$NumberOne
{
}
$NumberTwo
{
}
$NumberThree
{
}
$NumberFour
{
}
"+"
{
}
"-"
{
}
"*"
{
}
"/"
{
}
"("
{
}
")"
{
}
" "
{
}
Default
{
$Wrong = 1
}
}
}
If($Wrong -eq 1)
{
Write-Warning "Wrong input! Please use only the given numbers."
}
Foreach($Char in $Result.ToCharArray())
{
If((IsNumeric $TempChar) -AND (IsNumeric $Char))
{
Write-Warning "Wrong input! Combining two or more numbers together is not allowed!"
}
$TempChar = $Char
}
Foreach($Char in $Result.ToCharArray())
{
If(IsNumeric $Char)
{
$Count++
}
}
If($Count -eq 4)
{
$EndResult = Invoke-Expression $Result
If($EndResult -eq 24)
{
Write-Host "`nYou've won the game!"
}
Else
{
Write-Host "`n$EndResult is not 24! Too bad."
}
}
Else
{
Write-Warning "Wrong input! You did not supply four numbers."
}
}
While($EndResult -ne 24)