Beginning Programming 3 - Appendices

by Brad Moore

Appendix A


'The Magic 6 ball
'Written by Joshua Moore and Brad Moore'
'Copyright 2002, all rights reserved
'written for LB3.x
'You are free to incorporate any portion of this code
'into your own programs without notification or credit
'to the authors.  Please do not distribute as-is.

print "Hello - Ready to play Magic 8 Ball."

[getPlayer]
print "Enter your name please";
input name$
print ""

if name$ = "" then 
  print "You did not enter anything for your name!"
  print "Try agian...";
  goto [getPlayer]
end if

[instructions]
Print ""
print "I am the Magic 6 ball - I can tell the future..."
print "Ask me a yes or no question and I will tell the answer!"
print ""

[loop]
print name$; "What do you wish to ask the Magic 6 ball,"
print "(please make it a 'yes' or 'no' question)";
input question$
print ""

if question$ = "" then 
  print "I am sorry, I did not hear you."
  print "  Perhaps you should type a little louder.";
  goto [loop]
end if

'get a random number between 1 and 6
number = int(rnd(1)*6) + 1

if number = 1 then
   print "MAYBE..."
   goto [playagain]
end if

if number = 2 then
   print "NO! - Never - Don't ask again!"
   goto [playagain]
end if

if number = 3 then
   print "Its not clear now."
   goto [playagain]
end if

if number = 4 then
   print "Yes"
   goto [playagain]
end if

if number = 5 then
   print "Probably not..."
   goto [playagain]
end if

print "You can count on it!"

[playagain]
  'ask if they want to play again
  print ""
  print "Do you want to play again - (y = yes)";
  input answer$
  if answer$ = "y" or answer$ = "Y" then
     cls
     goto [loop]
  end if

print "Thanks for playing"


Appendix B


'The Magic 6 ball - version 2
'Written by Joshua Moore and Brad Moore'
'Copyright 2002, all rights reserved
'written for LB3.x
'You are free to incorporate any portion of this code
'into your own programs without notification or credit
'to the authors.  Please do not distribute as-is.

'DIMension a string array to hold the answers
DIM answer$(6)

'Now assign the text strings to each array member
answer$(1) = "MAYBE..."
answer$(2) = "NO! - Never - Don't ask again!"
answer$(3) = "Its not clear now."
answer$(4) = "Yes"
answer$(5) = "Probably not..."
answer$(6) = "You can count on it!"

'Start the interaction with the user
print "Hello - Ready to play Magic 6 Ball."

[getPlayer]
print "Enter your name please";
input name$
print ""

if name$ = "" then 
  print "You did not enter anything for your name!"
  print "Try agian...";
  goto [getPlayer]
end if

[instructions]
Print ""
print "I am the Magic 6 ball - I can tell the future..."
print "Ask me a yes or no question and I will tell the answer!"
print ""

[loop]
print name$; " What do you wish to ask the Magic 6 ball,"
print "(please make it a 'yes' or 'no' question)";
input question$
print ""

if question$ = "" then 
  print "I am sorry, I did not hear you."
  print "  Perhaps you should type a little louder.";
  goto [loop]
end if

'get a random number between 1 and 6
number = int(rnd(1)*6) + 1

'now simply print the answer
print answer$(number)

[playagain]
  'ask if they want to play again
  print ""
  print "Do you want to play again - (y = yes)";
  input answer$
  if answer$ = "y" or answer$ = "Y" then
     cls
     goto [loop]
  end if

print "Thanks for playing"


Appendix C


'The Magic 6 ball - version 3
'Written by Joshua Moore and Brad Moore'
'Copyright 2002, all rights reserved
'written for LB3.x
'You are free to incorporate any portion of this code
'into your own programs without notification or credit
'to the authors.  Please do not distribute as-is.

'DIMension a string array to hold the answers
DIM answer$(6)

'Now assign the text strings to each array member
answer$(1) = "MAYBE..."
answer$(2) = "NO! - Never - Don't ask again!"
answer$(3) = "Its not clear now."
answer$(4) = "Yes"
answer$(5) = "Probably not..."
answer$(6) = "You can count on it!"

'Start the interaction with the user
Notice "Hello - I am the Magic 6 ball - I can tell the future.  " + _ 
       "After we have been introduced, you will have a chance to " + _
       "Ask me a yes or no question and I will tell the answer!"

[getPlayer]
prompt "You know me, but who are you (enter name)?";name$

if name$ = "" then 
  Notice "You did not enter anything for your name! - Try agian..."
  goto [getPlayer]
end if


[loop]
Prompt name$ + " Ask Magic 6 a 'yes' or 'no' question.";question$

if question$ = "" then 
  Notice "I am sorry, I did not hear you.  Perhaps you should type a little louder."
  goto [loop]
end if

'get a random number between 1 and 6
number = int(rnd(1)*6) + 1

'now simply print the answer
Notice "Magic 6 ball says: " + answer$(number)


'ask if they want to play again

Confirm "Do you want to play again?";answer$
if answer$ = "yes" then
   goto [loop]
end if

Notice "Thanks for playing"