Guess

Original author: Walt Koetke.

Description: Guess is similar to what number im thinking of game. Guess randoms a value between 1 to limit player has given and then player tries to guess wich number it is. Game gives hints is player guess higher or smaller than randomed value.

Original code was edited pretty hard way since it was pure GOTO jungle. Idea and source basic structure are still pretty near of original one. Player can now end game by giving value of 0 as limit.

E.K.Virtanen

SCREEN 12
CONST Min    = 0
CONST Max    = 10000

DIM AS Integer Limit, Rounds, Guess, Randomed, ShouldGet

DO
CLS
    Color 14, 0
    Print TAB(33); "Guess"
    Print TAB(15); "Creative Computing Morristown, New Jersey"

    Color 15, 0
    Print TAB(17); "Remade for FreeBASIC by E.K.Virtanen."
    Print TAB(22); "www.ascii-world.com"
    Print TAB(29); "Public Domain"
    Print ""
    Print "This is a guessing game. I'll think"
    Print "of a number between "; (Min + 1); " and any limit you want (max." ; Max; ")."
    Print "Then you have to guess what it is."
    Print ""
    INPUT "What limit do you want (0 to quit game)"; Limit
    Print ""

    IF Limit < (Min + 1) OR Limit > Max Then END

    ShouldGet = INT(LOG(Limit) / LOG(2)) + 1
    Rounds = 1
    Randomed = INT(RND * Limit) + 1

    DO
        Print : Print "I'm thinking of a number between 1 and "; Limit
        Print "Now you try to guess what it is. (0 to return menu)"
        INPUT Guess
            IF Guess = 0 Then EXIT DO

            IF Guess < Randomed Then Print "Too small, try higher one."
            IF Guess > Randomed Then Print "Too high, try smaller one."

            IF Guess = Randomed Then 
                Print "That's it! You got it in "; Rounds; " tries."
                IF Rounds < ShouldGet Then Print "Very ";
                IF Rounds = ShouldGet Then Print "Good."

                    IF Rounds > ShouldGet Then
                        Print "You should have been able to get it in only "; ShouldGet; " rounds."
                    END IF

                SLEEP : EXIT DO
            END IF

        Rounds = (Rounds + 1)
    Loop
Loop Until Limit = 0
END
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.