Jump to content

TI-Basic Programs/GuessMe

From Wikibooks, open books for an open world

Program Description

[edit | edit source]

GuessMe is a wonderful, enjoyable game based upon the simple concept of guessing a number. In this game, the player interacts with the calculator in a sort of dialogue. When the program is initiated, a Main Menu opens and the player is given five options:

  1. 1,000
  2. 10,000
  3. 100,000
  4. HI SCORES
  5. QUIT

Option 4 types up a screen which displays the current high score for each of the three difficulty levels, and Option 5 simply quits the program and returns to the main calculator entry screen. If the player selects Option 1, 2, or 3, the game will begin. The game begins by the calculator choosing a random number for the player to guess. If the player chose Option 1, then the number chosen by the calculator will be any number from 1 to 1000. The maximum number for Option 2 is 10000 and the maximum number for option 3 is 100000. This means that there are three difficulty levels that the player can choose from and that the calculator will save a separate high score for each difficulty which can all be seen on the High Score page by selecting Option 4 from the Main Menu. After selecting a number for the player to guess, the calculator tells the player what is going on and prompts him for his first guess. It does so with these messages: "Im thinking of a number between 1 and 1,000..." (This will say "10,000" in difficulty 2 and "100,000" in difficulty 3), "What is it?" The player can then enter his first guess.

After each guess, the calculator will respond with a message saying "Higher" if the player's guess was too low or "Lower" if the player's guess was too high. In difficulty 3, the calculator may also say "Much higher" or "Much lower".
If the player guesses a number which is less than 1 or more than the maximum, the calculator will respond with, "Hey! I said it was between 1 and 1,000!" (As before, this final number will depend on which Option was chosen).
If the player's guess is within 1 number of the answer then the calculator will say "Youre SO close! Just a little higher!" or "Youre SO close! Just a little lower!"
After 20 guesses, the calculator will taunt the player with the message, "Hurry it up!"
After 30 guesses, the calculator says "Gosh! You take forever!!!"
The only other message that the calculator might show to the player is one that will only be displayed if the player cheats to guess the answer on his first try or if by chance he guesses the secret number on his very first try. If this is done, the calculator will simply say, "YOU CHEATER!" and the program will abruptly end.

When the player eventually guesses the correct number, a series of messages will be displayed. The first is: "You got it!!!", followed by the correct answer, then "In this many tries:", followed by the number of guesses it took the player to find the number. Then, if the player has broken the high score for that difficulty level, he will see the message, "HIGH SCORE!!"

Note: The variables used by the calculator to operate GuessMe are stored in the [J] matrix.

Program Code

[edit | edit source]
PROGRAM:GUESSME
:ClrHome
:{3,9}→dim([J])
:0→X
:If 0=[J](3,7)
:Then
:100→[J](1,8)
:100→[J](2,8)
:100→[J](3,8)
:End
:Lbl 6
:Menu("MAIN MENU","1,000",1,"10,000",2,"100,000",3,"HI SCORES",5,"QUIT",Z)
:Lbl 5
:Output(2,3,"HI     1:     SCORES:  2:)
:Output(4,10,"3:)
:Output(2,13,[J](1,8)
:Output(3,13,[J](2,8)
:Output(4,13,[J](3,8)
:Output(7,3,"PRESS ENTER")
:Pause 
:ClrHome
:Goto 6
:Lbl 1
:1000→C
:Goto 4
:Lbl 2
:10000→C
:Goto 4
:Lbl 3
:100000→C
:Lbl 4
:randInt(1,C)→B
:ClrHome
:Disp "Im thinking of a","number between 1","and"
:If 3=log(C)
:Output(3,5,"1,000...")
:If 4=log(C)
:Output(3,5,"10,000...")
:If 5=log(C)
:Output(3,5,"100,000...")
:Lbl A
:Input "What is it",A
:X+1→X
:If X=20
:Disp "  Hurry it up!
:If X=30
:Disp " Gosh! You take","   forever!!!"
:If A<1 or A>C
:Then
:Disp " Hey! I said it"," was between 1"," and"
:If 3=log(C)
:Output(7,6,"1,000!")
:If 4=log(C)
:Output(7,6,"10,000!")
:If 5=log(C)
:Output(7,6,"100,000!")
:Goto A
:End
:If A<B-1 and A>B-25000
:Then
:Disp " Higher"
:Goto A
:End
:If A>B+1 and A<B+25000
:Then
:Disp " Lower"
:Goto A
:End
:If A≥B-1 and A<B
:Then
:Disp " Youre SO close!"," Just a little","    higher!"
:Goto A
:End
:If A≤B+1 and A>B
:Then
:Disp " Youre SO close!"," Just a little","     lower!"
:Goto A
:End
:If A≤B-25000
:Then
:Disp " Much higher"
:Goto A
:End
:If A≥B+25000
:Then
:Disp " Much lower"
:Goto A
:End
:If A=B and X=1
:Then
:Disp "  YOU CHEATER!"
:Output(1,1,"")
:Stop
:Else
:Disp "  You got it!!!",B,"","In this many","     tries:",X
:Output(2,1,"")
:End
:If X<[J](log(C)-2,8)
:Then
:X→[J](log(C)-2,8)
:Output(8,3,"HIGH SCORE!!")
:1→[J](3,7)
:Lbl Z
:Output(1,1,"")
:Stop