Microsoft Small Basic

Program Listing: FCD758
UPPER_A = Text.GetCharacterCode("A")
UPPER_Z = Text.GetCharacterCode("Z")
LOWER_A = Text.GetCharacterCode("a")
LOWER_Z = Text.GetCharacterCode("z")

stage_0:
TextWindow.Writeline("You're at a fork in the road. ")
TextWindow.Writeline("Which way do you go? ")
choices="LEFT,RIGHT,STAY"
Choose()
If id=1 Then
Goto stage_1_1
ElseIf id=2 Then
Goto stage_1_2
ElseIf id=3 Then
Goto stage_1_3
Else
Goto stage_0
EndIf

stage_1_1:
TextWindow.Writeline(" Good choice, you find some money. :)")
TextWindow.Writeline(" Have a nice day.")
Goto end
stage_1_2:

stage_1_3:

end:
TextWindow.Writeline("")
' end of program

Sub Choose
' param choices - e.g. "A,B,C"
' return id - e.g. 1 for A
' work a,c,cc,choice,i,len,n,p,u - will be broken

' Make array of choice
len=Text.GetLength(choices)
p=1
i=0
While p<=len
c=Text.GetIndexOf(Text.GetSubTextToEnd(choices,p),",")
If c=0 Then
c=len+1
Else
c=c+p-1
EndIf
i=i+1
choice[i]=Text.GetSubText(choices,p,c-p)
p=c+1
EndWhile
' Dispaly choices
n=i
For i=1 To n
TextWindow.Write(choice[i])
If i TextWindow.Write(" ")
ElseIf i=n-1 Then
TextWindow.Write(" or ")
EndIf
EndFor
TextWindow.WriteLine("")
' Input
a= TextWindow.Read()
' Convert to upper case
u=""
len=Text.GetLength(a)
For p=1 To len
cc=Text.GetCharacterCode(Text.GetSubText(a,p,1))
If LOWER_A<=cc And cc<=LOWER_Z Then
cc=cc-LOWER_A+UPPER_A
EndIf
u=Text.Append(u,Text.GetCharacter(cc))
EndFor
' Search id of choces
id=n
While choice[id]<>u And 0 id=id-1
EndWhile
EndSub