Computer Science Canada

Another Lame Text Game

Author:  Zampano [ Mon Sep 17, 2007 8:20 am ]
Post subject:  Another Lame Text Game

Here's my second game in Turing. It took 20 minutes of a boring class to make.
It could be hard if you have no strategy.
I hope you enjoy.
Turing:

var num,guess,tries,win:int
loop   
    win:=0
    tries:=7
    num:=Rand.Int(1,100)
    put "Guess the number between 1 and 100 in seven tries."
    loop
        get guess
        if guess>num and guess<101 then
            tries:=tries-1
            put "You guessed too high!"
            if tries>0 then
                put "Try again. You have ",tries," tries left."
            end if
        elsif guess<num and guess>0 then
            tries:=tries-1
            put "You guessed too low!"
            if tries>0 then
                put "Try again. You have ",tries," tries left."
            end if
        elsif guess=num then
            put "You got it!"
            win:=1
        else
            put "Invalid entry."
        end if
        exit when tries=0 or win=1
    end loop
    if win=1 then
        put "You won!"
    elsif win not=1 then
        put "You lost! Try again."
    end if
   
end loop


: