REM Project: GravMath
REM Created: 10/21/2006 7:58:11 PM
REM Author: Rburke87
REM ***** Main Source File *****
REM
 
Set Display Mode 800,600,32
Sync On
Hide Mouse
 
Rem Initial Values
r = 0 ; g = 0 ; b = 25 ` Default Values for coloring the background
bgY = 0 ` Controls position for stacking colored boxes for background
Level = 1 ` Game Starts with the first level
barTotal# = 220 ; bar# = 200` Start with the bar empty
mG = 250; mB = 100` Mouse Cursor Color Values
`Problem$ = "Addition" ` Game Will Start with Addition
Speed# = 3 ` Starting falling speed of the math problems
`Nextdigit = 1 ` Value to contain selected answers
ProbCount = 1 ` If reaches a certain number, will get next problem
dim Num1(20) ; dim Num2(20) ; dim NumAns(20) ; dim NumY(20) ; dim NumX(20)
dim Digit1(20) ; dim Digit2(20) ; dim Digit3(20) dim NumYchance(20) ; dim NumColor(20)
dim NumStart(20) ; dim NumSelect(20) ; dim Nextdigit(20) ; dim Cht$(16) ; dim ChtX(50) ; dim ChtY(50)
dim ChtFall(50)
NumSelect(0) = 1 ` The First problem is selected at the start
 
for i = 0 to 20
   Nextdigit(i) = 1
   Digit1(i) = -1 ; Digit2(i) = -1 ; Digit3(i) = -1
next i
 
   Rem Draw the background
   For bgGrad = 1 to 60
      ink RGB(r,g,b),1
      box 0,bgY,screen width(),bgY + 10
      bgY = bgY + 10
      if b <= 255 Then b = b + 2
      if b >= 50
         g = g + 1
         r = r + 1
      endif
      if bgY >= screen height()
         bgY = 0 ; r = 0 ; g = 0 ; b = 25
      endif
   next bgGrad
 
   Set Current Bitmap 0
   Get Image 1,0,0,screen width(),screen height()
 
   set text font "Arial Black"
 
   for i = 0 to 50
      ChtX(i) = RND(screen width() - 50)
      ChtFall(i) = 100 * i
   next i
 
 
REM MAIN LOOP ####################################################################
REM ########## MAIN LOOP #########################################################
REM ##################### MAIN LOOP ##############################################
 
do
 
   Randomize (Timer())
 
   Rem Display The Title Screen
   While TitleScreen = 0
      FallCount = FallCount + 10
      Ink RGB(0,20,0),1 ; box 0,0,screen width(),screen height()
      Ink RGB(255,255,255),1 `; Text 100,100,"§»«¬¥¤£¢µ±Ø×çæ¿ÿþ"
      Cht$(0) = "§" ; Cht$(1) = "»" ; Cht$(2) = "«" ; Cht$(3) = "¬" ; Cht$(4) = "¥" ; Cht$(5) = "¤"
      Cht$(6) = "£" ; Cht$(7) = "¢" ; Cht$(8) = "µ" ; Cht$(9) = "±" ; Cht$(10) = "Ø" ; Cht$(11) = "×"
      Cht$(12) = "ç" ; Cht$(13) = "æ" ; Cht$(14) = "¿" ; Cht$(15) = "ÿ" ; Cht$(16) = "þ"
      Ink RGB(0,255,150),1
      set text size 70 ; Text 325,150,"Grav" ; set text size 100 ; Text 250,225,"M A T H"
      set text size 20
 
      for i = 0 to 50
         Ink RGB(0,255,150),1
         if ChtY(i) >= screen height() Then ChtY(i) = 0
         if ChtY(i) >= screen height() Then ChtX(i) = RND(screen width()-50)
         if FallCount >= ChtFall(i)Then ChtY(i) = ChtY(i) + 10
         Text ChtX(i),ChtY(i),Cht$(RND(16))
         Text ChtX(i),ChtY(i) - 20 ,Cht$(RND(16))
         Text ChtX(i),ChtY(i) - 40 ,Cht$(RND(16))
         text 320,550,"Press Enter to Begin"
         Ink RGB(0,20,0),1 ; Box 0,0,Screen Width(),50
      next i
      sync
      cls
      if ReturnKey() = 1 Then TitleScreen = 1
   endwhile
 
   Paste Image 1,0,0 ` Paste The Background Image
 
`   if SpaceKey() = 1
 `  ProbCount = ProbCount + 500
  ` Speed# = Speed# + 3
   `endif
 
   if Level = 1 Then Problem$ = "Addition"
   if Level = 2 Then Problem$ = "Subtraction"
   if Level = 3 Then Problem$ = "Multiplication"
   if Level = 4 Then Problem$ = "Addition"
   if Level = 5 Then Problem$ = "Subtraction"
   if Level = 6 Then Problem$ = "Multiplication"
   if Level = 7 Then Problem$ = "Addition"
   if Level = 8 Then Problem$ = "Subtraction"
   if Level = 9 Then Problem$ = "Multiplication"
 
   Rem Set Up Math Problems
   if Problem$ = "Addition"
      if SetProblem = 0
         for i = 0 to 20
            Num1(i) = RND(10) ; Num2(i) = RND(10)
            if Num1(i) <> 10 or Num2(i) <> 10 Then NumAns(i) = Num1(i) + Num2(i)
            if Num1(i) = 10 and Num2(i) = 0 Then NumAns(i) = 10
            if Num1(i) = 0 and Num2(i) = 10 Then NumAns(i) = 10
            if Num1(i) = 10 and Num2(i) = 10 Then NumAns(i) = 20
            NumX(i) = RND(Screen Width())
            while NumX(i) > 650 ` Prevent Problems reaching off screen
               NumX(i) = RND(Screen Width())
            endwhile
         next i
         SetProblem = 1
      endif
   endif
 
   If Problem$ = "Subtraction"
      if SetProblem = 0
         for i = 0 to 20
            Num1(i) = RND(10) ; Num2(i) = RND(10)
            while Num2(i) > Num1(i) ` First Number generated will always be greater than the second term
               Num1(i) = RND(10)
            endwhile
            NumAns(i) = Num1(i) - Num2(i)
            NumX(i) = RND(Screen Width())
            while NumX(i) > 650 ` Prevent Problems reaching off screen
               NumX(i) = RND(Screen Width())
            endwhile
         next i
         SetProblem = 1
      endif
   endif
 
   If Problem$ = "Multiplication"
      if SetProblem = 0
         for i = 0 to 20
            Num1(i) = RND(10) ; Num2(i) = RND(10)
            NumAns(i) = Num1(i) * Num2(i)
            NumX(i) = RND(Screen Width())
            while NumX(i) > 650 ` Prevent Problems reaching off screen
               NumX(i) = RND(Screen Width())
            endwhile
         next i
         SetProblem = 1
      endif
   endif
 
   Rem Set up timing sequence for Problems
   if SetProblem = 1
      for i = 0 to 20
         NumStart(i) = 600*i - NumStart(i) - 5
      next i
      SetProblem = 2
   endif
 
   Rem Adjust Speed
   if Speed# <= 7 Then Speed# = Speed# + 0.01 ` Speed Adjustment. Max speed is 7
   if Level = 4 Then Speed# = 7
   if Level = 5 Then Speed# = 7
   if Level = 6 Then Speed# = 7
   if Level = 7 Then Speed# = 9
   if Level = 8 Then Speed# = 9
   if Level = 9 Then Speed# = 9
 
      Rem Draw Math Problems
      for a = 0 to 20
 
      if numColor(a) = 1 Then ink RGB(0,255,0),1
      if numColor(a) = 2 Then ink RGB(255,0,0),1
      if numColor(a) = 0 Then ink RGB(255,255,255),1
      if numSelect(a) = 1 Then ink RGB(255,255,150),1
      Set Cursor NumX(a),NumY(a)
 
      Rem Setup Score and Bar Display information
      If Score > ScoreTotal Then Score = Score - 1 ` Number Decreases by 1 until correct Score is reached
      If Score < ScoreTotal Then Score = Score + 1 ` Number Increases by 1 until correct Score is reached
      If bar# > barTotal# Then bar# = bar# - 0.1
      if bar# < barTotal# Then bar# = bar# + 0.1
      if bar# > 500 Then bar# = 500 ` Fix the red bar running over frame
 
      Rem Actions taken if Problems hit bottom of screen
      if NumY(a) >= 500 and numColor(a) > 0
         NumYchance(a) = 1 ; NumY(a) = 0
      endif
      if NumY(a) >= 500 and numColor(a) = 0
         NumYchance(a) = 1
         ScoreTotal = ScoreTotal - 100
         barTotal# = barTotal# - 15
         NumY(a) = 0
         if NumSelect(20) = 0 Then NumSelect(a+1) = 1
         if NumSelect(20) = 0 Then NumSelect(a) = 0
      endif
 
      Rem Print Addition Problems
      if nextdigit(a) = 1  and digit1(a) <= -1 and NumYchance(a) <> 1 and Problem$ = "Addition"
         Print Num1(a)," + ",Num2(a)," = "
      endif
      if nextdigit(a) = 1 and digit1(a) > -1 and NumYchance(a) <> 1 and Problem$ = "Addition"
         Print Num1(a)," + ",Num2(a)," = ",digit1(a)
      endif
      if nextdigit(a) = 2 and digit2(a) <= -1 and NumYchance(a) <> 1 and Problem$ = "Addition"
         print Num1(a)," + ",Num2(a)," = ",digit1(a)
      endif
      if nextdigit(a) = 2 and digit2(a) > -1 and NumYchance(a) <> 1 and Problem$ = "Addition"
         Print Num1(a)," + ",Num2(a)," = ",digit1(a),digit2(a)
      endif
 
      Rem Print Subtraction Problems
      if nextdigit(a) = 1  and digit1(a) <= -1 and NumYchance(a) <> 1 and Problem$ = "Subtraction"
         Print Num1(a)," - ",Num2(a)," = "
      endif
      if nextdigit(a) = 1 and digit1(a) > -1 and NumYchance(a) <> 1 and Problem$ = "Subtraction"
         Print Num1(a)," - ",Num2(a)," = ",digit1(a)
      endif
      if nextdigit(a) = 2 and digit2(a) <= -1 and NumYchance(a) <> 1 and Problem$ = "Subtraction"
         print Num1(a)," - ",Num2(a)," = ",digit1(a)
      endif
      if nextdigit(a) = 2 and digit2(a) > -1 and NumYchance(a) <> 1 and Problem$ = "Subtraction"
         Print Num1(a)," - ",Num2(a)," = ",digit1(a),digit2(a)
      endif
 
      Rem Print Multiplication Problems
      if nextdigit(a) = 1  and digit1(a) <= -1 and NumYchance(a) <> 1 and Problem$ = "Multiplication"
         Print Num1(a)," x ",Num2(a)," = "
      endif
      if nextdigit(a) = 1 and digit1(a) > -1 and NumYchance(a) <> 1 and Problem$ = "Multiplication"
         Print Num1(a)," x ",Num2(a)," = ",digit1(a)
      endif
      if nextdigit(a) = 2 and digit2(a) <= -1 and NumYchance(a) <> 1 and Problem$ = "Multiplication"
         print Num1(a)," x ",Num2(a)," = ",digit1(a)
      endif
      if nextdigit(a) = 2 and digit2(a) > -1 and NumYchance(a) <> 1 and Problem$ = "Multiplication"
         Print Num1(a)," x ",Num2(a)," = ",digit1(a),digit2(a)
      endif
      if nextdigit(a) = 3 and digit2(a) > -1 and digit3(a) = -1 and NumYchance(a) <> 1 and Problem$ = "Multiplication"
         Print Num1(a)," x ",Num2(a)," = ",digit1(a),digit2(a)
      endif
      if nextdigit(a) = 3 and digit3(a) > -1 and NumYchance(a) <> 1 and Problem$ = "Multiplication"
         Print Num1(a)," x ",Num2(a)," = ",digit1(a),digit2(a),digit3(a)
      endif
 
      Rem Move Problems
      if ProbCount >= NumStart(a) and NumYchance(a) <> 1 Then NumY(a) = NumY(a) + Speed#
 
      Rem Keyboard Input
      if ReturnKey() = 1 and NumSelect(a) = 1 and Submit = 1 ` Will Submit Selected Problem
         Rem For :: ADDITION :: ADDITION :: ADDITION :: ADDITION :: ADDITION :: ADDITION ::
         if digit1(a) = NumAns(a) and Problem$ = "Addition" and numColor(a) = 0 and NumAns(a) < 10 `Single Digit Correct Answers
            NumColor(a) = 1 ; ScoreTotal = ScoreTotal + 100 ; barTotal# = barTotal# + 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0 ` Deselects Attempted Problem
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a)*10 + digit2(a) = NumAns(a) and Problem$ = "Addition" and numColor(a) = 0 and NumAns(a) >= 10 `Double Digit Correct Answers
            NumColor(a) = 1 ; ScoreTotal = ScoreTotal + 100 ; barTotal# = barTotal# + 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a) <> NumAns(a) and Problem$ = "Addition" and numColor(a) = 0 and NumAns(a) < 10 `Single Digit Wrong Answers
            NumColor(a) = 2 ; ScoreTotal = ScoreTotal - 100 ; barTotal# = barTotal# - 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a)*10 + digit2(a) <> NumAns(a) and Problem$ = "Addition" and numColor(a) = 0 and NumAns(a) > 10 `Double Digit  Wrong Answers
            NumColor(a) = 2 ; ScoreTotal = ScoreTotal - 100 ; barTotal# = barTotal# - 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         Rem For :: SUBTRACTION :: SUBTRACTION :: SUBTRACTION :: SUBTRACTION :: SUBTRACTION :: SUBTRACTION ::
         if digit1(a)  = NumAns(a) and Problem$ = "Subtraction" and numColor(a) = 0 and NumAns(a) < 10 `Single Digit Correct Answers
            NumColor(a) = 1 ; ScoreTotal = ScoreTotal + 100 ; barTotal# = barTotal# + 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0 ` Deselects Attempted Problem
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a)*10 - digit2(a) = NumAns(a) and Problem$ = "Subtraction" and numColor(a) = 0 and NumAns(a) >= 10 `Double Digit Correct Answers
            NumColor(a) = 1 ; ScoreTotal = ScoreTotal + 100 ; barTotal# = barTotal# + 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a) <> NumAns(a) and Problem$ = "Subtraction" and numColor(a) = 0 and NumAns(a) < 10 `Single Digit Wrong Answers
            NumColor(a) = 2 ; ScoreTotal = ScoreTotal - 100 ; barTotal# = barTotal# - 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a)*10 - digit2(a) <> NumAns(a) and Problem$ = "Subtraction" and numColor(a) = 0 and NumAns(a) > 10 `Double Digit  Wrong Answers
            NumColor(a) = 2 ; ScoreTotal = ScoreTotal - 100 ; barTotal# = barTotal# - 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         Rem For :: MULTIPLICATION :: MULTIPLICATION :: MULTIPLICATION :: MULTIPLICATION :: MULTIPLICATION ::
         if digit1(a) * 1 + digit2(a) + 1 = NumAns(a) and Problem$ = "Multiplication" and numColor(a) = 0 and NumAns(a) < 10 `Single Digit Correct Answers
            NumColor(a) = 1 ; ScoreTotal = ScoreTotal + 100 ; barTotal# = barTotal# + 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0 ` Deselects Attempted Problem
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a) * 10 + digit2(a) + digit3(a)+1 = NumAns(a) and Problem$ = "Multiplication" and numColor(a) = 0 and NumAns(a) >= 10 `Double Digit Correct Answers
            NumColor(a) = 1 ; ScoreTotal = ScoreTotal + 100 ; barTotal# = barTotal# + 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a) * 100 = NumAns(a) and Problem$ = "Multiplication" and numColor(a) = 0 and NumAns(a) >= 100 `Triple Digit Correct Answers
            NumColor(a) = 1 ; ScoreTotal = ScoreTotal + 100 ; barTotal# = barTotal# + 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a) * 1 + digit2(a) + 1 <> NumAns(a) and Problem$ = "Multiplication" and numColor(a) = 0 and NumAns(a) < 10 `Single Digit Wrong Answers
            NumColor(a) = 2 ; ScoreTotal = ScoreTotal - 100 ; barTotal# = barTotal# - 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
         if digit1(a) * 10 + digit2(a) + 1 <> NumAns(a) and Problem$ = "Multiplication" and numColor(a) = 0 and NumAns(a) > 10 `Double Digit  Wrong Answers
            NumColor(a) = 2 ; ScoreTotal = ScoreTotal - 100 ; barTotal# = barTotal# - 15
            Submit = 0 ; srtCount = 0 ; Count = 0 ; NumSelect(a) = 0
            if NumColor(20) = 0 Then NumSelect(a+1) = 1
         endif
      endif
 
      `set Cursor 10,screen height()-100
      `If NumSelect(a) = 1 Then Print "D1-D2: ",Digit1(a)-Digit2(a)," NumAns(a): ",NumAns(a), "  Color = ",NumColor(a),"  Submit ",Submit,"  Count: ",Count
      `set Cursor 10,screen height()-75
      `If NumSelect(a) = 1 Then Print "D1 ",Digit1(a),"   D2 ",Digit2(a),"  D3 ",Digit3(a)," nextdigit(a): ",nextdigit(a)
      Rem Enter the First digit
      if nextdigit(a) = 1 and NumSelect(a) = 1 and NumColor(a) = 0
         if inkey$() = "0"
            digit1(a) = 0
            nextdigit(a) = 2 ;srtCount = 1 ; Submit = 1
         endif
         if inkey$() = "1"
            digit1(a) = 1
            nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
         endif
      if inkey$() = "2"
         digit1(a) = 2
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "3"
         digit1(a) = 3
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "4"
         digit1(a) = 4
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "5"
         digit1(a) = 5
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "6"
         digit1(a) = 6
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "7"
         digit1(a) = 7
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "8"
         digit1(a) = 8
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "9"
         digit1(a) = 9
         nextdigit(a) = 2 ; srtCount = 1 ; Submit = 1
      endif
      if scancode() = 14 and numColor(a) = 0 ` Backspace and if answer not chosen yet
         nextdigit(a) = 1 ; digit1(a) = -1 ; Submit = 1
      endif
   endif
 
REM Enter the second digit
if nextdigit(a) = 2 and Count >= 40 and NumSelect(a) = 1 and NumColor(a) = 0
      if inkey$() = "0"
         digit2(a) = 0
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "1"
         digit2(a) = 1
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "2"
         digit2(a) = 2
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "3"
         digit2(a) = 3
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "4"
         digit2(a) = 4
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "5"
         digit2(a) = 5
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "6"
         digit2(a) = 6
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "7"
         digit2(a) = 7
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "8"
         digit2(a) = 8
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if inkey$() = "9"
         digit2(a) = 9
         if Problem$ <> "Multiplication" Then nextdigit(a) = 2 ;
         if Problem$ = "Multiplication" Then nextdigit(a) = 3
         Submit = 1 ; srtCount = 1 ; Count = 0
      endif
      if ScanCode() = 14 and numColor(a) = 0 ` Backspace and if answer not chosen yet
         nextdigit(a) = 1 ; digit2(a) = -1 ; Count = 0 ; srtCount = 0 ; Submit = 1
      endif
   endif
 
REM Enter the Third digit
if nextdigit(a) = 3 and Count >= 40 and NumSelect(a) = 1 and NumColor(a) = 0 and Problem$ = "Multiplication"
      if inkey$() = "0"
         digit3(a) = 0
         nextdigit(a) = 3 ;srtCount = 1 ; Submit = 1
      endif
      if inkey$() = "1"
         digit3(a) = 1
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "2"
         digit3(a) = 2
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "3"
         digit3(a) = 3
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "4"
         digit3(a) = 4
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "5"
         digit3(a) = 5
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "6"
         digit3(a) = 6
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "7"
         digit3(a) = 7
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "8"
         digit3(a) = 8
         nextdigit(a) = 3 ; Submit = 1
      endif
      if inkey$() = "9"
         digit3(a) = 9
         nextdigit(a) = 3 ; Submit = 1
      endif
      if ScanCode() = 14 and numColor(a) = 0 ` Backspace and if answer not chosen yet
         nextdigit(a) = 2 ; digit3(a) = -1 ; Count = 0 ; srtCount = 0 ; Submit = 1
      endif
   endif
   if srtCount = 1
      Count = Count + 1
   endif
   ProbCount = ProbCount + 1
   next a
 
   Rem Draw The Hud
   Set Text Font "Impact"
   ink rgb(35,0,50),1
   box 0,0,Screen width(),50
   ink rgb(15,0,25),1
   box 2,2,screen width() - 2,48
   Set Text Size 30
   Set Cursor 12,12
   ink rgb(0,0,100),1
   Print "L e v e l ","       ",Level
   ink rgb(50,200,100),1
   Set Cursor 10,10
   Print "L e v e l ","       ",Level
   Set Cursor 550,12
   ink rgb(0,100,200),1
   Print "S C O R E ","       ",Score
   ink rgb(255,255,255),1
   box 199,9,501,41
   ink rgb(0,0,0),1
   box 200,10,500,40
   ink rgb(100*(bar#/500),0,0),1
   box 200,10,bar#,15
   box 200,35,bar#,40
   ink rgb(150*(bar#/500),25*(bar#/500),25*(bar#/500)),1
   box 200,15,bar#,20
   box 200,30,bar#,35
   ink rgb(200*(bar#/500),50*(bar#/500),50*(bar#/500)),1
   box 200,20,bar#,23
   box 200,29,bar#,32
   ink rgb(250*(bar#/500),100*(bar#/500),100*(bar#/500)),1
   box 200,23,bar#,29
 
   Rem The Problem
   ink RGB(0,0,0),1 ; Set Text Font "Modern"
   Set Cursor 299,12 ; Print Problem$
   Set Cursor 301,12 ; Print Problem$
   Set Cursor 300,11 ; Print Problem$
   Set Cursor 300,13 ; Print Problem$
   Set Cursor 300,12 ; ink RGB(255,255,255),1
   Print Problem$
 
   Rem Check If the Player Lost
   if barTotal# <= 200
      Speed# = 0
      if ReturnKey() = 1 Then Ready = 1
      ink RGB(200,0,200),1 ; Box 50,100,Screen Width() - 50,200
      ink RGB(0,0,0),1 ; Box 51,101,Screen Width() - 51,199
      ink RGB(0,100,255),1 ; Set Cursor 325,110 ; Set Text Size 30
      Print "GAME OVER "
      ink RGB(0,150,255),1 ; Box 55,150,Screen Width() - 55,190
      if b <= 100 and AddBlue = 0 ` Will Add Blue if 0
         b = b + 10
         if b >= 100 Then AddBlue = 1
      endif
      if AddBlue = 1
         b = b - 10
         if b <= 0 Then b = 0
         if b <= 0 Then AddBlue = 0
      endif
      if Ready = 1 Then b = 255
      ink RGB(b*0.3,b*0,b*0.7),1 ; Box 56,151,Screen Width() - 56,158
      ink RGB(b*0.35,b*0,b*0.7),1 ; Box 56,158,Screen Width() - 56,168
      ink RGB(b*0.40,b*0,b*0.7),1 ; Box 56,168,Screen Width() - 56,172
      ink RGB(b*0.30,b*0,b*0.7),1 ; Box 56,172,Screen Width() - 56,182
      ink RGB(b*0.3,b*0,b*0.7),1 ; Box 56,182,Screen Width() - 56,189 ` Do not exceed 189
      Set Cursor 373-40,155 ; Ink RGB(0,0,50),1 ; Print "Play Again"
      Set Cursor 377-40,155 ; Ink RGB(0,0,50),1 ; Print "Play Again"
      Set Cursor 375-40,153 ; Ink RGB(0,0,50),1 ; Print "Play Again"
      Set Cursor 375-40,157 ; Ink RGB(0,0,50),1 ; Print "Play Again"
      Set Cursor 375-40,155 ; Ink RGB(150,150,255),1 ; Print "Play Again"
      if Ready = 1
         SetProblem = 0
         for i = 0 to 20
            Nextdigit(i) = 1
            Digit1(i) = -1 ; Digit2(i) = -1 ; NumYchance(i) = 0
            NumColor(i) = 0 ; NumSelect(i) = 0
            NumStart(i) = 600*i - NumStart(i) - 5 ; NumY(i) = 0 ; ScoreTotal = 0
         next i
         ProbCount = 0 ; Submit = 0 ; NumSelect(0) = 1 ; barTotal# = 220 ; Speed# = 3
         LevelIncrease = 0 ; Ready = 0 ; b = 0
      endif
 
   endif
 
   Rem If the player has completed the level
   if NumyChance(20) <> 0 and Ready = 0
      if barTotal# = 500 Then ScoreTotal = ScoreTotal + 1000
      if LevelIncrease = 0
         Level = Level + 1
         LevelIncrease = 1
      endif
      if Level = 2 Then Problem$ = "Subtraction"
      if Level = 3 Then Problem$ = "Multiplication"
      if Level = 4 Then Problem$ = "Addition"
      if Level = 5 Then Problem$ = "Subtraction"
      if Level = 6 Then Problem$ = "Multiplication"
      if Level = 7 Then Problem$ = "Addition"
      if Level = 8 Then Problem$ = "Subtraction"
      if Level = 9 Then Problem$ = "Multiplication"
 
      if ReturnKey() = 1 Then Ready = 1
      ink RGB(200,0,200),1 ; Box 50,100,Screen Width() - 50,200
      ink RGB(0,0,0),1 ; Box 51,101,Screen Width() - 51,199
      ink RGB(0,100,255),1 ; Set Cursor 150,110 ; Set Text Size 30
      Print "CONGRATULATIONS! You finished level ", Level - 1
      ink RGB(0,150,255),1 ; Box 55,150,Screen Width() - 55,190
      if b <= 100 and AddBlue = 0 ` Will Add Blue if 0
         b = b + 10
         if b >= 100 Then AddBlue = 1
      endif
      if AddBlue = 1
         b = b - 10
         if b <= 0 Then b = 0
         if b <= 0 Then AddBlue = 0
      endif
      if Ready = 1 Then b = 255
      ink RGB(b*0.3,b*0,b*0.7),1 ; Box 56,151,Screen Width() - 56,158
      ink RGB(b*0.35,b*0,b*0.7),1 ; Box 56,158,Screen Width() - 56,168
      ink RGB(b*0.40,b*0,b*0.7),1 ; Box 56,168,Screen Width() - 56,172
      ink RGB(b*0.30,b*0,b*0.7),1 ; Box 56,172,Screen Width() - 56,182
      ink RGB(b*0.3,b*0,b*0.7),1 ; Box 56,182,Screen Width() - 56,189 ` Do not exceed 189
      Set Cursor 373,155 ; Ink RGB(0,0,50),1 ; Print "O.K"
      Set Cursor 377,155 ; Ink RGB(0,0,50),1 ; Print "O.K"
      Set Cursor 375,153 ; Ink RGB(0,0,50),1 ; Print "O.K"
      Set Cursor 375,157 ; Ink RGB(0,0,50),1 ; Print "O.K"
      Set Cursor 375,155 ; Ink RGB(150,150,255),1 ; Print "O.K"
      if Ready = 1
         SetProblem = 0
         for i = 0 to 20
            Nextdigit(i) = 1
            Digit1(i) = -1 ; Digit2(i) = -1 ; NumYchance(i) = 0
            NumColor(i) = 0 ; NumSelect(i) = 0
            NumStart(i) = 600*i - NumStart(i) - 5
         next i
         ProbCount = 0 ; Submit = 0 ; NumSelect(0) = 1 ; barTotal# = 220 ; Speed# = 3
         LevelIncrease = 0 ; Ready = 0 ; b = 0
      endif
 
   endif
 
   Sync
   Cls
 
loop