use modules
use console, rand
def Run():
def mynum = rand!RandomGenerator().Choice(100) + 1
def yourguess = 200
def lastdist = 0
def tries = 0
*Stdout out
*Stdin in
console!out.Puts("I'm thinking of a number from 1 to 100.")
loop while (yourguess != mynum):
.tries = tries + 1
@prompt
console!out.Write("Your guess? ")
def ans = console!in.Gets()
.yourguess = Integer.parse(ans)
case if (yourguess != mynum):
.newdist = abs(yourguess - mynum)
case:
(lastdist = 0):
console!out.Puts("Guess again...").
(newdist > lastdist):
console!out.Puts("You're getting colder.").
else:
console!out.Puts("You're getting warmer.").
.
.lastdist = newdist
.
.
console!out.Puts("Good job! That took "(tries)" tries.")
catch (event: _(parsed: "")? ParseError):
console!out.Puts("The solution was "(mynum))
return.
catch (event: ?ParseError):
console!out.Puts("Type a number or ENTER")
resume @prompt.
.