Quick Fire Character Counting Game In PowerShell

Another pointless activity in PowerShell. The premis of this game is that you have a short amount of time to look at a word, you then have to guess how many letters are in the word.

If you get the number correct, the game continues and your score increases. If you input and incorrect number, then the game ends, shows your score and exits.

As always I have added this to my “Games In PowerShell” project. Below is the code for the game:


function quickfirecounting{
$getverbs = Get-Verb | select verb
[int]$verbamount = $getverbs.count
$scoreforquickfire = 0
do{
$random = Get-Random -Minimum 0 -Maximum $verbamount
$selectedword = $getverbs[$random] -replace "@{verb=","" -replace "}",""
$selectedwordlength = $selectedword.Length

$scoreforquickfire = $scoreforquickfire + 1
Clear-Host
Write-Host "$selectedword"
Start-Sleep -Milliseconds 550
Clear-Host
$guess = Read-Host "how many letters are in the word?"
}until ($guess -ne $selectedwordlength)
Clear-Host
Write-Host "Incorrect! There were $selectedwordlength letters"
Start-Sleep -Seconds 1
Clear-Host
Write-Host "Your score was $scoreforquickfire"
Start-Sleep -Seconds 1
Clear-Host

do {$playagainselection = Read-Host "do you want to play again? (Y or N)"} while (("y","n") -notcontains $playagainselection)
if ($playagainselection -eq "y"){
####GO TO GAME FUNCTION TO PLAY AGAIN####
}elseif ($playagainselection -eq "n"){
####GO TO THE MAIN MENU####
}
}

As you can probably see, I am using the verb section of PowerShell to get the random words. This is better and easier than inputting my own words individually.

Enjoy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s