# Warmer/colder game, the player has to guess a number with the help of
# the computer. The game was translated in dodo to illustrate Python-style
# programming
# 
# Original version:
#   warmer.py       3/11/96 by Joe Strout
# http://www.strout.net/python/warmer.py

class Run:
    Run():
        # pick a number in the range 1-100
        def mynum = rand!RandomGenerator().Choice(100) + 1
    
        def yourguess = 200    # what user guessed
        def lastdist = 0       # last distance to mynum
        def tries = 0          # number of tries so far
        Stdout out
        Stdin in

        console!out.Puts("I'm thinking of a number from 1 to 100.")
    
        # main loop: repeat until user gets it right
        loop while (yourguess != mynum):
    
            .tries = tries + 1
            $$prompt
            console!out.Write("Your guess? ")
            def ans = console!in.Gets()
            .yourguess = Integer.parse(ans)
    
            test (yourguess != mynum):
        
                # find how far off you are
                .newdist = abs(yourguess - mynum)
    
                # print warmer/colder than last time
                test:
                    (lastdist = 0):
                        console!out.Puts("Guess again..."). #first try
                    (newdist > lastdist):
                        console!out.Puts("You're getting colder.").
                    default:
                        console!out.Puts("You're getting warmer.").
                .
                .lastdist = newdist
            .
        .
    
        console!out.Puts("Good job!  That took " & tries + " tries.")
    
        catch (event: $e):
            test match (e):
                &(parsed: "")/ParseError:
                    console!out.Puts("The solution was " & mynum)
                    return.
                &/ParseError:
                    console!out.Puts("Type a number or ENTER")
                    resume $$prompt.
            .
        .
    .
.