# A number guessing game for KiXtart.

KiXtart is yet another scripting language I’m learning. It uses a simple, BASIC-like language to allow you to make your own scripts with ease. I’ve yet to see if it’s better than AutoIt, but so far it’s been a smooth ride. Here’s a number guessing game in which the script tells you if your guess is too high or too low.

dim \$guess
SRND (2007)
\$num = int(RND(100))

while \$num \$guess

? “Your guess? “
GETS \$guess

if int(\$guess) > \$num
? “Too high.”
else
if int(\$guess) < \$num
? “Too low.”
endif
endif

loop

? “You guessed it!”

# A number guessing game for Bonzi Buddy.

It’s surprisingly easy to make VB scripts that use Microsoft Agent characters to interact with you. This one loads the Bonzi Buddy character file and has him play a little number guessing game with you. He’ll think of a number between 1 and 100 and then ask for your guess. He will then tell you if your guess is too high or too low. Don’t worry, he won’t spy on you or do anything from his bad old days.

intHighNumber = 100
intLowNumber = 1

strAgentPath = “C:\Windows\MSAgent\chars\Bonzi.acs”
Set objAgent = CreateObject(“Agent.Control.2”)

objAgent.Connected = TRUE
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

objCharacter.Show
objCharacter.Speak “Guess the number!”

Do Until Cint(StrGuess)=IntNumber
strGuess = InputBox(“Enter your guess.”, _
“Guess the Number”)
if strGuess=”” then
objCharacter.Hide
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
objCharacter.Speak “Too high.”
elseif Cint(strGuess)
objCharacter.Speak “Too low.”
end if

Loop

objCharacter.Speak “You guessed it!”
objCharacter.Play “Pleased”
objCharacter.Hide

Do While objCharacter.Visible = TRUE
Wscript.Sleep 250
Loop

For this script to work, you’ll need to download the Bonzi.acs file from this site and put the file in your \Windows\MSAgent\chars folder. If you still don’t like that cute little purple gorilla, you can easily change the script’s third line to load a different character such as Merlin, which should already be installed.

# A number guessing game for AutoIt.

I played around with AutoIt and came up with, yes, another number guessing game. This was a great way to get a feel for what making AutoIt scripts will be like. It’s not too difficult and is quite similar to programming in BASIC. Again, this following script is for AutoIt and shouldn’t be confused with VBScript, although the two scripts do look similar.

\$IntNumber=Int(Random(1, 100, 1))
\$answer=Int(0)

while \$answer \$IntNumber

\$answer = InputBox(“Guess the Number”, “What is your guess?”)

If \$answer=”” then
Exit
ElseIf \$answer > \$IntNumber Then
MsgBox(4096,”Incorrect”, “Too high.”)
ElseIf \$answer < \$IntNumber Then MsgBox(4096,”Incorrect”, “Too low.”) EndIf wend MsgBox(4096,”W00t!”, “You guessed it!”)

# Variations of a number guessing game.

One of my favorite games is the classic “Guess the Number” in which you try guessing a number and the computer tells you whether your guess is too high or too low. Here’s a VB Script version:

intHighNumber = 100
intLowNumber = 1

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

Do Until Cint(StrGuess)=IntNumber

strGuess = InputBox(“Enter your guess.”, _
“Guess the Number”)
if strGuess=”” then
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
Wscript.Echo “Too high.”
elseif Cint(strGuess) < IntNumber then
Wscript.Echo "Too low."
end if

Loop

Wscript.Echo "You guessed it!"

I find myself playing this game whenever I’m in need of a quick break. Still, I try to see how I can vary the game and have come up with some pretty interesting variations. Here’s one that not only tells you whether your guess is too high or low, but it tells you how far off your guess is. With a little math, you can guess the correct number on the next try.

intHighNumber = 100
intLowNumber = 1

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

Do Until Cint(StrGuess)=IntNumber

strGuess = InputBox(“Enter your guess.”, _
“Guess the Number”)
if strGuess=”” then
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
Wscript.Echo “Too high and off by ” & Cint(strGuess)-IntNumber & “.”
elseif Cint(strGuess) < IntNumber then
Wscript.Echo "Too low and off by " & Cint(strGuess)-IntNumber & "."
end if

Loop

Wscript.Echo "You guessed it!"

Finally, here’s a variation that caters to those in the shallow end of the gene pool. I call this one Guess the Number for Dummies. Here the computer makes every effort to tell you the answer and gives you a hard time if you put in a wrong guess.

intHighNumber = 100
intLowNumber = 1

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

Wscript.Echo “HINT: The number I’m thinking of is “& intNumber & “.”

Do Until Cint(StrGuess)=IntNumber

strGuess = InputBox(“Enter the number I’m thinking, which is ” & intNumber & “.”, _
“Guess the Number for Dummies”)
if strGuess=”” then
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
Wscript.Echo “NO! Too high! The answer is ” & IntNumber & “! Try again!”
elseif Cint(strGuess) < IntNumber then
Wscript.Echo "NO! Too low! The answer is " & IntNumber & "! Try again!"
end if

Loop

Wscript.Echo "You actually got it? How did that happen?"
Wscript.Echo "MORON!"

You have no idea how much fun I had making that one.