A learning program that guesses an animal. The more you play it the more it knows!
We got the idea from an old program from the 70's and it is a fun learning experience for beginners. it's fully commented to help explain what is going on.
We also added some other bits n bobs which aren't essential but they make it a bit nicer
Hope someone gets something out of it! Enjoy
dim question$(1000,3) `makes the database where the questions and animals are stored
`question$(x,1)=the question
`question$(x,2)=link to yes answer
`question$(x,3)=link to no answer
question$(1,1)="Is it a Mammal? "
question$(1,2)="3"
question$(1,3)="2"
question$(2,1)="Dodo"
question$(3,1)="Shrew"
if file exist("database.txt")=1 then load array "database.txt", question$(1000,3): `loads all the questions and animals for use- provided the file exists
scrx=screen width()/2
scry=screen height()/2
question=1
center text scrx,scry,"Welcome to the Animal guessing game!"
center text scrx,scry+40,"Press any key to continue."
gosub refresh
center text scrx,scry,"I want you to think of an animal..."
center text scrx,scry+40,"Press any key to continue."
gosub refresh
center text scrx,scry,"Any animal at all."
center text scrx,scry+40,"Press any key to continue."
gosub refresh
center text scrx,scry,"I'll ask you some questions now!"
center text scrx,scry+40,"Press any key to continue."
gosub refresh
do
if question$(question,2)="" or question$(question,3)="" then center text scrx,scry,"Is it a " + question$(question,1)+" ?" else center text scrx,scry,question$(question,1) :`writes the question on the screen, or the animal if there are no questions left.
if question<>0:`if there are questions left
oldanswer$=answer$
there:
if answer=0 then center text scrx,scry,question$(question,1)
set cursor scrx,scry+20:input answer$:` where you put in your answer to the question(yes or no)
gosub answers
if answer=0
cls
sync
sync
goto there
endif
oldoldquestion=oldquestion
oldquestion=question
if answer=1 then question=val(question$(question,2)):`Makes the current question go up the yes path from the one you just answered yes to.
if answer=2 then question=val(question$(question,3)):`Makes the current question go up the no path from the one you just answered no to.
wait 100:cls
endif
if question=0 and answer=2:`if you have answered no to a animal question
cls
Sync
Sync
center text scrx,scry,"I give up, what is your animal?"
set cursor scrx,scry+20:input newanimal$ :`where you put in the new animal
caps$=left$(newanimal$,1):`finds the first letter in the name of your animal
caps$=upper$(caps$):` makes it a capital letter
newanimal$=caps$+right$(newanimal$,len(newanimal$)-1):` and here it grafts it all together
cls
Sync
Sync
center text scrx,scry,"(Don't worry about the question mark!)"
center text scrx,scry-20,"what question differentiates a "+newanimal$+" from a " + question$(oldquestion,1)
set cursor scrx,scry+20:Input newquestion$ :` where you put in the new question
newquestion$=newquestion$+" ?":` puts in the question mark for you.
caps$=left$(newquestion$,1):`finds the first letter in the question you typed in
caps$=upper$(caps$):` makes it a capital letter
newquestion$=caps$+right$(newquestion$,len(newquestion$)-1):` and here it grafts it all together
here:
cls
Sync
Sync
center text scrx,scry,"for a "+newanimal$+", what is the answer to '" + newquestion$ +"'"
set cursor scrx,scry+20:Input newanswer$:` where you put in the answer to your new question that leads to you new animal
gosub answers
if newanswer=0 then goto here
for x=1 to 1000
if question$(x,1)="" then emptyspot=x:exit:`find the next empty spot in the database
NEXT
question$(emptyspot,1)=newanimal$ : ` insert your new animal here
question$(emptyspot+1,1)=newquestion$:`goto the next slot up and insert the question for your animal
if newanswer=1 :`yes
question$(emptyspot+1,2)=str$(emptyspot): `links the yes answer for your question to the animal
question$(emptyspot+1,3)=str$(oldquestion) :`links the no answer to the last question you answered
endif
if newanswer=2:`no
question$(emptyspot+1,3)=str$(emptyspot): `links the no answer for your question to the animal
question$(emptyspot+1,2)=str$(oldquestion):` links the yes answer to the last question you answered
endif
if oldoldanswer=1 then question$(oldoldquestion,2)=str$(emptyspot+1):` links the yes path of the last non-animal question you answered to your new question(if you answered yes)
if oldoldanswer=2 then question$(oldoldquestion,3)=str$(emptyspot+1):` links the no path of the last non-animal question you answered to your new question(if you answered no)
answer=0
question=1:oldquestion=0:oldoldquestion=0:oldanswer=0
save array "Database.txt" , question$(1000,3):` saves the database for future use
cls
rand=rnd(4)+1
if rand=1 then center text scrx,scry,"Processing your response"
if rand=2 then center text scrx,scry," Processing information "
if rand=3 then center text scrx,scry," Learning about animal "
if rand=4 then center text scrx,scry," Learning your response "
if rand=5 then center text scrx,scry," Thinking about answer "
gosub Blink
center text scrx,scry+20,"Press any key to continue."
gosub refresh
ENDIF
if question=0 and answer=1: `if there are no more questions left and you've answered yes to the last one
answer=0
question=1:oldquestion=0:oldoldquestion=0:oldanswer=0
cls
Sync
Sync
center text scrx,scry,"I am the greatest!!" :` celebration ;)
suspend for key
cls
Sync
Sync
ENDIF
remstart
for x=1 to 20
text 320,x*20,str$(x)+". " + question$(x,1) + " / " +question$(x,2) + " / " +question$(x,3) + "/"
next x
remend
sync
LOOP
answers:
oldoldanswer=oldanswer
oldanswer=answer
answer=0
newanswer=0
if answer$="y" or answer$="Y" or answer$="YES" or answer$="yes" or Answer$="Yes" then answer=1 :`where it converts your yes answer for a non-animal question into a number
if answer$="n" or answer$="N" or answer$="NO" or answer$="no" or Answer$="No" then answer=2 :`where it converts your no answer for a non-animal question into a number
if newanswer$="y" or newanswer$="Y" or newanswer$="YES" or newanswer$="yes" then newanswer=1 :` where it converts your yes answer for your new animal into a number
if newanswer$="n" or newanswer$="N" or newanswer$="NO" or newanswer$="no" then newanswer=2 : ` where it converts your no answer for your new animal into a number
answer$=""
newanswer$=""
return
refresh:
sync
sync
suspend for key
cls
return
blink:
for x=1 to 5
text (scrx+85)+x*8,scry, "."
wait 500
next x
return