Code: Select all
' FreeBasic Magic 8 Ball program
SCREENRES 800, 600, 32
CONST PI = 3.14159265359
CONST RADIUS = 200
CONST SPEED = 0.05
DIM SHARED AS INTEGER centerX, centerY
DIM SHARED AS DOUBLE angle, x, y
Dim As Integer randomAnswer
Dim As UByte cnt = 0, n = 0
Dim As String key, question
centerX = 400: x = 600
centerY = 300: y = 300
Dim shared As String answers(20)
answers(0) = "Yes"
answers(1) = "No"
answers(2) = "Maybe"
answers(3) = "Ask Again Later"
answers(4) = "Outlook not so good"
answers(5) = "Definitely"
answers(6) = "Cannot predict now"
answers(7) = "Most likely"
answers(8) = "Don't count on it"
answers(9) = "You may rely on it"
answers(10) = "Reply hazy, try again"
answers(11) = "Better not tell you now"
answers(12) = "My sources say no"
answers(13) = "As I see it, yes"
answers(14) = "Concentrate and ask again"
answers(15) = "Very doubtful"
answers(16) = "Signs point to yes"
answers(17) = "It is certain"
answers(18) = "It is decidedly so"
answers(19) = "Without a doubt"
Randomize
Color rgb (0, 0, 0), rgb(255,255,255)
Cls
CIRCLE (400, 300), 230, RGB(0, 0, 0),,,,F
Locate 4,20:Print "Welcome to the Magic 8 Ball! Ask a yes or no question out loud."
Locate 6,20: Print "Then press the space bar. Its not necessary to type the question."
locate 33,38:Print " "
locate 34,38:Print " "
locate 35,38:Print " "
Do
key = Inkey
if key = chr(32) Then n = 1:locate 34,38:Print " "
if n = 1 Then cnt += 1
' pause before giving an answer
If cnt >= 100 Then
randomAnswer = Int(Rnd * 20)
locate 34,38: Print " "; answers(randomAnswer); " "
cnt = 0: n = 0
End If
ScreenLock
CIRCLE (x, y), 30, RGB(0, 0, 0),,,,F
angle = angle + SPEED
x = centerX + RADIUS * COS(angle)
y = centerY + RADIUS * SIN(angle)
CIRCLE (x, y), 30, RGB(0, 255, 0),,,,F
ScreenUnlock
SLEEP 10, 1
Loop Until (key = Chr(27)) Or (key = Chr(255) & "k")