Computer Science Canada

simple but addictive (guess that number) game

Author:  a random person [ Sat Nov 26, 2005 9:40 am ]
Post subject:  simple but addictive (guess that number) game

this is a game I therw togather in under 5 minutes, forgive me for the simplicity but ive been only working with turing for about a couple of weeks. now that i got you all hyped I will now give you the code.
code:

var c, u, g : int
var p : string
loop
    g := 0
    randint (c, 1, 100)
    put "pick a number 1-100"
    get u
    for i : 1 .. 5
        if c < u then
            g := g + 1
            put "lower"
            get u
        elsif c > u then
            g := g + 1
            put "higher"
            get u
        else
        end if
        exit when c = u
    end for
    if c = u then
        put "you win in ", g, " guesses"
    else
        put "I win"
        put "the correct number was ", c
    end if
    put "play again, (y)es or (n)o?"
    get p
    if p = "y" then
        cls
    else
        exit when p = "n"
    end if
end loop

I hope you have fun and please give me feed back

Author:  jrblast [ Tue Nov 29, 2005 11:23 pm ]
Post subject: 

Very Happy this type of game is fun Very Happy and unlike with realy people, you wont have a number greater than 80 and less than 20 o.O

Author:  jamonathin [ Wed Nov 30, 2005 2:26 pm ]
Post subject: 

you know you're really missing one thing in your title.

Simple, stupid, and addicting.

Notice I didn't take out the addicting part. I actually played it a few times (surprisingly) where my best was four. It's stupid that it's addicting. . lol.

Author:  MysticVegeta [ Wed Nov 30, 2005 2:47 pm ]
Post subject: 

jamonathin wrote:
stupid


Isnt that a little bit harsh for new people?

Author:  a random person [ Wed Nov 30, 2005 4:07 pm ]
Post subject:  DO BETTER

jamonathin, if you think your so good then, make a better guessing game
that is not "stupid" and post it on this thread.

plz give feedback and rate it out of 10

Author:  Tony [ Wed Nov 30, 2005 5:01 pm ]
Post subject: 

it would be good to use meaningful names and perhaps comments.. espectially when other people are looking at your code (and since you posted it here, you must have expected someone to read it).

looking at
code:

if p = "y" then

I have no idea what's going on. P and Y are different letters, why should this ever be true? Wink

Author:  [Gandalf] [ Wed Nov 30, 2005 6:28 pm ]
Post subject:  Re: DO BETTER

a random person wrote:
if you think your so good then, make a better guessing game

Ok Wink Well, since goodness is relative, I'll make it shorter heh...
code:
var randomNumber : int := Rand.Int (1, 100)
var guessedNumber : int
var guessesUsed : int := 0
loop
    put "Enter your guess: " ..
    get guessedNumber
    guessesUsed += 1
    if guessedNumber > randomNumber then
        put "Too high!"
    elsif guessedNumber < randomNumber then
        put "Too low!"
    end if
    exit when guessedNumber = randomNumber
end loop
put "You won!  It took you ", guessesUsed, " tries to get the number ", randomNumber, "."


One slightly different thing about your game is that it has a guess limit - great!

Author:  Tony [ Thu Dec 01, 2005 10:07 am ]
Post subject:  Re: DO BETTER

[Gandalf] wrote:
Ok Wink Well, since goodness is relative, I'll make it shorter heh...

Gandalf, stop showing off. Besides, a guessing game could be done in 8 lines
Turing:

var guessedNumber, randomNumber : int := Rand.Int (1, 100)
for guessCount : 1 .. maxint
    put "Enter your guess #(", guessCount, "): " ..
    get guessedNumber
    put "Saying that your guess is 'too high' is: ", guessedNumber > randomNumber
    exit when guessedNumber = randomNumber
end for
put "You won!"

Author:  jamonathin [ Thu Dec 01, 2005 12:01 pm ]
Post subject:  Re: DO BETTER

a random person wrote:
jamonathin, if you think your so good then, make a better guessing game
that is not "stupid" and post it on this thread.

plz give feedback and rate it out of 10

code:
setscreen ("msdos")
var numb, guess : int := Rand.Int (128, 254)
loop
    put "Enter your number guess for:\n\n             ", chr (numb), "\n\n         (128-254)\n\n"
    get guess
    cls
    exit when numb = guess
end loop

Take an educated guess.

I give it a 3/10.

Author:  [Gandalf] [ Thu Dec 01, 2005 4:14 pm ]
Post subject:  Re: DO BETTER

Tony wrote:
Gandalf, stop showing off. Besides, a guessing game could be done in 8 lines

Sad I wasn't going for as short as possible, the main point of my program was to show him using good variable names, functions instead of procs, etc.

I wouldn't show off making a guessing game in Turing. If I wanted to do that, I'd have to make it in Python Smile

Besides, if you want less lines, I'd make it in 1:
code:
var guessedNumber, randomNumber : int := Rand.Int (1, 10) for guessCount : 1 .. maxint put "Guess #(", guessCount, ")? " .. get guessedNumber put guessedNumber = randomNumber exit when guessedNumber = randomNumber end for

Author:  Tony [ Thu Dec 01, 2005 4:37 pm ]
Post subject:  Re: DO BETTER

[Gandalf] wrote:
Besides, if you want less lines, I'd make it in 1:

We count the number of lines after Turing's F2 indent. It makes your a 7, and only because you took out that last put "you win" statement Razz

Author:  a random person [ Thu Dec 01, 2005 4:42 pm ]
Post subject: 

Quote:

jamonathin, if you think your so good then, make a better guessing game
that is not "stupid" and post it on this thread.


there i quoted myself, jamonathen, didn't i say a game that is not <b> stupid</b>.

this isn't the pot calling the kettle black here, if you realy want you can retry.

and guys, great job condensing my game.

Author:  Cervantes [ Thu Dec 01, 2005 5:42 pm ]
Post subject: 

Let's not let things get out of control.

Locked.


: